Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe: parameter_invalid_integer, New to PHP

I am debugging my code. I am no genius at PHP and need some help to decipher what I declare as the parameter if it is not an integer...

Can anyone help?

{

  "error": {

    "code": "parameter_invalid_integer",

    "doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",

    "message": "Invalid integer: 1.13",

    "param": "amount",

    "type": "invalid_request_error"

  }

$app->post('/createCharges', function() use ($app) { $response = array();

    $json = $app->request->getBody();
    $data = array(json_decode($json,true));

    $amount = $data[0]['amount'];
    $source = $data[0]['source'];
    $appointmentid = $data[0]['appointmentid'];


    \Stripe\Stripe::setVerifySslCerts(false);
    \Stripe\Stripe::setApiKey(STRIPE_API_KEY);

    $charge = \Stripe\Charge::create(array(
        "amount" => $amount,
        "currency" => "usd",
        "source" => $source,
        "description" => "test order from ios"
    ));
like image 996
c andrews Avatar asked Nov 18 '25 11:11

c andrews


1 Answers

With Stripe, the amount property of a Charge is always an integer in the smallest unit of a currency (cents for USD).

https://stripe.com/docs/api/charges/create#create_charge-amount

So to charge $1.13 you'd need to make sure the amount that you pass in \Stripe\Charge::create is 113 rather than 1.13 --- if your front-end is passing a decimal value a simple *100 should get you the value you need here, e.g. $amount = (int)($data[0]['amount'] * 100);

like image 120
duck Avatar answered Nov 21 '25 03:11

duck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!