#smokey_subscription-collectionmethod

1 messages ¡ Page 1 of 1 (latest)

cyan remnantBOT
#

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

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

meager elmBOT
mystic badger
#

You need to expand the latest invoice

tranquil cape
#
sub = stripe.Subscription.create(
      customer=customer_id,
                items=[
                    {
                        'price': price_id
                    }
                ],
                payment_behavior='allow_incomplete' if is_setup else 'default_incomplete',
                payment_settings={'save_default_payment_method': 'on_subscription'},
                expand=['latest_invoice.payment_intent', 'pending_setup_intent'],
                collection_method='charge_automatically' if is_setup else 'send_invoice',
                days_until_due=0
            )
#

Here is better formatted., Latest invoice is expanded

mystic badger
#

Okay, that still works for me and I'm using stripe-python

tranquil cape
#

Is it OK to paste the return object here?

mystic badger
#

If you

#

could just paste the Subscription ID that would be better

tranquil cape
#

This code worked perfectly about 2 months ago, I came back to the propject today and it's not working..

#

And yeah sure

mystic badger
#

I can look it up and it won't clutter things

tranquil cape
#

sub_1OtIB0B8l4UplgS6kO8eB7hQ

mystic badger
#

Thanks, taking a look

tranquil cape
#

Thanks! Appreciate it

mystic badger
#

Did your version of stripe-python change?

#

It looks like you're on 7.11.0 in this request

tranquil cape
#

I don't think so, I reinstalled from my requirements created the last time I was on this project

#

what v of stripe-python are you using?

mystic badger
#

I have multiple. Some integrations are on 8.0.0, a few are on 5.4.0

tranquil cape
#

Actually it turns out that latest_invoice is indeed returning an object, my parser was just messing up when I was viewing it, but latest_invoice.payment_intent is null

#

previously it would contain a client secret

mystic badger
#

Ah, yeah payment_intent: null,

tranquil cape
#

Did something change with Stripe recently?

#

Because I didn't require to use days_until_due either, but now I do

mystic badger
#

Were you always using collection_method: "send_invoice"?

tranquil cape
#

Yep

#

Basically IIRC, collection_method is set to send_invoice if the customers stripe account hasn't been fully setup with a card linked. So I create the invoice, and the client adds their card and then charges for the invoice

mystic badger
#

The default API version for this account is 2022-11-15 but the API version on this request is 2023-10-16

#

The Customer doesn't have a Stripe account. Unless this is a Connected Account.

#

But I think you mean the Customer hasn't set up a default payment method

tranquil cape
#

My bad, I mean a customer object

mystic badger
#

Okay, cool. Just want to make sure we're on the same page

#

Okay yes I confirmed my integration does the same thing ( using stripe-python v 5.4.0 and API version 2020-08-27)

#

collection_method: "send_invoice" returns a null as a Payment Intent.

#

The Hosted Invoice Page doesn't create a Payment Intent until the user confirms the payment intent.

tranquil cape
#

hmm I need a client secret through to process the payment. Everything is self hosted on my site - no stripe invoice page

mystic badger
#

Ummm....no you don't?

tranquil cape
#

How come you're getting the same result as me on older version of package & api?

mystic badger
#

Collecting payment yourself and using send_invoice are mutually exclusive

tranquil cape
#

previously it would return a client secret

#

yeah but if the payment requires 3ds then it has to be done on the client which requires a secret

mystic badger
#

That has always been the case since I started at Stripe over 2 years ago

#

I think what would make more sense (based on how you described using the send_invoice option) woul be that you should try creating your Subscriptions with collection_method: "charge_automatically" and for those Customers who don't have a saved Payment method you should include payment_settings.save_default_payment_method:"on_subscription"

tranquil cape
#

I'm confused as to why everything worked couple months back, but not now. And I've checked the changelog and see no mention of this

mystic badger
#

Do you have an example of the previous flow? The tought part is "a couple months" is past our retention time for API requests but I could look at some objects

tranquil cape
#

I routinely nuke my test data so I'm not sure if it would still be visible?

mystic badger
#

And when the Customer succeeds in their first payment it will automatically save that paymemt method as their default

tranquil cape
#

The flow is this:

Users signs up
Then goes to setup screen
They choose pay as you go, or monthly
If payg, their card details is attached to the customer object
if monthly, I create an invoice, and process the payment and save their card details to the customer object.

I had quite a bit of trouble with this last time and spent a fair amount of time with someone from Stripe going through this, and this turned out to be the best option

mystic badger
#

I routinely nuke my test data so I'm not sure if it would still be visible?
Without examples it's really hard to dig further into this

#

That makes sense but I don't see a need for send_invoice in any of that

meager elmBOT
tranquil cape
#

I believe its because the customer object doesn't have a card attached. I think the sub is created, the secret is passed back to the client, and then the client processes the payment with the sub ID

earnest vortex
#

still no reason to use send_invoice for any of that

#

smokey_subscription-collectionmethod

tranquil cape
#

ok can you tell me where I'm going wrong in my logic?

earnest vortex
#

Me and @mystic badger don't understand why you are using send_invoice. There's really no reason to do this at all. This is for when you want us to email the end customer to pay later, often via bank transfers, like for B2B

#

What you described above you can totally use charge_automatically

tranquil cape
#

Yeah I guess you're right. using send_invoice was actually the recommendation of someone from this support group about 6 months ago. I remember coming here for support when i couldn't figure out how to achieve what I wanted...

#

I guess I'll have to try figure out how to get everything to work with charge_automatically

earnest vortex
#

What you likely are missing is payment_behavior: 'default_incomplete' on Subscription creation. That will finalize the Invoice, give you a PaymentIntent and then you can use it to render PaymentElement client-side for example

tranquil cape
#

well default_incomplete is already there on initial subscription creation

earnest vortex
#

then no reason to use send_invoice at all in that case (you were explicitly saying you handle having a save card or not differently)

tranquil cape
#

I think you're totally right. I've removed send_invoice and everything seems to be working as I'd expect.... I really have no idea why I was using send_invoice

earnest vortex
#

yeah likely a misunderstanding!

tranquil cape
#

Thanks a lot for the help, I really appreciate it. And you too @mystic badger. You spent the best part of 35 minutes helping me with this.