#riya-p_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1288109898428579942
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- riya-p_api, 6 days ago, 7 messages
hi there!
Hello @stark mason , I have the confusion about what to do further in the requirements as I have described above.
if you just want a buy button, have you looked into the Express Checkout Elemet? https://docs.stripe.com/elements/express-checkout-element
No, I have added the Payment Element as per my project requirement, and have added the pay button below it. What I want to do is pay via that button press.
got it. have you read this doc that explains how to use the Payment Element in React? https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements&client=react#web-submit-payment
Yes, I have added that code as explained.
and handleSubmit function too, but what are the backend requirements for the whole payment flow?
what do you mean?
- create the PaymentIntent on the backend and send the client_secret to the frontend
- mount the Payment Element on the frontend
- confirm the PaymentIntent on the frontend
and... that's it. then you can use webhook event to be notified when the payment is successful. all of this is explained in the link I shared above.
I have only done the,
Collect Payment Details Part on front-end side
next you need to confirm the PaymentIntent on the frontend
and CheckoutForm part of Submit the payment to Stripe
Here is my code:
Is this correct?
we are not able to review code here. is it working? if not, what's the error message?
okay, Sorry..๐ฌ
Um, like I have added the front-end side code of Collect Payment Details Part and CheckoutForm part of Submit the payment to Stripe on the front-end side from the above link you sent.
I don't know about the backend side
How can i do so?
Where I have to add this code?
once you confirm the PaymentIntent, the user will be redirected to the return_url you set. that code you shared should be on the return_url page to retrieve the information about the PaymentIntent, if needed.
but to test your integration you don't really need this code. you could just display "hello world" on your return_url for now.
okay, it means that the code displayed in the image I have shared is optional, right?
correct
Okaie, understood.
only, I have to add the client_secret to confirm the PaymentIntent or inside the stripe.confirmPayment on the frontend side, right?
I don't understand. when the user submit the payment form, you need to call stripe.confirmPayment like this:
yes, I have added the code for handleSubmit.
and , I have to ask that i have to add client_secret too inside the stripe.confirmPayment method?
and after that, It will give the paymentIntent Status.
and , I have to ask that i have to add client_secret too inside the stripe.confirmPayment method?
why don't you use the code in the link I shared? you can see it in the image above, and there's noclient_secretthere.
I have used that code from the link you have shared.
and as fill the Payment Element fields, and submit the form, I'm getting this error:
You must pass in a clientSecret when calling stripe.confirmPayment().IntegrationError: You must pass in a clientSecret when calling stripe.confirmPayment().
can you share your confirmPayment() code?
can you console.log the elements object?
yes
could not copy the log from the console.
here is the screenshot
Hi, @wide citrus
can you catch up with me here for help, please?
hello...
Yep, just catching up on everyone now
sorry
It looks like you code is mixing two patterns: intent-first and deferred intent
The confirmPayment pattern your showed matches the intent-first pattern, because it assume elements already has a clientSecret to use.
However, your initialization pattern looks like deferred intent:
const options: StripeElementsOptions = {
// passing the stripe elements options
mode: 'payment',
amount: 1099,
currency: 'eur',
// Fully customizable with appearance API.
appearance: {
theme: 'flat',
labels: 'floating',
variables: {
colorPrimary: '#0A74DA',
colorBackground: '#F4F4F5',
colorText: '#333',
},
},
};
this sets up elements to collect details but leaves payment intent creation for later, during the "pay" handler
could not understand
It seems like you put pieces together from two different guides, and the pieces don't match. That's why you get the error: You must pass in a clientSecret when calling stripe.confirmPayment().IntegrationError: You must pass in a clientSecret when calling stripe.confirmPayment().
because you initialized elements without a client secret, and you're also not providing one at confirm time.
Which pattern do you want to use? There are at least two possible corrections here.
Do you want to create the payment intent up front, or only when you customer hits the pay button?
which one is recommended to use?
I suggest the latter (defer intent creation) but its up to you
yes, i'll do that one you said
Ok, then you need to review your handlePayment method to match the pattern here:
https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=payment&client=react#submit-the-payment
You need to:
1/ Use elements.submit()
2/ Call your server back end to get a payment intent ( the client secret)
3/ Adjust your confirmPayment call to add that clientSecret
okaie, Thank you very much for help.
Added the code, but having issue as the code is in .ts file
You can ingore any type issue temporarily to get things running
okay
// We don't want to let default form submission happen here,
// which would refresh the page.
event.preventDefault();
if (!stripe) {
// Stripe.js hasn't yet loaded.
// Make sure to disable form submission until Stripe.js has loaded.
return;
}
setLoading(true);
// Trigger form validation and wallet collection
const {error: submitError} = await elements.submit();
if (submitError) {
handleError(submitError);
return;
}
// Create the PaymentIntent and obtain clientSecret
const res = await fetch("/create-intent", {
method: "POST",
});
const {client_secret: clientSecret} = await res.json();
// Confirm the PaymentIntent using the details collected by the Payment Element
const {error} = await stripe.confirmPayment({
elements,
clientSecret,
confirmParams: {
return_url: 'https://example.com/order/123/complete',
},
});
if (error) {
// This point is only reached if there's an immediate error when
// confirming the payment. Show the error to your customer (for example, payment details incomplete)
handleError(error);
} else {
// Your customer is redirected to your `return_url`. For some payment
// methods like iDEAL, your customer is redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
}
};```
I have added this function, and which API do I have to call here?
What do you mean?
const res = await fetch("/create-intent", {
method: "POST",
});
this part is a call to your own back end
in this doc, take a look at the preivous step 4
you need to implement your back end to create a payment intent and return the client secret to your front end