#xqprtzcv
1 messages · Page 1 of 1 (latest)
hello!
Is there a webhook for a new term starting
you can monitor the current_period_start and current_period_end in the previous_attributes in the customer.subscription.updated webhook
Or i guess, you could alternatively listen for invoice.created and check the billing_reason : https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
How do I get the current subscription product when I get a "type": customer.subscription.updated (because I believe currently I will see the updated and not the current product).
do you have an example customer.subscription.updated event for me to refer to?
Thank you. Sorry for the delay, here you go:
{'id': 'evt_1NAkc4HtzQiUYLb0LbReahTP', 'object': 'event', 'api_version': '2022-11-15', 'created': 1684807571, 'data': {'object': {'id': 'sub_1NAkbpHtzQiUYLb0IXLrr0tz', 'object': 'subscription', 'application': None, 'application_fee_percent': None, 'automatic_tax': {'enabled': True}, 'billing_cycle_anchor': 1684807557, 'billing_thresholds': None, 'cancel_at': None, 'cancel_at_period_end': False, 'canceled_at': None, 'cancellation_details': {'comment': None, 'feedback': None, 'reason': None}, 'collection_method': 'charge_automatically', 'created': 1684807557, 'currency': 'usd', 'current_period_end': 1716429957, 'current_period_start': 1684807557, 'customer': 'cus_NuKyCooxBeYnQL', 'days_until_due': None, 'default_payment_method': None, 'default_source': None, 'default_tax_rates': [], 'description': None, 'discount': None, 'ended_at': None, 'items': {'object': 'list', 'data': [{'id': 'si_NwdtMWu6PqRgIh', 'object': 'subscription_item', 'billing_thresholds': None, 'created': 1684807557, 'metadata': {}, 'plan': {'id': 'price_1N8RGiHtzQiUYLb0BfDXhbNw', 'object': 'plan', 'active': True, 'aggregate_usage': None, 'amount': 17976, 'amount_decimal': '17976', 'billing_scheme': 'per_unit', 'created': 1684256556, 'currency': 'usd', 'interval': 'year', 'interval_count': 1, 'livemode': False, 'metadata': {'users': '2'},
'nickname': None, 'product': 'prod_NuFlhFY1axH37S', 'tiers_mode': None, 'transform_usage': None, 'trial_period_days': None, 'usage_type': 'licensed'}, 'price': {'id': 'price_1N8RGiHtzQiUYLb0BfDXhbNw', 'object': 'price', 'active': True, 'billing_scheme': 'per_unit', 'created': 1684256556, 'currency': 'usd', 'custom_unit_amount': None, 'livemode': False, 'lookup_key': None, 'metadata': {'users': '2'}, 'nickname': None, 'product': 'prod_NuFlhFY1axH37S', 'recurring': {'aggregate_usage': None, 'interval': 'year', 'interval_count': 1, 'trial_period_days': None, 'usage_type': 'licensed'}, 'tax_behavior': 'exclusive', 'tiers_mode': None, 'transform_quantity': None, 'type': 'recurring', 'unit_amount': 17976, 'unit_amount_decimal': '17976'}, 'quantity': 1, 'subscription': 'sub_1NAkbpHtzQiUYLb0IXLrr0tz', 'tax_rates': []}], 'has_more': False, 'total_count': 1, 'url': '/v1/subscription_items?subscription=sub_1NAkbpHtzQiUYLb0IXLrr0tz'}, 'latest_invoice': 'in_1NAkbpHtzQiUYLb0EFAdUnfG', 'livemode': False, 'metadata': {'pk': '107218753037995822977', 'users': '[]'}, 'next_pending_invoice_item_invoice': None, 'on_behalf_of': None, 'pause_collection': None, 'payment_settings': {'payment_method_options': None, 'payment_method_types': ['card'], 'save_default_payment_method': 'off'}, 'pending_invoice_item_interval': None, 'pending_setup_intent': None, 'pending_update': None, 'plan': {'id': 'price_1N8RGiHtzQiUYLb0BfDXhbNw', 'object': 'plan', 'active': True, 'aggregate_usage': None, 'amount': 17976, 'amount_decimal': '17976', 'billing_scheme': 'per_unit', 'created': 1684256556, 'currency': 'usd', 'interval': 'year', 'interval_count': 1, 'livemode': False, 'metadata': {'users': '2'}, 'nickname': None, 'product': 'prod_NuFlhFY1axH37S', 'tiers_mode': None, 'transform_usage': None, 'trial_period_days': None, 'usage_type': 'licensed'}, 'quantity': 1, 'schedule': None, 'start_date': 1684807557, 'status': 'active', 'test_clock': None, 'transfer_data': None,
'trial_end': None, 'trial_settings': {'end_behavior': {'missing_payment_method': 'create_invoice'}}, 'trial_start': None}, 'previous_attributes': {'status': 'incomplete'}}, 'livemode': False, 'pending_webhooks': 1, 'request': {'id': 'req_NMeV1M3FbMwQlG', 'idempotency_key': 'b660a63b-75b8-43ea-b129-0de934c6114a'}, 'type': 'customer.subscription.updated'}
actually this is probably the event you'll want to look at (where you downgraded) : https://dashboard.stripe.com/test/events/evt_1NAkirHtzQiUYLb05GlAIBOp
you can see in the previous Product in the previous attributes
Ok, I see that. And then is it possible to determine which one is currently active?
have you tried looking at the event data under items?
Looking at it now
I am still struggling to figure out what the current subscription is in general for a "type": customer.subscription.created event
Hi @earnest wind I'm taking over this thread.
Hey Jack, thanks.
As Alex explained earlier, you can find the current subscription items in the items field of the susbcription.
Ok, I guess my problem is that the current subscription in the items field is the one that will be on the next invoice. So in the example above, that one says "1" user, even though the current active subscription on my site is the "2" user subscription until the end of the term.
Ultimately, what I am trying to do is to process all "type": customer.subscription.updated which the server will read, and based on the stream of those events, I will always be able to tell what the current subscription is, and when it will expire.
I am not sure if there is a better way to keep track of the current subscription than that, or if I need to do something more complex.
Maybe I'm missing something, but can you tell me why the subscription items in items don't work for your case?
Sure.
This is the object I am looking at by the way: https://dashboard.stripe.com/test/events/evt_1NAkirHtzQiUYLb05GlAIBOp
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
This has "current_period_start": 1684807557 and "current_period_end": 1716429957
This is the term for the subscription that has already been paid for. The subscription that has been paid for is a 2 user subscription, which costs $180.
Sometime during that term, the user decides to downgrade to a 1 user subscription which costs $120.
When they downgrade, the subscription in items changes to the "1 user" subscription
The active "2 user" subscription can be seen in the "previous_attributes" field
So maybe the answer is that if the "previous_attributes" field exists, then the current subscription is the one listed there, and if that field doesn't exist, then it the one in the main "items" field.
Hmm, the current subscription items are already reflected in the items field, why do you need to check the previous_attributes?
Or maybe can you tell me the problem that you are trying to solve?
I am just going to think about it a little, and maybe ask again later.