#Hotsauce-elements
1 messages ยท Page 1 of 1 (latest)
Hi Karbi! I want to provide some context for all the information we need to capture on our checkout modal.
Here is the staging link: https://catalog-web-phi.vercel.app/ of the previous Stripe Checkout integration.
We want to move to Stripe Elements.
Let me grab some code.
There are a few business requirements I am currently stuck on.
- We have multiple Stripe accounts (for different countries)
- Capturing additional information: dates, names, currency, etc.
I haven't been able to send the correct shape over to Stripe via the 'stripe.confirmPayment' method.
I'm hoping to get a beter understanding how I can achieve the business requirements within the Stripe Elements tool.
Np, thanks!
Okay so the Stripe account for each API call is identified on both the client (front-end) and server(back-end) by the use of API keys.
These are used to instantiate Stripe client libraries (back-end) and Stripe.js (front-end)
I see.
You can only confirm payments client side that were created with the same API key server-side
So that's some significant engineering but not impossible.
When it comes to capturing additional info, where do you want to capture it?
Just so I am on the same page. The API key on the client would have to pinpoint the location initially? Then the currency could potentially be set? I know its not a catch all but is that the gist?
Not the location, just the Stripe account.
Sorry thats what I meant.
The currency is set on the back-end when creating the Payment Intent
So the API key on the back-end creating the Payment Intent would need to match the API key on the front-end used to render the Payment Element and confirm the payment
I see, thanks for clarifying that.
The additional information would ideally be capture in a modal with the stripe elements 'card' iframe.
That would entirely depend on if that information capture is supported by Stripe. Since you cannot add arbitrary fields within the Stripe Element iframe
And Payment Element by default renders inputs for only the information required to successfully process the payment for the selected payment method
However, you can always capture those details yourself and update the Payment Intent record to keep them associated with the payment you are confirming
I see. I wasn't updating the iframe directly. Let me share some code here:
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
payment_method_data: {
billing_details: {
name: orgName,
address: {
line1: addressValue,
city: cityValue,
state: stateValue,
country: "US",
},
},
},
// Make sure to change this to your payment completion page
return_url: "http://localhost:3000/success",
},
});
I'll list out the information we would like to capture:
Organzation: string,
Full Name: string,
Date one: date,
Date two: date,
Currency: string, // I understand the limitations here
Address: string,
City: string,
State: string,
Okay the address/name info can be captured in the billing_details but the rest of this information would need to be added to the Payment Intent on the metadata property if you wanted to store the info with the payment
I attempted to updated the 'billing_details' (code above) but was unable to see the fields upon a live order.
Do you have the payment ID I could review?
Yes, one sec.
Ah! that did work. Sorry I thought the address would show up toward the top of the payments page. The payment ID is:pi_3LNleRDLP5Onkmu32bQIRFDu
Okay yeah the dashboard doesn't always put things where you might expect. But I'm glad you were able to save the data.
Last question is the shape of the metadata, would it look like this:
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
payment_intent_data: {
metadata: {
organization: orgName,
startDate: startDate,
endDate: endDate,
},
},
// Make sure to change this to your payment completion page
return_url: "http://localhost:3000/success",
},
});
},
});
You cannot pass metadata from the client side
I believe I was able to in the Stripe Checkout. Is that a inherent difference between the two?
That would need to be handled on the server
Stripe checkout has no client side that you can interface with.
You can pass metadata either when creating or updating the Payment Intent
I think I get that. I would have to update this block with the metadata information:
// Create a PaymentIntent with the order amount and currency
const paymentIntent = await stripe.paymentIntents.create({
amount: calculateOrderAmount(items),
currency: "usd",
automatic_payment_methods: {
enabled: true,
},
});
Bingo! If you know the information by the time that code runs that is where you would put it
Awesome! Thanks so much for all the help. I should have messaged you earlier ๐คฆโโ๏ธ