Question:
What is Mode in Stripe API in Laravel?

Problem

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:


$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? 


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')

                ]);


Answered by: >Jarmo T

Credit: >StackOverflow


Blog Links

>How to manage the Text in the container in Django?

>Fix webapp stops working issue in Django- Python webapp

>Creating a form in Django to upload a picture from the website

>Sending Audio file from Django to Vue

>How to keep all query parameters intact when changing page in Django?

>Solved: TaskList View in Django

>Implement nested serializers in the Django rest framework

>How to filter events by month in Django?

>Sorting the restframework in Django

>Ways to access instances of models in view in order to save both forms at once in Django

>What makes index.html have such kind of name in Django?

>Fix Module Not Found during Deployment- Django

>Creating a Django with existing directories, files, etc.?

>How to Read a CSV file with PHP using cURL?


Nisha Patel

Nisha Patel

Submit
0 Answers