#itchtherightspot_best-practices

1 messages ยท Page 1 of 1 (latest)

night sigilBOT
#

๐Ÿ‘‹ 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/1369363815090749512

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

west palm
#

I'll go warm up chicken noodle soup. be back in 20 seconds

#

back

dense crystal
#

Hi! During the initial creation of a Subscription & successful payment of its initial Invoice using Checkout, you'll actually see a number of events:

customer.subscription.updated
invoice.payment_succeeded
invoice.paid
invoice.updated
customer.subscription.created
invoice.finalized
invoice.created
checkout.session.completed

During a subsequent successful event using a saved card, you'd only get:

customer.subscription.updated
invoice.payment_succeeded
invoice.paid
invoice.updated
customer.subscription.created
invoice.finalized
invoice.created

A Subscription is the container for Invoices, represent the amounts owning for the period. Invoices are paid by one or more Payment Intents, and so you'll also see their events:

payment_intent.created
payment_intent.partially_funded
payment_intent.payment_failed
payment_intent.processing
payment_intent.requires_action
payment_intent.succeeded

In fact, you'll want to listen to payment_intent.requires_action events in case an associated Invoice requires action from the customer.

west palm
#

Wow thats alot of events to listen to.

dense crystal
#

You don't necessarily need them all, but there are a lot.

west palm
#

Is it safe to say for a simple case of subscription, I should listen for checkout.session.completed for initial payment and payment_intent.requires_action for reoccurring payment?

dense crystal
#

To do what?

west palm
#

For a monthly or yearly subscription

dense crystal
#

To do what?

#

What are you using the event for?

dense crystal
west palm
#

To validate is a user is a active paying member. I essentially want to listen to monthly webhook for an enrolled user

dense crystal
#

Right, so the two key questions are:

  1. How do I know that my customer's subscription has become "paid up"; and
  2. How do I know that my customer's subscription is no longer "paid up"

Right?

west palm
#

Right to point 1.

dense crystal
#

invoice.paid will be emitted whenever an Invoice is successfully paid. checkout.session.completed tells you only that the Checkout Session was completed; it doesn't (explicitly) tell you anyhting about the Subscription's status. In the case of the first Invoice / payment on a Subscription, you could use checkout.session.completed instead, but invoice.paid would be logical to use for future successful payments.

west palm
#

Ahh so it is invoice.paid not invoice.payment_succeeded. Final question is am I to assume invoice.paid means a new subscription object is created as per your statement A Subscription is the container for Invoices, represent...

dense crystal
#

They both still exist I think.

#

No, only one Subscription Object is created per subscription.

west palm
#

Gotcha

#

Well thank you for your time.

dense crystal
#

Of course! Does that all make sense? Is it enough to get you moving forward here?

west palm
#

Yh I believe so. Turns out my understanding prior to this conversation was for every successful subscription, a new subscription object is created (new unique subscription id) which is wrong.

#

So a subscription is created once for a customer, and said subscription can or will have multiple invoices. The most recent invoice determines if the subscription is active (actively paying customer or not).

west palm
#

Thanks for the link. I got a bunch of refactoring to do hahaha

dense crystal
#

You're welcome! Been there, done that, wore out the t-shirt. ๐Ÿ˜…

night sigilBOT