#Eyepatch_128 - Update Payment Intent
1 messages · Page 1 of 1 (latest)
Hi, thanks for helping
I'm not familiar with commerce.js integrations. How do you instantiate Stripe.js?
First of all I have this: const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY); outside the parent react component
then I create the paymentintent
useEffect(() => {
if(stepPayment){
fetch("/api/create-payment-intent", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ live }),
})
.then((res) => res.json())
.then((data) => {
if(data.error){
setError(data.error);
}else{
setClientSecret(data.clientSecret)
setError("");
}
});
}
}, [token, live, stepPayment]);
Note: live is commerce result object and stepPayment is a variable to track which form to show (customer info, or payment)
const appearance = {
theme: 'stripe',
};
const options = {
clientSecret,
appearance,
};
Oh
but i've found it here : https://stripe.com/docs/payments/finalize-payments-on-the-server#payment-method-details
Yes, if you take a look at how Stripe.js is initialized in the second code snippet here: https://stripe.com/docs/payments/finalize-payments-on-the-server#set-up-stripe.js
You can see a value specified for apiVersion
The first value (before the ;) is the API version. The text after the ; is the beta flag
Also there is an array passed in as the betas argument. I suspect both are needed
Those are pretty easy to skip in all fairness
This flow is in publc Beta.
It is intended for testing and building out potential future developments.
These flags are required to expose Beta features
I see
I'm only practicing now but is this safe in production?
I'm quite new to stripe and ecomm dev
If you want access to this feature you'll need to contact Stripe using the link near the top of the page with this text:
This feature is in beta. For early access, contact us.
That way you can get all the information regarding this specific beta feature
Sure
Thanks
So in commerce.js stripe guide :
they have this:
// When mounting the Stripe elements form to your page, you should have a line like this which provides a card element
const card = elements.create('card')
// ... Integrate Elements onto your page, and other fields required for capturing a checkout with Commerce.js.
// Create a function that can be called when a "complete order" button is clicked
async function captureOrder() {
// Create a payment method using the card element on the page
const paymentMethodResponse = await stripe.createPaymentMethod({ type: 'card', card });
....
Then they carried on with commerce.js methods
Now I would like to know if there is a way to get paymentMethodResponse from paymentElement
paymentMethodResponse in this case is the response from the Stripe API that creates PaymentMethod objects.
okay
can I use it with paymentElement?
I just got this idea now, but if I pass paymentElement as card. would it work?
The documentation here seems to suggest it wouldn't:
https://stripe.com/docs/js/payment_methods/create_payment_method
since it expects a card or cardNumber element
But what are you trying to accomplish?
You can use a Payment Element directly with a Payment Intent to capture funds:
https://stripe.com/docs/js/payment_intents/confirm_payment
If you just want to save the Payment Method for use later, you can use a Setup Intent: https://stripe.com/docs/js/setup_intents/confirm_setup
I know it's a lot of docs but I want to make sure you get the right references.
Thanks,
Yes it's really a lot. but gotta read them lol
However I don't think it is a setup intent because I'm at a checkout, so I am not sure.
Our public docs (not just the API references) do a good job of explaining how to use both approaches within the larger context of an application:
Payment Intent: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
Setup Intent: https://stripe.com/docs/payments/save-and-reuse?platform=web
Okay, yes in that case where you want to collect payment you would use a Payment Intent. If you want to also save the Payment Method we've got a doc for that too:
https://stripe.com/docs/payments/save-during-payment
Yes thank you