#b33fb0n3_best-practices

1 messages ¡ Page 1 of 1 (latest)

rigid nymphBOT
#

👋 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/1226834041223905280

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

gleaming lanceBOT
#

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.

mellow pivot
#

In your UI, which APIs are you using to 'save' right now?

brazen tundra
#

right now I am using none to save it. I currently thinking about the process and how everything should work together to create this cart checkout

brazen tundra
#

So I thought: why can't I just create a new payment method?

mellow pivot
#

You need a Customer object to save cards, yes. Otherwise the PMs are not reusable

brazen tundra
mellow pivot
#

If the 'pay' function facilitates a payment with the card you just created then no

#

(or before like I linked earlier)

brazen tundra
#

hmmm ok. Is there any possibility I can maintain the single responsibility principle?

mellow pivot
#

I don't know what that means

brazen tundra
# mellow pivot I don't know what that means

Imagine this setup of components or "parts of the app":
Checkout Page:
-> Product List
-> Payment Method
-> Shipping Address
-> ...

Now imagine these parts of the app are person that talk or don't talk to each other.
Checkout Page should talk to all, because it needs the details to the products, the details to the payment methods and so on.
Payment Method just need to collect the payment method. For Payment Method it doesnt matter what products are there and where to ship to. So Payment Method don't talk to Product List or Shipping Address
Payment Method is single responsible for the payment collection. For nothing else.

mellow pivot
#

If you want it 'isolated' , then you'd use a Setup Intent with Payment Element to collect and save the PM that can then be used in subsequent payments

#

That's the first guide I linked

#

Ideally you consolidate them so that you save the card during the payment, which will make your checkout more efficient (less API calls, etc)

brazen tundra
#

ok.. can I somehow only create this setup intent without redirecting the customer somewhere and only get the payment_method-ID back?

mellow pivot
#

No because the process of confirm with Setup Intent will carry out any 3DS/auth challenges requested by bank

#

i.e. collect the payment details in the Element, generate a Confirmation Token from those, then use that token if the user utlimately decides to pay

brazen tundra
mellow pivot
#

This confirmation token includes the payment details and can be used then the customer really pays, right?
Correct yes, it's a token that encapsulates all details of the payment (amount, currency, etc) as well as the card details

#

No they're immutable, you'd just generate a new token with the updated details

brazen tundra
mellow pivot
#

It sounds like you have a checkout flow which has multiple forms to submit?

brazen tundra
#

-> Payment Method is a seperated and isolated form to include a payment method into the order
-> Shipping Address is also a seperated and isolated form to include only the shipping address
..

mellow pivot
#

Confirmation Token likely not a good fit then as the idea is that you collect all details in a single submission

brazen tundra
#

oh ok. Are there ways to collect data one after another and then confirm the payment?

mellow pivot
#

I've outlined a few ways, yes. There's no perfect solution here really as requiring submission at each step prevents you from adapting best practices

brazen tundra
#

give me a few minutes to check the possibilities please

mellow pivot
#

What I would do would be adapt your form so payment and shipping are handling by the same submission, then you can use the Confirmation Token approach

brazen tundra
#

Thanks for your time. I think that's a good solution, but does not follow the single responsibility principle..

brazen tundra
brazen tundra
mellow pivot
#

Sure, seems fine. Just means you'd no shipping records in Stripe

brazen tundra
mellow pivot
#

Yeah I guess so