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

kaushal's avatar

Which stripe method i have to use for eccommerce cart items checkout?

Which stripe method i have to use for eccommerce cart items checkout?

0 likes
12 replies
drewdan's avatar

Are you looking to take the credit card details on the website you are developing, or redirecting them to Stripes payment portal?

kaushal's avatar

yes i am looking to take credit card details

drewdan's avatar

I get that, but are you looking to integrate the payment form directly into your website using stripe.js, or are you looking to use checkout and redirect them to the stripe website to take payment?

kaushal's avatar

looking for stripe.js. By the way which is better according to you stripe.js or redirect on stripe website to take payment. how laravel cashier is for my requirement?

drewdan's avatar

Cashier is more for subscriptions to certain things, so Jeffrey Way uses cashier for laracasts to handle billing for access to laracasts. I dont think its really for an online shop.

stripe.js is a better implementation in my opinion as it provides a better ux, however it requires from front and and backend work.

With stripe.js, you would need to send a request to your server which will use the PaymentIntent class, which will return a payment intent token: https://stripe.com/docs/api/payment_intents/create

You can then pass this token to your front end, and this token, submitted with the stripe.js stripe elements will allow you to charge a customers card.

A very good user guide with step by step details can be found here: https://stripe.com/docs/payments/accept-a-payment#web

kaushal's avatar

@drewdan stripe accepts payments in cent. And 131 cent = 1 GBP. So if i need to receive payment of 10 GBP then i should write following way right?

Stripe\Charge::create ([
            "customer" => $customer->id,
            "amount" => 131 * 10,
            "currency" => "GBP",
            //"source" => $request->stripeToken,
            "description" => "Stripe Demo App",
            'metadata' => array(
                'order_id' => $orderID
            )
        ]);
drewdan's avatar

Stripe accepts payments in the lowest denomination of any currency, so if you have the currency set to GBP, as you do in your example, then you are passing in pennies, not cent. So if you wanted to receive a payment of £10, you need to just give it 1000. Equally if you wanted 10 dollars. you would need to pass 1000 again, but change the currency to usd.

The only calculation you would or should ever do to this would be converting pounds to pence, or dollars to cents etc

kaushal's avatar

@drewdan one last question I have created one following stripe demo that take payment to only single merchant. see following example

public function stripePost(Request $request)
    {
        Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));

        $customer = \Stripe\Customer::create(array(
            'name' => 'test',
            'description' => 'test description',
            'email' => '[email protected]',
            'source' => $request->stripeToken,
            "name" => "kaushal",
            "address" => ["city" => "Rajkot", "country" => "india", "line1" => "Near Bhaktinagar", "line2" => "Near Makkam chowk", "postal_code" =>"360001", "state" => "Gujrat"]
        ));

        $orderID = strtoupper(str_replace('.','',uniqid('', true)));

        Stripe\Charge::create ([
            "customer" => $customer->id,
            "amount" => 100 * 10,
            "currency" => "GBP",
            //"source" => $request->stripeToken,
            "description" => "Stripe Demo App",
            'metadata' => array(
                'order_id' => $orderID
            )
        ]);

        Session::flash('success', 'Payment successful!');

        return back();
    }

But now what if site needs customer have to pay different merchant according to his oders. Say like suppose my site have 3 restorent named with rest-1,rest-2,rest-3. so if cusotmer make order from rest-1, then payment will transfer in rest-1 merchant account and if order from rest-2 then customer payment will transer in rest-2 owner account and same for other restaurant.Can you suggest what should i change on above code? Should i do stripe secret dynamic?

drewdan's avatar
drewdan
Best Answer
Level 15

You will have to dynamically populate this:

Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));

You may have to store the key in the database and depending upon which user is signed in, the correct key gets put in place. I would not recommend putting keys in the database usually, but I cannot think of another way of handling this nicely.

kaushal's avatar

You mean if customer creates order for rest-1 then i have to set dynamically STRIPE_SECRET of rest-1 owner' stripe account.so i have to get STRIPE_SECRET of all the restaurant owner in to my db right?

Please or to participate in this conversation.