#rotfeliga-product-subs

1 messages ยท Page 1 of 1 (latest)

fiery kayak
#

Hello! Is this something that worked for you in the past, and if so, can you send me an example event ID where you see event[data][object][product] populated?

rare bough
#

Hello! I just investigated some json blobs from stripe test events in the past but haven't used it in production.

#

Is there a recommended way to get the product_id of customer.subscription.created events?

fiery kayak
rare bough
#

Currently I'm using event = stripe.Webhook.construct_event(payload, sig_header, endpoint_secret) to get the event

#

Is there an analog for items or is items inside the event blob somewhere?

fiery kayak
#

The event has a subscription object, which you can then pull items from

rare bough
#

ah .. okay thanks karbi! ๐Ÿ™‚

#

One last thing, I'm getting customer_email from the json payload blob strip is sending me:

payload = input_event.get("body")

customer_email = json.loads(payload)["data"]["object"].get("customer_email")

#

Is there a more principled way to get this ?

#

(payload is the same as the payload in event = stripe.Webhook.construct_event(payload, sig_header, endpoint_secret))

fiery kayak
#

You could jsut get this information from event instead of off the raw payload.

customer_email = event.data.object.customer_email

rare bough
#

wow, thanks

#

one final thing.

I want to know when a user becomes a paying subscriber and when their subscription has ended.

Am I correct in assuming when they becoming a paying subscriber they will always trigger a:

customer.subscription.created event

#

and when they stop paying they will trigger one of:

customer.subscription.deleted
subscription_schedule.aborted
subscription_schedule.canceled

?

#

The reason for this, is I'm already keeping track of all my users via their email but I simply want to know when they are paying subscribers or not so I can bump them up to a paid tier of usage or knock them down to the free tier.

#

(Hence all my previous questions about product_id, customer_email, subscriptions, etc)

#

One edge case is when they stop being paying, I want them to finish the duration of their paid subscription.

#

So ideally I'd only have to deal with one event that tells me when they are no longer in the "paid customer" category.

#

Not that they will become one in the future

fiery kayak
#

For the case of knowing when the become a paying subscriber you'll want customer.subscription.created in combination with invoice.paid to confirm that the subscription has actually become active.

#

For the case where they've stopped paying - you'll likely want customer.subscription.deleted which will be triggered when the subscription in stripe has actually ended/is over.

rare bough
#

TY. For the first case do I have to keep track of the customer state? I was hoping to avoid this.

#

Ideally, I'd like to listen for invoice.paid and check it corresponds to a subscription for a particular product

#

(btw, in the lingo of event or payload where does invoice.paid live?)

fiery kayak
#

Really, all of this depends on the specifics of your integration - you could just listen to invoice.paid events and tie them back to the subscription in order to track successful payments made by a customer. However, if you want to keep track of any changes that are happening on the subscription (the specific biling cycle dates, when products are added or quantities change) you'd need other events like customer.subscription.updated.

rare bough
#

My setup is super simple for now. No other complexity.

fiery kayak
#

invoice.paid is just another event type that would give you an Invoice instead of a Subscription so you woud get it back from an event

rare bough
#

I am happy to kick the can and deal with complexity like that later.

#

Ok, so to summarize in order to detect a paying subscriber, I can listen for invoice.paid (and confirm that its for the product with product_id = X)

#

and then to see when they are no longer paying

#

I can listen for subscription.deleted

#

Is that correct? And thank you very much karbi.

fiery kayak
#

Yes, that sounds right

#

I need to head out, but @remote moon can help if you have any follow-up questions

rare bough
#

np, thnk you!

#

@remote moon my only follow up question is I know how to create test events with the stripe cli for say invoice.paid is there a way to do that and also set the product_id of the test event?

remote moon
#

Catching up. Is this with the stripe trigger command?

rare bough
#

Yes

#

So i want to do say stripe trigger customer.subscription.deleted AND specify the product_id of that event

#

I understand that might not be possible, but I wanted to double check.

remote moon
rare bough
#

No problem. Thanks @remote moon

#

@remote moon somewhat related, can I trigger an invoice.paid event?

#

I tried stripe trigger invoice.paid and it says its not supported

#

Ah nevermind it appaears invoice.payment_succeeded is the alternative

rare bough
#

I would rather not keep track of state externally and was hoping to be able to get the product id from the invoice.payment_succeeded event type

#

one second, i think i found it ..

#

sorry again

#

event['data']['object']['lines']['data'][0]['price']['product']

#

yep ๐Ÿ™‚

serene jay
#

yay!

rare bough
#

One final thing @serene jay customer.subscription.deleted has a customer field but no customer_email, is there an alternate way to get this ? Should I do a query of some kind?

serene jay
rare bough
#

stripe.Customer.retrieve(customer_id)["email"]

#

sorry for the specific requirements, i have a dead simple subscription and am trying hard to avoid having an extra database to think about

serene jay
#

I would separate that code in 2, handle errors, make sure a real customer is return, etc., but yes

rare bough
#

yep, thx ๐Ÿ™‚

#

Can a paying customer change their email?

serene jay
rare bough
#

i c. we can do it

#

but can the customer who is a subscriber ever do it?

#

is it fair to assume they can't do it unless we do it for them somehow?

#

we created a subscription link with no code, i imagine the customer can choose to cancel, etc which makes sense, but can they also change their email address?

serene jay
#

I don't think so but hard to say with what you said, we have numerous products, each working differently, so depends waht you use

#

but no hosted surface today lets a customer change their own email address. But it might happen in the future as we improve those UI flows

rare bough
#

ok, were very much in kick the can mode so this might work for our startup launch for a few months if i had to guess

#

thank you again @serene jay

serene jay
#

sure thing! Good luck!