#bugkiller.

1 messages ยท Page 1 of 1 (latest)

alpine brambleBOT
torn sleet
#

Hello! Just how it works:

When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as active.
https://stripe.com/docs/api/subscriptions/create#:~:text=When sending an invoice%2C Stripe will email your customer an invoice with payment instructions and mark the subscription as active.

trim ruin
#

we're giving proper access if subscription status is active ๐Ÿ˜ฆ

#

we used collection_method 'charge automatically'

#

so it was fine

torn sleet
#

Yeah I guess you'll need to provision access based on invoice.paid events instead

trim ruin
#

now how to do for subscription made with 'send_invoice'

torn sleet
#

Depends how you're giving access to your service? I assume by listening for customer.subscription.created events?

alpine brambleBOT
trim ruin
#

giving permission by listening invoice.payment_succeeded

#

event

#

but generally, we have cron job to manage the permission for some reason (for example to give some credits in each month) in there I'm just checking if subscription is active ๐Ÿ˜ฆ

trim ruin
#

what about my cron?

grand yacht
#

not sure what specifically you're asking?

trim ruin
#

for example you made yearly subscription ok?

#

for our end, we're giving some internal credits monthly

#

so we have cron to give the users monthly credits

#

so this can't be done by invoice event because you will pay invoice once a year

grand yacht
#

then I suppose you can use a cron and check the status every month if that's what you need to do

trim ruin
#

which status??

#

you're marking subscription as 'active' even if invoice wasn't paid

grand yacht
#

yes, as said that's just how it works

#

so if you want, check that the Subscription is active, and also check subscription->latest_invoice->status is paid.

#

I suggest that ^^

trim ruin
#

ok. maybe I'll check invoice status paid

#

def get_last_paid_billing_cycle_start_end(self, subscription_id):
try:
invoices = stripe.Invoice.list(subscription=subscription_id, limit=10)
for inv in invoices:
if inv.status == 'paid':
items = sorted(inv.lines.data, key=lambda x: x.period.end, reverse=True)
item = items[0]
return datetime.fromtimestamp(item['period']['start']), datetime.fromtimestamp(item['period']['end'])
return None, None
except Exception as e:
print(e)
return None, None

#

I already have code something liek this.

#

I'll use it then

#

Are you here?

grand yacht
#

yes, I didn't see that you had a question though. how can I help?

trim ruin
#

my question is what's the difference between

#

invoice.payment_suceeded vs invoice.paid

#

I can completely remove invoice.payment_succeeded and replace it to invoice.paid?

#

is that ok?

grand yacht
#

invoice.paid is better since it happens even if an Invoice is "marked as paid" while invoice.payment_succeeded only happens if there's an actual payment. Bascially invoice.paid is better and replaces the other event, we just didn't remove invoice.payment_succeeded yet.

trim ruin
#

for the invoice payment which was sent (by subscription creation with 'send_invoice' for collection_method), I got invoice.payment_succeeded webhook

#

should I still need to have invoice.paid webhook also?

grand yacht
#

you get both those webhooks at the same time

trim ruin
#

ok.

#

so my question is "is it ok to replace invoice.payment_succeeded webhook to invoice.paid?

grand yacht
#

yes

trim ruin
#

ok, it will have same params

#

right?

grand yacht
#

it just returns an Invoice object in the data field of the Event, which is the same, yes.

trim ruin
#

one more question. where can I cuztomize invoice email?

grand yacht
#

can you describe in more detail what specifically you'd like to customise and in what way?

trim ruin
#

for example, I want to add some custom text into the invoice email

grand yacht
trim ruin
#

ok

#

another question how can I get metadata on invoice.paid

#

if I create metadata when I create subscription

#

I can get it?

trim ruin
#

thanks

#

what about metadata I added when I create stripe checkout session for subscription

#

that also can be collected in 'invoice.paid' event?

grand yacht
trim ruin
#

let me test.

#

thanks. will contact you again after the testing soon

#

one more question should I call invoice finalize and send_invoice myself to make invoice to be sent quickly?

#

I heard invcoice email will be sent in 1 hour

grand yacht
#

you can do that yes.

trim ruin
#

so after creating subscription. need to retreive invoice

#

and call finalize and send ?

grand yacht
#

if you want to, yes. Otherwise you can just wait.

trim ruin
#

how many time should I wait?

#

1 hour a sI know

grand yacht
#

yes.

#

anyway as you said, you need to step away and go test some of these things so I'll let you do that

trim ruin
#

hi, I created metadata when I create subscription

#

but invoice hasn't it

languid dune
#

Hey! Taking over for my colleague. Metadata are scoped to the object you've created with, they aren't propagated to inner objects

#

So it's expected that the invoice hasn't the metadata you've created with the Subscription

grand yacht
#

but it will have it in the field that I mentioned

#

the metadata is not copied to invoice.metadata, but it will be in invoice.subscription_data.metadata per the API docs I linked above ๐Ÿ™‚

trim ruin
#

I got it

#

invoice.subscription_details.metadata

#

๐Ÿ™‚

#

no data like

#

invoice.subscription_data.metadata

#

but I see

#

invoice.subscription_details.metadata

grand yacht
#

yes.

trim ruin
#

what about in case I add metadata on stripe checkout session (for subscription)

#

I can also get that metadata by same field? invoice.subscription_details.metadata

or on another field?

grand yacht
#

it's that field, like I said

trim ruin
#

ok, thank you I'll try.

#

thanks for your help today. appreciated it