Usually when we create the Stripe token thats used to send credit card information to Stripe’s servers we are using Stripe.js. But what if we are doing an API for example and there is no front end to utilize Stripe.js?
We can use the stripe/stripe-php package and easily create the token based on the POST parameters sent to the API.
Lets say we have an application that takes credit card payments and they are utilizing our API to process these payments.
They may have a very simple form like this.
We are sending some basic information that might be used in a credit card payment. We pass it to the API using an ajax method
This information has now been sent to our controller and we need to do something with it. We can use Laravel’s Request to grab the information from the POST request. With that we can use the following code to create the token.
This will return JSON like this.
Now all we have to do is grab the ID from the returned JSON and we can utilize our token.
Receive updates and more content that doesn't make it to the blog.