Closed GeekyGeeky closed 1 year ago
Paystack API requires you to send the subunit currency as amount when initializing a transaction. Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR (i.e amount = currency * 100). https://paystack.com/docs/api/#transaction-initialize
Why does the API expects "int" instead of "double"?
-- I thought about that as well but honestly, that seems to be the most logical way to tell paystack how much exactly to charge since the least subunit of a naira is 1 kobo which is an integer this means your customers cannot be charged "0.1 kobo" in between. It's either +1 kobo or no kobo. Let's say you send a double value of "3666.554" as amount which supposedly is meant to be kobo, how do you intend paystack interpret or charge your customers with such value? 36 naira, 66 kobo and 554 cowrees...? Not logical unless you do some rounding up and you also don't expect paystack to do rounding up for you. The APIs cannot read your mind neither can the library, do you want to ceil the floating subunits or do you want to floor them, that's for the merchant to decide.
Good day, GiddyNaya,
I appreciate your reply on this matter, but I believe since we multiply by 100 to provide Paystack a kobo value, Paystack should be able to do the division, I mean on the web, when I tried to pay 500.85 naira, It got debited accordingly.
So I feel, if we have something like 36.876 NGN and we multiply by 100, paystack can do their calculation and deduct the actual amount we charged. I do not know If I passed my message correctly but I believe you understand.
Thanks once again
@GiddyNaya Provided an excellent explanation. Closing.
When adding amount to the charge amount, I always have to round up/down the amount to be paid, sometimes I programmatically want to calculate amount to be paid, and it is usually in double not integer. Can we have that option ?