xendit / xendit-php

Xendit REST API Client for PHP - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services, xenPlatforms
https://developers.xendit.co/api-reference/
MIT License
153 stars 76 forks source link

Can't Create Invoice with Customer Detail #170

Closed henzan02 closed 2 years ago

henzan02 commented 2 years ago

Hello, I've got this error when running create invoice with customer details.

Fatal error: Uncaught Xendit\Exceptions\ApiException: There was an error with the format submitted to the server. in C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\HttpClient\GuzzleClient.php:171 Stack trace: #0 C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\HttpClient\GuzzleClient.php(144): Xendit\HttpClient\GuzzleClient::_handleAPIError(Array) #1 C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\HttpClient\GuzzleClient.php(90): Xendit\HttpClient\GuzzleClient->_executeRequest(Array, '/v2/invoices') #2 C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\ApiRequestor.php(84): Xendit\HttpClient\GuzzleClient->sendRequest('POST', '/v2/invoices', Array, Array) #3 C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\ApiRequestor.php(43): Xendit\ApiRequestor->_requestRaw('POST', '/v2/invoices', Array, Array) #4 C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\ApiOperations\Request.php(94): Xendit\ApiRequestor->request('POST', '/v2/invoices', Array, Array) #5 C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\ApiOp in C:\xampp\htdocs\xendit\vendor\xendit\xendit-php\src\HttpClient\GuzzleClient.php on line 171

When I add customer_notification_preference, and customer array, its got an error above, but if I remove customer_notification_preference, and customer it's works well. I tried in development mode with PHP.

here's my code :

$params = ['external_id' => 'inv-934jan22',
    'payer_email' => 'myemailingoogle@gmail.com',
    'description' => 'Trip to Bali',
    'amount' => 11000,
    'customer_notification_preference' => ['whatsapp','email'],
    'customer' => [
        'given_names' => 'John',
        'email' => 'myemailingoogle@gmail.com',
        'mobile_number' => '+6281125688871',
        'address' => 'Jln Jakarta Raya',
    ],
];

$createInvoice = \Xendit\Invoice::create($params);
print_r($createInvoice);

What is the correct code format?

xen-HendryZheng commented 2 years ago

Hi @henzan02 Can you try to modify for customer_notification_preference to become like below?

Referring to developers.xendit.co image

'customer_notification_preference' => [
   'invoice_created' => ['whatsapp','email']
]
henzan02 commented 2 years ago

Wowww.. Thanks a lot @xen-HendryZheng it works!!