#Peta Stewart
1 messages · Page 1 of 1 (latest)
Hi there!
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_4LdeX7oJJNPodr
this is one. because the process works I didn't pick up the error until testing live
As the error mentions, that payment_intent was already succeeded :
https://dashboard.stripe.com/test/logs/req_poc1bkPbMJPIOv
You are trying to confirm a succeeded payment_intent twice. If you want to do another payment then you need to create a new PaymentIntent.
One of the advantages of using PaymentIntent APIs is no double charges:
https://stripe.com/docs/payments/payment-intents#best-practices:~:text=No double-,charges,-No idempotency key
Yes, but as my code was built according to the docs... I don't see where this "double" request is happening. (The same second) Like a double hit.
My flow; purchase Page - get the secret (and some other stuff) checkout page - set up the stripe.elements & confirmPayment & retreive PaymentIntent
The error message is coming from the handleSubmit() - confirmPayment function
👋 taking over for my colleague. Let me catch up.
OK
There was a check status code. I think perhaps it is unnecessary as the payment is redirected. But the error message was from the handleSubmit function.
sorry for keeping you waiting
You must be busy : )
which flow are you following? would you mind sharing the link and some code snippets?
async handleSubmit(e) {
e.preventDefault();
this.setLoading(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: App.origin + "/success",
},
});
if (error.type === "card_error" || error.type === "validation_error") {
this.showMessage(error.message);
} else {
this.showMessage("An unexpected error occurred.");
}
this.setLoading(false);
}
This is the code sending the error message, just before being redirected to success page
could you please share the front-end code that is calling handleSubmit?
what framework are you using on the front-end?
nodejs is a backend programming language
are you using vanilla HTML/js or React or Next.js or something else
you must mean the html
I have an event listener
document
.querySelector("#payment-form")
.addEventListener("submit", (e) => {
CheckoutAPI.handleSubmit(e)
});
on the payment form
<form id="payment-form">
(FIY my frontend is a web app built with node & lit/html.js)
could you add a console.log in your handleSubmit to see whether it's getting called twice?
ok sure
Ok, I get the console.log and error message, but I am redirected before I can catch anything. So the console is cleared
you have an option in the devtools that lets you keep the console even after a redirect
OK let me look...
it's called preserve log
Ok, yes it is being called twice.
Perhaps in click function. Ok I will try and test.
I have one more question about the stripe domains
are you add and event listener on click of the button as well?
I have set up my server to only accept requests from specific domains. Are there limited domains used for webhooks?
There must be a glitch in the eventListener. But I'm sure I will be able to figure it out now I know it is a "click" issue.
https://stripe.com/docs/ips#webhook-notifications these are the list of IPs for webhook notifications
const allowlist = ['http://localhost:1234', '3.18.12.63'];
Do I add them straight in like this? Or do I need to add the https...
I'm not sure how you're doing your checks but this is more of an infrastructure thing rather than having to do it inside your code
At the bottom of here
It says to only trust if coming from these IPs. So I was just trying to integrate that into my CORS safe list
At the moment the server is blocking the webhooks ...
But thank you for your time. I will go and troubleshoot.
Take care
yes but blocking IPs should be at the infrastructure level not at the code level
OK so you mean via domain settings like .htaccess
it really depends on your infrastructure
let me know if you need any more help
Are you still here?
I disabled all the code for testing and on the eventListener I only get one console.log But when running the function, I get 2?
Which log?
My code is somehow getting called twice. But I only called it once.
I thought to set up a global variable to prevent it from running twice.
Can you share the exact code that is being called?
Ok the global variable prevent the code from being called twice....
Yes
I have an event listener
document
.querySelector("#payment-form")
.addEventListener("submit", (e) => {
e.preventDefault()
//console.log('call submit')
CheckoutAPI.handleSubmit()
});
This console log only reads once
But my code calls twice
async handleSubmit(){
console.log("Handle initiated Called")
console.log(initiated)
if(initiated == true){return}
else { initiated = true }
console.log("Handle Submit Called")
this.setLoading(true);
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: App.origin + "/success",
},
});
if (error.type === "card_error" || error.type === "validation_error") {
this.showMessage(error.message);
} else {
this.showMessage("An unexpected error occurred.");
}
this.setLoading(false);
}
The code at the top, prevents the it from repeating.
Which?
this global variable I added:
if(initiated == true){return}
else { initiated = true }
What is CheckoutAPI?
No, which console.log
CheckoutAPI is my .js where I run the codes from (Inside my node web app)
The console log which was repeated twice was the one in ... handleSubmit()
Anyway, I don't understand what the problem was. Maybe just a glitch in my app. But that global variable (Band-Aid fix) stopped the errors.