bullioncapital / kinesis-pay-woocommerce

0 stars 1 forks source link

Currency being ignored by API #1

Closed robwoodgate closed 2 months ago

robwoodgate commented 7 months ago

This isn't necessarily a problem with the WooCommerce plugin, but the API is ignoring the amountCurrency param in the payment endpoint: https://apip.kinesis.money/api/merchants/payment

The result is the KAG/KAU amounts calculated are incorrect if using a currency other than USD.

Example request payload in Aussie Dollars (AUD):

{"globalMerchantId":"ABCXYZ123","paymentKauAmount":"0.15144","paymentKagAmount":"0.42711","amount":15,"amountCurrency":"AUD"}

Response from API:

{"merchantBusinessName":"My Business Ltd","globalMerchantId":"ABCXYZ123","paymentKauAmount":0.22999,"paymentKagAmount":0.64884,"amount":15,"amountCurrency":"USD","status":"created","expiryAt":"2024-02-20T15:04:56.918Z","globalPaymentId":"KPAPXXXXXXX","createdAt":"2024-02-20T14:54:56.920Z","updatedAt":"2024-02-20T14:54:56.920Z","paymentCurrency":null}]

The API is (AFAIK) undocumented, but it appears to calculate and returns paymentKagAmount / paymentKauAmount based on the amount submitted. My tests have shown only the globalMerchantId and amount param are required (amountCurrency being ignored by the API at present). The paymentKagAmount / paymentKauAmount params are also ignored.

The two calls the plugin makes to the exchange rate API (function request_kpay_exchange_rates() at lines 80/81 of the api.php file) therefore seem to be unnecessary overhead.

Cheers Rob

golashr commented 3 months ago

Thank you for highlighting this issue. In version 2 of our API, we have enhanced the input parameter format. The amount currency is now constant for a merchant and can be retrieved from the merchant profile. As a result, only two mandatory fields are required.

{
   "globalMerchantId":"ABCXYZ123",
   "amount":15
}

So the AUD as preferred (amount) currency will be fetched from the profile. In case you want to have different preferred (amount) currency, you need to create another merchant profile.

Please share your feedback on how it went! Thanks.

robwoodgate commented 2 months ago

Ok, that's understood. Thanks for clarifying.

I think ultimately it would allow more flexible use of the API if amountCurrency could be optionally set (falling back to the profile setting if omitted). Some docs for this API would also be useful in the account API Docs section :)