Level 2
Issue solved by previous post -> https://laracasts.com/discuss/channels/general-discussion/trycatch-stripe-error-handling
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, An issue happened when recently inserted the data as card name, address, postcode etc and pressing submit using Stripe.
This is the checkout.js:
// Create a Stripe client.
var stripe = Stripe('');
// Create an instance of Elements.
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base: {
color: '#32325d',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
// Create an instance of the card Element.
var card = elements.create('card',
{
style: style,
hidePostalCode:true
});
// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');
// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Handle form submission.
var form = document.getElementById('payment-form');
form.addEventListener('complete-orders', function(event) {
event.preventDefault();
var options = {
name: document.getElementById('card-name').value,
address_line1: document.getElementById('card-address').value,
address_city: document.getElementById('card-city').value,
address_state: document.getElementById('card-province').value,
address_zip: document.getElementById('card-postcode').value,
};
document.getElementById('card-city').disable = true;
stripe.createToken(card, options).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;
document.getElementById('card-city').disable = false;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
});
// Submit the form with the token ID.
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);
// Submit the form
form.submit();
}
First I thought that I did not include the inputs:
<label for="card-name">Cart Name</label>
<input type="text" id="card_name" class="form-control" required>
<label for="card-address">Address</label>
<input type="text" id="card_name" class="form-control" required>
<label for="card-city">City</label>
<input type="text" id="card_name" class="form-control" required>
<label for="card-province">Province</label>
<input type="text" id="card_province" class="form-control" required>
<label for="card-postcode">Postcode</label>
<input type="text" id="card_postcode" class="form-control" required>
but that was not the issue. I did everything but I get: Invalid parameters.
I am using the correct secret and public key.
Issue solved by previous post -> https://laracasts.com/discuss/channels/general-discussion/trycatch-stripe-error-handling
Please or to participate in this conversation.