#ben_api

1 messages ¡ Page 1 of 1 (latest)

modest pilotBOT
#

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

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

serene kite
#

Hello, can you tell me more about when you are making that subscription update call? It sounds like you tried to update a subscription before it was actually fully started by the checkout session creating it

viral grove
#

I am enumerating over the users Subscriptions after re receive the payment method attached to customer event

#

I then do a Stripe::Subscription.list({customer: stripe_customer}).auto_paging_each do |subscription|

#

and update their subscriptions to refllect the new payment method set as default

serene kite
#

Gotcha, looking in to how this works. I didn't realize that those were listable before the checkout session ended

viral grove
#

thanks Pompey

serene kite
#

Still looking in to this, taking a step back, can you explain what this process looks like from your customer's perspective? Like what process are they doing where they will go through a Checkout Session in setup mode and then immediately one in subscription mode?

viral grove
#

absolutely.

  1. We have a line of code that presents a user with a payment update if they have an invoice that has not been processed.
  2. we present the user with a link to update their payment method using a Checkout Session. with setup_mode
  3. this triggers a payment_method.attached which we set the payument as default
  4. we then get a user.updated event and thats when we enumerate their subscriptions for ensuring existing subscriptions point to the proper card on file.
#

that being said, at anytime the user can just make a subscription purchase from the checkout with subscription mode and add tehir Payment Details there

serene kite
#

Gotcha, and you are setting them to empty strings so that the subscriptions use the default that is set on the customer itself? In that case, it may be easiest to not list and iterate through all of these subscriptions each time, if you listen to checkout.session.succeeded events and update subscriptions as they are created that should allow you to make sure that all subscriptions created that way use the default for the customer

viral grove
#

Correct with the empty string because it would have had a previous payment method associated.
Also we set , cancel_at_period_end: subscription.cancel_at_period_end if its present otherwise it seemes that its always reset to true after update when blank.

But that resulted in an error, which then is why we made it conditional. so if there is not a cancle_at_period present we dont attempt to set the field, otherwise we get an error that a checkout session has not yet completed.

However this continues to occur.

#

the issue with the aforementioned is that if a previously created subscription has a cc that expired

#

they wont create a new subscription we want to give them a period to update their payemnt method

#

moreover if they have 1 subscription that fails to process they may have others which is why we are enumerating their subs

serene kite
#

Is there some process you have where this field might get set to a specific PM after it has been created?
If you do want to keep doing this iterative method, I think the best thing may be to just ignore this error and to add logic in your checkout.session.completed handler to unset the default PM field.

viral grove
#

ok thanks pompey

#

is there a way to query if a subscription is still in chekcout?

modest pilotBOT
serene kite
#

Not that Checkout is still active specifically, but code-wise you would be able to see that these subscriptions are incomplete

viral grove
#

what will incomplete in this case indicate?

serene kite
#

That the first payment on the subscription has not been made yet, so that could be a good indication to try to skip them for this update

viral grove
#

perfect thanks Pompey!

#

that might work as another option

#

i appricate your assistance and work on an amazing API/Product