#bugkiller.
1 messages ยท Page 1 of 1 (latest)
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.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
we're giving proper access if subscription status is active ๐ฆ
we used collection_method 'charge automatically'
so it was fine
Yeah I guess you'll need to provision access based on invoice.paid events instead
now how to do for subscription made with 'send_invoice'
Depends how you're giving access to your service? I assume by listening for customer.subscription.created events?
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 ๐ฆ
yeah, probably best to refactor to use the invoice.paid event to provision access to your product
https://stripe.com/docs/billing/subscriptions/webhooks#:~:text=Sent when the invoice is successfully paid. You can provision access to your product when you receive this event and the subscription status is active.
what about my cron?
not sure what specifically you're asking?
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
then I suppose you can use a cron and check the status every month if that's what you need to do
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 ^^
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?
yes, I didn't see that you had a question though. how can I help?
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?
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.
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?
you get both those webhooks at the same time
ok.
so my question is "is it ok to replace invoice.payment_succeeded webhook to invoice.paid?
yes
it just returns an Invoice object in the data field of the Event, which is the same, yes.
one more question. where can I cuztomize invoice email?
can you describe in more detail what specifically you'd like to customise and in what way?
for example, I want to add some custom text into the invoice email
you can experiment with the settings on https://dashboard.stripe.com/settings/billing/invoice for memos/footers etc
and see also https://stripe.com/docs/invoicing/customize
ok
another question how can I get metadata on invoice.paid
if I create metadata when I create subscription
I can get it?
thanks
what about metadata I added when I create stripe checkout session for subscription
that also can be collected in 'invoice.paid' event?
you can pass metadata in https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata and then it's present in the Invoices of the resulting subscription through the field in my previous message.
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
you can do that yes.
if you want to, yes. Otherwise you can just wait.
yes.
anyway as you said, you need to step away and go test some of these things so I'll let you do that
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
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 ๐
I got it
invoice.subscription_details.metadata
๐
no data like
invoice.subscription_data.metadata
but I see
invoice.subscription_details.metadata
yes.
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?
it's that field, like I said
I did explicitly already answer that exact question
you can pass metadata in https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata and then it's present in the Invoices of the resulting subscription through the field in my previous message.