Laravel stripe payment form isn't handled just posted
I've created https://jsfiddle.net/s8foxw9r/2/ that confirms the stripeTokenHandler
is working (and the token is being generated correctly).
If you open the jsfiddle URL, then open the developer tools in your browser and look at the console output you will see a dump of the token
object that is passed to stripeTokenHandler()
.
When you hit Submit Payment
the page POST
s to https://postman-echo.com/post which will dump out your request. You'll notice the request looks something like this:
{
"args": {},
"data": "",
"files": {},
"form": {
"stripeToken": "tok_1F07d72eZvKYlo2CqBprboVK"
},
"headers": {
"x-forwarded-proto": "https",
"host": "postman-echo.com",
"content-length": "40",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded",
"cookie": "sails.sid=s%3AHyTHsNyIhRvFINR3EGiXw1Kf12oufx84.jd6rEiCaqHsrM8eOGN1x%2ByzU%2BMatjM4l5S1Ekxhxdyo",
"origin": "https://fiddle.jshell.net",
"pragma": "no-cache",
"referer": "https://fiddle.jshell.net/",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
"x-forwarded-port": "443"
},
"json": {
"stripeToken": "tok_1F07d72eZvKYlo2CqBprboVK"
},
"url": "https://postman-echo.com/post"
}
The important parts are headers.content-type
and json
attributes. This means the stripe.js lib POST
ed the form via the application/x-www-form-urlencoded
MIME type, and that the stripeToken
was included.
This means your issue is one/both of the following:
- If you are not seeing a token generated in the browser, your stripe private key is probably incorrect. I'd start out with using your stripe test private key, it looks like
pk_test_xxx
. - Your Laravel server is not setup correctly. Lots of potential issues, would need more info, and unfortunately I've never used Laravel.
Lastly, I found a Stripe integration package for Laravel, might be worth trying: https://github.com/cartalyst/stripe-laravel