#blagi.connecto
1 messages · Page 1 of 1 (latest)
You need to add a button to your UI that calls confirmPayment from Stripe.js, like in step 3 of that guide
Then then you call that, and the Google Pay tab is selcted, then the dialog will appear
I have that button. When the card is chosen and card details are entered the validation started with that button should passed if everything is ok, but for a Google Pay chosen I had to know that is a Google pay is chosen to pass validation. Is there such an information available?
I'm sorry I don't understand what you're asking me
after pressing that button a validation is started. Including checking of card data. But when a Google Pay button is pressed I should know that Google Pay is chosen payment method and to pass without validating.
Correct yes, we wouldn't validate any of the form fields we'd just open the Google Pay dialog
Is there some methos or property of Stripe object that has info about google pay buton state?
Specifically what state are you trying to check? What are you trying to do?
Just to know that Google Pay is chosen payment method.
Then you'd use this change event and check the value hash: https://stripe.com/docs/js/element/events/on_change?type=paymentElement
I started confirmPayment but this appears n cosole:
Uncaught DOMException: Failed to execute 'postMessage' on 'Window': Delegation is not allowed without transient user activation.
at l (https://js.stripe.com/v3/?202305251330:1:102286)
at t.value (https://js.stripe.com/v3/?202305251330:1:33250)
at t.value (https://js.stripe.com/v3/?202305251330:1:32685)
at e.show (https://js.stripe.com/v3/?202305251330:1:152893)
at t.<anonymous> (https://js.stripe.com/v3/?202305251330:1:190131)
at t.show (https://js.stripe.com/v3/?202305251330:1:59377)
at https://js.stripe.com/v3/?202305251330:1:241595
at https://js.stripe.com/v3/?202305251330:1:54934
at Array.forEach (<anonymous>)
at t._emit (https://js.stripe.com/v3/?202305251330:1:54677)
What is the code you used?
` confirmPayment: async function(returnUrl, countryCode) {
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: returnUrl,
payment_method_data: {
billing_details: {
address: {
country: countryCode,
}
},
},
},
});
// This point will only be reached if there is an immediate error when
// confirming the payment. Otherwise, your customer will be redirected to
// your `return_url`. For some payment methods like iDEAL, your customer will
// be redirected to an intermediate site first to authorize the payment, then
// redirected to the `return_url`.
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message);
} else {
showMessage("An unexpected error occurred.");
}
}`
we need to see the context that confirmPayment is called from
that error means that you're not calling the function in response to an event like button press or a form submit, which is required
$.ajax({ async: false, type: 'POST', url: url, data: jsonData, dataType: 'JSON', success: function(rezervacija) { if (rezervacija.hasOwnProperty('return_url') && rezervacija.return_url.length > 0) { stripePaymentElements.confirmPayment(rezervacija.return_url, rezervacija.country_code); } }, error: function(err) { console.log('error'); } });
yes, that's the problem, you can't call this from a callback of an Ajax request like this. It has to be done directly from a button press event handler/form submit action.
Um, I had to retrieve return_url and country_code. 😦
If I eliminate ajax call it should work?
the idea is you would call the backend and create the PaymentIntent before you show the PaymentIntent and then you can call confirmPayment immediately when the button is pressed).
(that's why in the sample code it's done in an initialize function at the start)
altearnatively you can use https://stripe.com/docs/payments/accept-a-payment-deferred?type=payment if you want to wait to create it until later
Ok thanks! I had to change a flow.