Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mode in Stripe API

What is the Mode parameter in Stripe API? When I test Stripe Api in laravel, it says:

Error sending request to Stripe: (Status 400) (Request req_XKxpoKv6C0eFDm) You must provide mode when using prices. Stripe\Exception\InvalidRequestException: You must provide mode when using prices.

Here is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  $session = Session::create([
                    'payment_method_types' => ['card'],
                   
                    'line_items' =>  [
                        [
                           
                         'price_data' => [
                          
                           'unit_amount' => $secretPlan['amount'] * 100,
                           'currency' => $secretPlan['currency'],
                           'product_data' => [
                             'name' => $secretPlan['name'],
                             'description' => $secretPlan['description']
                           ]
                         ],
                         'quantity' => $secretPlan['quantity'],
                        
                        ],
 
                     ],
                    'success_url' => $successURL,
                    'cancel_url' => route('payment.cancel')
                ]);

Can anyone give me a solution? Thanks in advance.

>Solution :

From the Stripe docs:

The mode parameter is of type enum with 3 possible values:

payment: accept one-time payments for cards, iDEAL, and more.

setup: save payment details to charge your customers later.

subscription: use Stripe Billing to set up fixed-price subscriptions.

So in your case when creating a session, add the mode parameter that fits your context, for example:

$session = Session::create([
                    'payment_method_types' => ['card'],
                    'mode' => 'payment',
                    'line_items' =>  [
                        [
                           
                         'price_data' => [
                          
                           'unit_amount' => $secretPlan['amount'] * 100,
                           'currency' => $secretPlan['currency'],
                           'product_data' => [
                             'name' => $secretPlan['name'],
                             'description' => $secretPlan['description']
                           ]
                         ],
                         'quantity' => $secretPlan['quantity'],
                        
                        ],
 
                     ],
                    'success_url' => $successURL,
                    'cancel_url' => route('payment.cancel')
                ]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading