#stereozwo
1 messages · Page 1 of 1 (latest)
Can you share an example setup intent? I'm not sure I fully understand what you're trying to do here.
Okay, wait, I will copy short one of my script
$('#register-form').on('beforeSubmit', function (event) {
event.preventDefault();
stripe.confirmSetup({
elements,
confirmParams: {
return_url: window.location.href,
},
redirect: "if_required",
}).then(function(result) {
if (result.error) {
// Display error.message in my UI.
return false;
} else {
// The SetupIntent was successful!
stripeIntentHandler(result.setupIntent);
}
});
return false;
});
function stripeIntentHandler(setupIntent) {
// Insert the setupIntent into the form so it gets submitted to the server
var form = document.getElementById('register-form');
$('#registerform-payment_method').val(setupIntent.payment_method);
form.submit();
}
This is my js
On before submit in case of paymentw with card, the setupInent is insert in hidden field and the form submit in stripeIntentHandler()
after submit I save my customer to db
but in case of paypal, the stripe js redirects my customer direkt to paypal and the information in the checkout form (email, password) is lost, when paypal redirect back to my site
The checkout works very well with a credit card and I would like to add paypal. Does the type of checkout have to be fundamentally changed for this?
I hope I was able to explain it in a way that was understandable.
Gotcha - yes you're going to need to make changes to handle payment methods that require redirects
That's what the return_url is for, that's where your customer will be redirected to after the redirect flow is done
and that will include some details about the intent (setup intent ID, eg) then you can look up the payment method from there
But the way you're doing things now won't work with redirect methods
My idea was to save the customer before redirecting to paypal. Is there a way to know that the customer has selected PayPal before being redirected? You know what I mean?
In my UI and checkout, the customer enters all their information on one page. The Stripe payment element is also integrated into this form. Everything happens on one page so far.
The 3DS dialog also works very well here, as it is opened in a modal.
Yep, you can capture this from the change event on the payment element, it tells you the payment_method_type in the value.type: https://stripe.com/docs/js/element/events/on_change?type=paymentElement#element_on_change-handler-value