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

tjnapster555@gmail.com's avatar

how to stop user to pay same order twice in stripe ?

Hi i create the stripe form of payment and then make a create request in laravel now if the user press back in browser and then click on pay he charge again how i can prevent this from happening again i try to use this

 \Stripe\Charge::create(array(
                "amount" => 434 * 100,
                "currency" => "pkr",
                "source" => $request->stripeToken, // obtained with Stripe.js
                "description" => "Charge Challan",
                "metadata" => array("order_id" => "6735")
            ), array(
                    "idempotency_key" => uniqid(),
                )
            );

but i didnt help any , user is still being charge over and over again

0 likes
1 reply
martinbean's avatar

@tjnapster555 Store the payment status against the order. Could be as simple as a boolean column called paid. Fetch the order before creating the Stripe charge. If the order’s already been paid, redirect back with an error message.

$order = Order::findOrFail($orderId);

if ($order->paid()) {
    return redirect()->back()->withError('Order has already been paid.');
}

StripeCharge::create([
    // attributes...
]);

$order->markAsPaid();

I’d also recommend Cashier for using Stripe in Laravel. It has a nice charge() method that makes code a bit nicer:

$charge = $user->charge($amount, $options);

$order->update([
    'paid' => true,
    'stripe_charge_id' => $charge->id,
]);
1 like

Please or to participate in this conversation.