unicodeveloper / laravel-paystack

:credit_card: :package: :moneybag: Laravel 6, 7, 8, 9, 10 and 11 Package for Paystack
https://paystack.co
MIT License
597 stars 310 forks source link

Done. Upgrade to the latest version. version 1.0.4, Still getting same response, invalid amount. #102

Open temple300 opened 4 years ago

temple300 commented 4 years ago

Error is 401 Unauthorized,

Done. Upgrade to the latest version. version 1.0.4

Originally posted by @unicodeveloper in https://github.com/unicodeveloper/laravel-paystack/issues/78#issuecomment-633094730

temple300 commented 4 years ago

error

seunsekoni commented 4 years ago

Battled with this over 2 hours yesterday before i found a fix. From the Paystack::makePaymentRequest() method, you are expected to pass "quantity" because the value of quantity will be multiplied by the value of amount. If you don't set a value for quantity, the value of amount when calculated will be zero. You can solve this by passing an hidden input value of quantity to be set to 1 or just remove the variable quantity that was multiplied with amount. see the screenshot i attached.

Screenshot 2020-05-28 at 08 27 26
unicodeveloper commented 4 years ago

This is very interesting. The package expects that the user puts the value of quantity in the form via a hidden field. And it's stated in the README file.

seunsekoni commented 4 years ago

It wasn't stated as a required field in the README file. I for one don't need the quantity field for my payments but i realised it's required in the make Paystack::makePaymentRequest() to calculate the value of amount. Hence, why i removed it.

unicodeveloper commented 4 years ago

In the sample form (in the README), I added it. I never really thought anyone would omit putting a quantity field (apparently I was wrong). Maybe in a new release, I can default the quantity to 1 if quantity is not added to the form field to prevent hair-pulling situations like this.

sample_form

temple300 commented 4 years ago

Serious? Are you supposed to have any business with dev's quantity? In my case, we're operating a store where multiple products can be purchased with different quantities. What if I want to include some other variable after multiplying by quantity? How do you calculate it then? The simple solution is to accept whatever amount you're given and leave multiplication arithmetic to the dev. If the underlying API requires a "quantity", it's safe to also pass it without our knowledge. I'm not sure they'll encourage such poor design, though.

unicodeveloper commented 4 years ago

I totally get your use case. You are right. For folks dealing with specific/just one product, it makes sense for them. In previous versions, I left out calculating the amount with quantities.