unicodeveloper / laravel-paystack

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

I got "400 Bad Request: Invalid Amount Sent" everytime #63

Closed ahkmunna closed 4 years ago

ahkmunna commented 5 years ago

I send the request from backend after verifying the form inputes and got 400 Bad Request every time even when I set the amount in raw int format. I got "400 Bad Request: Invalid Amount Sent"every time

https://api.paystack.co/transaction/initializeresulted in a400 Bad Request` response: { "status": false, "message": "Invalid Amount Sent" }

aeadedoyin commented 5 years ago

Can you send an excerpt of your code? So as to figure where the problem might be from.

kennyendowed commented 5 years ago

pls wat d solution to this $amount = 50000;

talktojoegee commented 4 years ago

The hidden field of quantity is required. <input type="hidden" name="quantity" value="3"> Enjoy!

khollinzx commented 4 years ago

the field below is required... with the value of 1.

`<`input type="text" name="quantity" value="1" hidden`>`

cause it need its to multiple the amount passed to it.

amanKumar689 commented 3 years ago

you must send form data in a req body if you are using axios then you must attach your form data to data : form_data

orangesnowtech commented 2 years ago

Stringify the data to be sent as body. It should work.

also write "body" not "Body" const data = {amount: 1000000, email: "someone@someone.com", currency: "NGN",

body: JSON.stringify(data)

quiet-programmer commented 2 years ago

Hi having some issues at my end here

this is not working for me, any clarification here? $data = array( "amount" => 700 * 100, "reference" => '4g4g5485g8545jg8gj', "email" => 'user@mail.com', "currency" => "NGN", "orderID" => 23456, ); return Paystack::getAuthorizationUrl($data)->redirectNow();

I'm getting a: {"status":false,"message":"Invalid Amount Sent"} resulted in a400 Bad Request``

orangesnowtech commented 2 years ago

I believe you'll need to turn your data array back into a string for it to work hence the stringify.json and instead of 700*100 as amount, just put in 70000.

On Sun, 26 Jun 2022, 15:42 Godsend Joseph, @.***> wrote:

Hi having some issues at my end here

this is not working for me, any clarification here? $data = array( "amount" => 700 * 100, "reference" => '4g4g5485g8545jg8gj', "email" => @.***', "currency" => "NGN", "orderID" => 23456, ); return Paystack::getAuthorizationUrl($data)->redirectNow();

I'm getting a: {"status":false,"message":"Invalid Amount Sent"} resulted in a 400 Bad Request``

— Reply to this email directly, view it on GitHub https://github.com/unicodeveloper/laravel-paystack/issues/63#issuecomment-1166553068, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK5YLDMEVK5NRCVMFSTX6LTVRBT45ANCNFSM4GL5P4SQ . You are receiving this because you commented.Message ID: @.***>

quiet-programmer commented 2 years ago

I believe you'll need to turn your data array back into a string for it to work hence the stringify.json and instead of 700*100 as amount, just put in 70000. On Sun, 26 Jun 2022, 15:42 Godsend Joseph, @.> wrote: Hi having some issues at my end here this is not working for me, any clarification here? $data = array( "amount" => 700 100, "reference" => '4g4g5485g8545jg8gj', "email" => **@.', "currency" => "NGN", "orderID" => 23456, ); return Paystack::getAuthorizationUrl($data)->redirectNow(); I'm getting a: {"status":false,"message":"Invalid Amount Sent"} resulted in a 400 Bad Request`` — Reply to this email directly, view it on GitHub <#63 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK5YLDMEVK5NRCVMFSTX6LTVRBT45ANCNFSM4GL5P4SQ . You are receiving this because you commented.Message ID: @.>

can you please explain well on turning the data array back into a string?

kodunmi commented 2 years ago

I doubt @orangesnowtech knows what he's saying

kodunmi commented 2 years ago

Why is this closed

The code provided in the example is not working

/**

return Paystack::getAuthorizationUrl($data)->redirectNow();

orangesnowtech commented 2 years ago

The method I suggested is what worked for me...

I put the data I wanted to pass in a JSON object and passed it after turning it back into a string with stringify. Because doing it plainly just didn't work the way it should.

If you've got a solution let's hear it..

On Mon, 4 Jul 2022, 06:46 kodunmi, @.***> wrote:

Why is this closed

The code provided in the example is not working

/**

  • In the case where you need to pass the data from your
  • controller instead of a form
  • Make sure to send:
  • required: email, amount, reference, orderID(probably)
  • optionally: currency, description, metadata
  • e.g:

/ $data = array( "amount" => 700 100, "reference" => '4g4g5485g8545jg8gj', "email" => @.***', "currency" => "NGN", "orderID" => 23456, );

return Paystack::getAuthorizationUrl($data)->redirectNow();

— Reply to this email directly, view it on GitHub https://github.com/unicodeveloper/laravel-paystack/issues/63#issuecomment-1173375939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK5YLDO2IJJCFCWXUZWYDTTVSJ3CRANCNFSM4GL5P4SQ . You are receiving this because you were mentioned.Message ID: @.***>

kodunmi commented 2 years ago

Okay @quiet-programmer

Here is the solution to your problem

I had to go under the hood to discover this

Make use of laravel request (Illuminate\Http\Request)

$request->merge([ 'amount' => 700 * 100, 'email' => "test@gmail.com", "reference" => Paystack::genTranxRef(), "currency" => "NGN", ]);

try { $url = Paystack::getAuthorizationUrl()->url; return redirect()->away($url); } catch (\Exception $e) { return Redirect::back()->withMessage(['msg' => 'The paystack token has expired. Please refresh the page and try again.', 'type' => 'error']); }

quiet-programmer commented 2 years ago

@kodunmi Thanks a lot let me test this