#ironbeard_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/1268578004611891285
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
confirmCardPayment doesn't have a return_url param, but if you used the Payment Element instead of the Card Element, you'd call confirmPayment instead, which handles redirect with return_url: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements#web-submit-payment. With the Card Element, you'd need to handle all this yourself
Gotcha, awesome. And PaymentElement will handle e.g. ACH Credit / bank transfers?
Yeah
I guess I'll set that up then. Thanks ๐
No problem. Yeah the Payment Element is the move if you want to accept more than just card payments
Is there a way to pass e.g. a customer id to the PaymentElement so they can see e.g. their default payment method instead of entering a card?
There is, yeah. This feature was actually just added recently: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements#save-payment-methods
So actually, I just remembered (it's been awhile since I wrote this code), I'm actually potentially processing two separate payments with possibly two separate subscription client secrets. The reason being is that we have two main types of products: a newsletter (email pdf) and SaaS (which can be upgraded/downgraded etc).
If I recall correctly, the reason I split it into two separate payments was that upgrading and downgrading became a real mess when both the newsletter and the SaaS were on the same Subscription.
Based on a quick glance of the code you linked, it looks like I need to specify the subscription client secret when initializing the PaymentElement? (e.g., in the const options = {clientSecret: '{{CLIENT_SECRET}}', appearance: {[...]}})
So I create the card element using const stripe = Stripe('{{ STRIPE_API_KEY}}') and const cardInstance = stripe.elements().create('card', {style: {base: {fontSize: '16px'}}}); cardInstance.mount('#card-element');
Then my hidden form has possibly 2 client secrets, so I just loop through them and if they have a value I call stripe.confirmCardPayment(clientSecretValue, {payment_method: {card: cardInstance}})
Yeah this is going to be difficult to do with the payment element. We have a flow to initialize the payment element without a client secret, but the return_url on the confirmPayment call is going to be an issue since there will have to be a redirect after the first confirmPayment call
Right, I just thought the same thing.
I'm trying to remember the specifics of why I needed to separate them into two separate subscriptions. I think it was because idealsly the newsletter subscription start/end dates shouldn't change even if the user upgrades/downgrades their SaaS package, but I think that was happening?
That shouldn't change the start/end dates
Hmm ๐ค It would if proration_behavior: 'always_invoice' and billing_cycle_anchor: 'now', right?
yeah billing_cycle_anchor controls that
I wonder why I set it to 'now' ๐
If you don't specify it, it shouldn't change
I remember now (had to search your discord for a post of mine from Sept 2022!).
- To simplify things, we offer two levels of SaaS subscription: data for a single region and data for all regions. Everything is an annual subscription, both the SaaS and the newsletter.
- If someone subscribes to a single region on Jan 1st, theoretically if we didn't have
billing_cycle_anchor: 'now', then on Dec 31st at 11pm they could "upgrade" to the "All Regions" package and access the data for 1hr at a vastly reduced price, then cancel their subscription before midnight. - To combat this, we set
billing_cycle_anchortonow. However, a byproduct of this situation was, if someone subscribed to both the SaaS (single region) and the Newsletter on Jan1st, and then on July1st they upgrade the SaaS to all regions, they wouldn't only be paying the full price for the SaaS (which is good), but they would also be asked to pay for 6 months of the newsletter, since it it's billing cycle would be adjusted to line up with the SaaS.
So, felt weird to ask them to pay more for their newsletter subscription even though it wasn't finished yet. Hence doing these as separate Subscription objects.
I see. So, things will definitely be much simpler if you stick with card element given this
However, I can suggest some workarounds if you really want to move to payment element
Hmm, the redirect_url, and the handling of default payment methods, as well as being able to take bank payments, are all very enticing.
Hmm, the redirect_url
This piece becomes a complication in your flow actually
In reality, we're a small-ish company: 21 people subscribed to newsletter only, 4 people subscribed to both Newsletter+SaaS, 4 people subscribed to the "All Regions" package and 10 people subscribed to the single region stuff.
It's possible that I'm giving more weight to the edge cases than they deserve.
Up to you
Yeah, the redirect url being the issue bc if I'm processing two separate subscription objects, then there's no clear way to say "don't redirect until both of these payments are processed"?
Hello
Taking over
I'm trying to read through previous messages but can you give me a short summary of what you're trying to do?
Sure. I'm interested in ditching CardElement for PaymentElement. But, there's a bit of a nuance where I'm actually creating two Subscription objects and two Charges currently in order to address some edge cases
I see. How exactly are you handling it today?
I'm returning possibly two clientsecrets to the front end and just looping over them and calling stripe.confirmCardPayment(clientSecretValue, payment_method: {card: cardInstance}}) possibly twice
but I'd like Stripe to handle the redirect for me, and the default payment methods, two enticing benefits of the PaymentElement.
But if I used the PaymentElement, then it would possibly redirect before the second subscription is paid for
Have you thought about using SetupIntents to tokenize payment method and create the two subscriptions server-side?
That would save you the trouble of confirming an intent twice
Hmm, not familiar with SetupIntents
Currently I am creating the Subscriptions server-side, in order to send the client secrets?
SetupIntents allow you to store a payment method for future use: https://docs.stripe.com/payments/save-and-reuse
Once stored, you can use it to create Subscriptions via server-side
Interesting. So I would still display a PaymentElements, but I wouldn't need to pass ClientSecrets to the front end. Then, I can listen for webhooks to actually create the Subscription object(s) and provision access?
You'd need to pass client-secret but it would be for a SetupIntent unless you use defer-intent approach
https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=setup
Then, I can listen for webhooks to actually create the Subscription object(s) and provision access?
Correct
- Is this compatible with allowing an existing customer to use default payment method in the PaymentElements?
- The docs seem to suggest going the async route and creating the Subscription via webhooks. But if I wanted to gaurantee that they can immediately access their SaaS after clicking "submit," I should create the subscriptions using the session_id in the GET request of
success_url?
And I could do a single SetupIntent client-secret, I wouldn't need two for the even where I create two Subscriptions?
Oh I think you're looking at Stripe hosted Checkout Session docs.. We also support SetupIntents with PaymentElement: https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
1/ Yes you can create SetupIntent for existing customers too. It doesn't automatically set the payment method as default. You can listen to webhook events for SetupIntents and set that payment method as default by calling the Update customer API: https://docs.stripe.com/api/customers/update#update_customer-invoice_settings-default_payment_method
Hmm. I'm realizing that a lot of complications could be addressed if we just provided the newsletter pdf subscription as a complimentary item when people subscribed to the data access.
I think I need to regroup a bit and discuss with others before progressing, but I appreciate your help and pointing me in the right direction!