Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maaz's avatar
Level 2

Invalid integer: value while implementing Stripe payment

Hi everyone . What is the solution of this problem. here is my code

  Stripe::setApiKey('sk_test_51HvoOvD0N8iA6zau2zVHsTsg3adl5ddxnTIDrB4LjWbvhgwN3dBvwBMaynf7TMzJS6Ozd');
        Charge::create([
            "amount" => Cart::subTotal(), // error here
            "currency" => "usd",
            "source" => $request->stripeToken,
            "description" => "Test payment from Trustech IT Solutions"
        ]);

it gives me an error of invalid integer

0 likes
4 replies
MichalOravec's avatar

You have amount as integer, so it has to be an integer.

What do you get for this?

dd(Cart::subTotal());
MichalOravec's avatar
Level 75

There is not easy way to convert "2,358.00" to number.

I guess it has to be in cents, so just remove commas and dots from that string

$amount = str_replace([',', '.'], ['', ''], Cart::subTotal());
1 like

Please or to participate in this conversation.