#johnl_code
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- johnl_code, 17 hours ago, 72 messages
- johnl_code, 19 hours ago, 8 messages
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1260018382741438576
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
I am trying to send info to the server after the successful payment (name and email).
I heard that I can insert this:
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
paymentIntentId: paymentIntent.id,
additionalData: 'Any additional data you want to send',
}),
});```
However, this code cannot be reached because "payment_intent_client_secret" is not appended to the URL like it was supposed to? ( console.log(clientSecret) prints null)
Most of my code is pre-made btw, I am just trying to modify it for my needs
The name and email are your own web form?
yes
And you're asking how to send the info from it to the back-end?
When you submit the Payment Element, are you also making sure the name/email is included in the same HTML form element? So that it also gets submitted?
yes
Okay, and in your submit handler, are you able to console.log() the values for paymentIntentId and additionalData?
This is the handler:
e.preventDefault();
setLoading(true);
const response = await fetch("/create-payment-intent", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
cost
}),
});
const { clientSecret } = await response.json();
const { error } = await stripe.confirmPayment({
elements,
redirect: 'if_required',
});
if (error) {
if (error.type === "card_error" || error.type === "validation_error") {
showMessage(error.message);
} else {
showMessage("An unexpected error occurred.");
}
setLoading(false);
}
}
There is no paymentIntentId or additionalData
This is commented out btw, I want to make sure the code is reachable first
(it isn't reachable yet)
๐ Taking over this thread, catching up now
In confirmPayment() function, the redirect is set to if_required. If the payment method used isn't a redirect payment method, you won't be redirected to the return_url and payment_intent_client_secret won't be available
So you mean do this?
Or like, something like this
The first screenshot is right integration. I'd recommend checking the guide here for more details: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements#web-submit-payment
This is what I kinda currently already have
I ended up creating a new page fo redirect
And I passed the client secret into the url params
And now I get this
I now have the clientsecret key, but retreivePaymentIntent does not work
stripe.retrievePaymentIntent() is a promise. You either use await or use promise to access the payment intent
For example,
// Retrieve the PaymentIntent
stripe
.retrievePaymentIntent(clientSecret)
.then(({paymentIntent}) => {
switch (paymentIntent.status) {
....
});
});
I'd recommend checking the guide here: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements&client=html#web-submit-payment
Got it, I made it a promise and now it works!
Just one thing...
On the server side, can I get the cost from the payment intent id?
Obvioudly I don't want to pass the cost through the additional information because then the user can just edit it
Value in amount property is the amount that you charge to the customer: https://docs.stripe.com/api/payment_intents/object#payment_intent_object-amount
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You can get the amount information from there