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 not pass decimal number to Xendit #171

Closed tannguyen-iprice closed 2 years ago

tannguyen-iprice commented 2 years ago

Currently, the total payment is being rounded in Xendit gateway.

E.g: in the checkout page, total payment is 23,545.50 but the total payment in Xendit gateway is 23,545.00

Here is our EVN info Version: 1.4 OS: Ubuntu

I think it's happening because 'amount' is cast to (int) in XenditPHPClient::createInvoice.

Just wondering, is there a configuration to allow payment with decimal number. Do you have a patch for it, or we need to upgrade to the latest version(2.17)? Thanks

xen-HendryZheng commented 2 years ago

Hi @tannguyen-iprice Thanks for highlighting ! We will look into this and update you soonest.

xen-HendryZheng commented 2 years ago

Hi @tannguyen-iprice We just got affirmation that for IDR Invoice, the 2 decimals behind will be truncated. Unless for PHP (Philiphines), the decimals are being kept.

Hope that clarifies :)

tannguyen-iprice commented 2 years ago

Hi @xen-HendryZheng,

Thanks for checking our issue. I'm not sure about this part "Unless for PHP (Philiphines), the decimals are being kept", so it means current version is working well, no need to check issue on version 1.4, and we should upgrade to the latest version, right?

Maybe I haven't shared enough context to you, we are using xendit-php version 1.4. Here is the sample data that we called xendit-php to create invoice.

        //private XenditPHPClient $client;
        return $this->client->createInvoice(
            'devgoreward72',
            1098.5,
            'dummymail@gmail.com',
            'Payment for Galaxy A12 NTC 1 year official warranty at Lazada',
            [
                'currency' => 'PHP',
                'should_send_email' => '',
                'invoice_duration' => 120,
                'success_redirect_url' => 'https://dev-gorewards-ph.iprice.mx/checkout-success/',
                'failure_redirect_url' => 'https://dev-gorewards-ph.iprice.mx/checkout-fail/',
            ]
        );

But the amount is being rounded in "createInvoice" function here image

Link reference: https://github.com/xendit/xendit-php/blob/462ef3e13003039a522177bb576808f1bb16fe86/src/XenditPHPClient.php#L20

I think there are some options for us:

  1. Apply the patch from you
  2. Upgrade to the latest version(if the latest version does not have the same issue)
  3. We are missing some configurations(need your advice)

Thanks

xen-HendryZheng commented 2 years ago

Hi @tannguyen-iprice

Could you try the latest version of our SDK at v2.17.1

And refer to the code below: ```

use Xendit\Xendit;

require 'vendor/autoload.php';

Xendit::setApiKey('xnd_development_3YaHDmp8Wo5mDpZZi7y3jMFlIR9BZNgeP1L0wMfKHQDKxq6ZFAVOlfLmf1WGr88');

$params = ['external_id' => 'demo_1234992211',
    'payer_email' => 'hendry@xendit.co',
    'currency' => 'PHP',
    'description' => 'Trip to Bali',
    'amount' => 23545.50
];

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

for PHP Currency, there's no validation or casting to int for the amount.

Do try it out and let us know :)

luminto17 commented 2 years ago

Hi @tannguyen-iprice , additional context on top of Hendry's suggestion above, we have tried to make an Invoice w/ decimal using the latest version, and it was successfully created alongside the decimal (screenshot attached)

Screen Shot 2022-01-04 at 21 29 15

Let us know how's the result on your end :)

tannguyen-iprice commented 2 years ago

Hi @xen-HendryZheng , @luminto17 , Thank you for the enthusiastic support! We are planning to upgrade the extension to v2.17.1, thanks