It looks like you're using Stripe Checkout.
If you look at the method in your javascript stripe.createToken(), you will see it checks for result.error:
stripe.createToken(card , optinas).then(function(result) {
if (result.error) {
// Inform the user if there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
If no error is found, it hits the else block:
else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
which takes you to the stripeTokenHandler() method:
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
This function:
- Accepts the token that was returned from the API
- Creates a hiddenInput
- Sets the name of the hidden input to "stripeToken"
- Sets the value of the hidden input to "token.id"
- And finally adds the hidden input element to the form
When the form is submitted the token will be part of the POST data sent to your server.
To troubleshoot, first try dd($response->all()); after post. If stripe_token doesn't show up there, it's an issue on the front end.
Either you there is an error, meaning you are getting caught in the else block (meaning the token is never attached to the form), or you have some kind of JS issue. You can use Dev Tools to add breakpoints or just drop some console.log()'s in there to start tracing what is being returned by Stripe.