#b33fb0n3_best-practices
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/1226834041223905280
đ 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.
- b33f_paymentmethod-retrieve, 3 days ago, 20 messages
- b33fb0n3_api, 4 days ago, 11 messages
Hello! If your intention is to save payment details for future usage then you should be mostly using Setup Intents: https://docs.stripe.com/payments/save-and-reuse
In your UI, which APIs are you using to 'save' right now?
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
I looked at this saving method, but was a little bit confused, that I need a session, and a customer and an extra page and and and
So I thought: why can't I just create a new payment method?
You need a Customer object to save cards, yes. Otherwise the PMs are not reusable
I would bind the paymentmethod to the customer after the customer clicked "Pay". Is that possible?
If the 'pay' function facilitates a payment with the card you just created then no
You can't attach them after the payment. You'd attach them during the payment: https://docs.stripe.com/payments/save-during-payment
(or before like I linked earlier)
hmmm ok. Is there any possibility I can maintain the single responsibility principle?
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.
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)
ok.. can I somehow only create this setup intent without redirecting the customer somewhere and only get the payment_method-ID back?
No because the process of confirm with Setup Intent will carry out any 3DS/auth challenges requested by bank
What you're describing overall sounds more akin to a two-step payment flow, which is enabled via a Confirmation Token: https://docs.stripe.com/payments/build-a-two-step-confirmation
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
so it's like the -> Payment Method collects the payment details and generates this confirmation token. This confirmation token includes the payment details and can be used then the customer really pays, right?
Can I update this confirmation token with new data (e.g. customer add payment method and some minutes later he adds a shipping address)?
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
so in my case -> Payment Method collects the payment details and generates this confirmation token and saves it in the db. -> Shipping address retrieve this when a new address is entered and generates a new one with the data from the confirmation token before and the new/chosen shipping address, right?
It sounds like you have a checkout flow which has multiple forms to submit?
yea, it looks like this:
Checkout Page:
-> Product List
-> Payment Method
-> Shipping Address
-> ...
-> 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
..
Confirmation Token likely not a good fit then as the idea is that you collect all details in a single submission
oh ok. Are there ways to collect data one after another and then confirm the payment?
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
give me a few minutes to check the possibilities please
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
Thanks for your time. I think that's a good solution, but does not follow the single responsibility principle..
I'm still thinking about it and the idea has just occurred to me that I can simply handle "shipping" myself without involving Stripe. So Stripe really only handles the payment processing and I take care of the rest. What do you think?
With that idea -> Payment Method is single responsible for the confirmation token best practise and can handle the payment stuff and the shipping stuff and other things are just handled by myself. The the customer choose another payment method or create a new payment method, the confirmation token just get (re-)created and everything will be fine, correct?
Sure, seems fine. Just means you'd no shipping records in Stripe
Can't I append it when creating the paymentintent which is then directly confirmed?
https://docs.stripe.com/api/payment_intents/object#payment_intent_object-shipping
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yeah I guess so