[ { "name": "customer.subscription.created starts the state from the snapshot", "args": [ null, { "id": "evt_1", "type": "customer.subscription.created", "created": 1772323200, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "trialing", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": 1773532800, "latest_invoice": null, "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "trialing", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": 1773532800, "latestInvoiceId": null, "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 0, "lastEventId": "evt_1" } }, { "name": "expanded customer and latest_invoice objects give their ids", "args": [ null, { "id": "evt_1", "type": "customer.subscription.created", "created": 1772323200, "object": { "id": "sub_1Pz", "object": "subscription", "customer": { "id": "cus_9", "object": "customer" }, "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": { "id": "in_7", "object": "invoice" }, "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "data": [ { "price": { "id": "price_team" }, "quantity": 3 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_team", "quantity": 3, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_7", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 0, "lastEventId": "evt_1" } }, { "name": "newer API versions: the period is read from the subscription item", "args": [ null, { "id": "evt_1", "type": "customer.subscription.updated", "created": 1772323200, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "items": { "data": [ { "price": { "id": "price_pro" }, "quantity": 1, "current_period_start": 1772323200, "current_period_end": 1775001600 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 0, "lastEventId": "evt_1" } }, { "name": "the customer cancels at the period end: still entitled until then", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_3", "type": "customer.subscription.updated", "created": 1772400000, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": true, "cancel_at": 1775001600, "canceled_at": 1772400000, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": true, "cancelAt": 1775001600, "canceledAt": 1772400000, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772400000, "invoiceEventAt": 1772323260, "lastEventId": "evt_3" } }, { "name": "customer.subscription.deleted is cancelled and not entitled, whatever status it carries", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_4", "type": "customer.subscription.deleted", "created": 1775001600, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": 1772400000, "ended_at": 1775001600, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "canceled", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": 1772400000, "endedAt": 1775001600, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": false, "subscriptionEventAt": 1775001600, "invoiceEventAt": 1772323260, "lastEventId": "evt_4" } }, { "name": "cancelled is final: a later snapshot saying active does not revive it", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "canceled", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": 1775001600, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": false, "subscriptionEventAt": 1775001600, "invoiceEventAt": 1772323260, "lastEventId": "evt_4" }, { "id": "evt_5", "type": "customer.subscription.updated", "created": 1775001700, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "canceled", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": 1775001600, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": false, "subscriptionEventAt": 1775001600, "invoiceEventAt": 1772323260, "lastEventId": "evt_4" } }, { "name": "a snapshot older than the one applied is ignored", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_0", "type": "customer.subscription.updated", "created": 1772300000, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "incomplete", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" } }, { "name": "a redelivered event changes nothing", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_2", "type": "invoice.payment_failed", "created": 1772500000, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "paid" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" } }, { "name": "invoice.payment_failed moves active to past_due, still entitled while Stripe retries", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_6", "type": "invoice.payment_failed", "created": 1772500000, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "open" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "past_due", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_2", "paymentFailed": true, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772500000, "lastEventId": "evt_6" } }, { "name": "a failed payment during a trial leaves it trialing", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "trialing", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": 1773532800, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_6", "type": "invoice.payment_failed", "created": 1772500000, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "open" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "trialing", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": 1773532800, "latestInvoiceId": "in_2", "paymentFailed": true, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772500000, "lastEventId": "evt_6" } }, { "name": "invoice.paid after a failure moves past_due back to active", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "past_due", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_2", "paymentFailed": true, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772500000, "lastEventId": "evt_6" }, { "id": "evt_7", "type": "invoice.paid", "created": 1772600000, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "paid" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_2", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772600000, "lastEventId": "evt_7" } }, { "name": "newer API versions: invoice.payment_succeeded finds the subscription under parent, and unpaid becomes active", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "unpaid", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": true, "entitled": false, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_8", "type": "invoice.payment_succeeded", "created": 1772600000, "object": { "id": "in_3", "object": "invoice", "customer": "cus_9", "status": "paid", "parent": { "type": "subscription_details", "subscription_details": { "subscription": "sub_1Pz" } } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_3", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772600000, "lastEventId": "evt_8" } }, { "name": "an invoice event older than the last one applied is ignored", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "past_due", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_2", "paymentFailed": true, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772500000, "lastEventId": "evt_6" }, { "id": "evt_5", "type": "invoice.paid", "created": 1772400000, "object": { "id": "in_1", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "paid" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "past_due", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_2", "paymentFailed": true, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772500000, "lastEventId": "evt_6" } }, { "name": "invoice.paid before any subscription event starts an active state", "args": [ null, { "id": "evt_1", "type": "invoice.paid", "created": 1772323260, "object": { "id": "in_1", "object": "invoice", "customer": "cus_9", "subscription": { "id": "sub_1Pz", "object": "subscription" }, "status": "paid" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": null, "quantity": 1, "currentPeriodStart": null, "currentPeriodEnd": null, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 0, "invoiceEventAt": 1772323260, "lastEventId": "evt_1" } }, { "name": "the subscription.created that arrives after its paid invoice fills the plan in and stays active", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": null, "quantity": 1, "currentPeriodStart": null, "currentPeriodEnd": null, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 0, "invoiceEventAt": 1772323260, "lastEventId": "evt_1" }, { "id": "evt_0", "type": "customer.subscription.created", "created": 1772323200, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "incomplete", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_0" } }, { "name": "invoice.payment_failed before any subscription event starts an incomplete state, not entitled", "args": [ null, { "id": "evt_1", "type": "invoice.payment_failed", "created": 1772323260, "object": { "id": "in_1", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "open" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "incomplete", "priceId": null, "quantity": 1, "currentPeriodStart": null, "currentPeriodEnd": null, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": true, "entitled": false, "subscriptionEventAt": 0, "invoiceEventAt": 1772323260, "lastEventId": "evt_1" } }, { "name": "a one-off invoice with no subscription changes nothing", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_9", "type": "invoice.paid", "created": 1772700000, "object": { "id": "in_9", "object": "invoice", "customer": "cus_9", "subscription": null } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" } }, { "name": "an event this reducer does not read leaves no state as no state", "args": [ null, { "id": "evt_9", "type": "checkout.session.completed", "created": 1772700000, "object": { "id": "cs_test_1", "object": "checkout.session" } } ], "expect": null }, { "name": "customer.updated leaves the state unchanged", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_9", "type": "customer.updated", "created": 1772700000, "object": { "id": "cus_9", "object": "customer" } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" } }, { "name": "customer.subscription.paused: paused is not entitled", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_10", "type": "customer.subscription.paused", "created": 1772700000, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "paused", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "paused", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": false, "subscriptionEventAt": 1772700000, "invoiceEventAt": 1772323260, "lastEventId": "evt_10" } }, { "name": "a snapshot at the same second as the last one applies", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_11", "type": "customer.subscription.updated", "created": 1772323200, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "data": [ { "price": { "id": "price_pro" }, "quantity": 5 } ] } } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 5, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_11" } }, { "name": "trial_will_end with no items: no price, quantity 1", "args": [ null, { "id": "evt_1", "type": "customer.subscription.trial_will_end", "created": 1773273600, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "trialing", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": 1773532800, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600 } } ], "expect": { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "trialing", "priceId": null, "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": 1773532800, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1773273600, "invoiceEventAt": 0, "lastEventId": "evt_1" } }, { "name": "an event for another subscription is an error", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_12", "type": "customer.subscription.updated", "created": 1772800000, "object": { "id": "sub_other", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expectError": "event is for subscription sub_other, not sub_1Pz" }, { "name": "an invoice for another subscription is an error", "args": [ { "subscriptionId": "sub_1Pz", "customerId": "cus_9", "status": "active", "priceId": "price_pro", "quantity": 1, "currentPeriodStart": 1772323200, "currentPeriodEnd": 1775001600, "cancelAtPeriodEnd": false, "cancelAt": null, "canceledAt": null, "endedAt": null, "trialEnd": null, "latestInvoiceId": "in_1", "paymentFailed": false, "entitled": true, "subscriptionEventAt": 1772323200, "invoiceEventAt": 1772323260, "lastEventId": "evt_2" }, { "id": "evt_12", "type": "invoice.paid", "created": 1772800000, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_other", "status": "paid" } } ], "expectError": "event is for subscription sub_other, not sub_1Pz" }, { "name": "an unknown status is an error", "args": [ null, { "id": "evt_1", "type": "customer.subscription.updated", "created": 1772800000, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "expired", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expectError": "unknown subscription status \"expired\"" }, { "name": "a subscription without its customer is an error", "args": [ null, { "id": "evt_1", "type": "customer.subscription.created", "created": 1772800000, "object": { "id": "sub_1Pz", "object": "subscription", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": 1775001600, "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expectError": "subscription object needs id, customer and status" }, { "name": "an empty event id is an error", "args": [ null, { "id": "", "type": "invoice.paid", "created": 1772800000, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "paid" } } ], "expectError": "event id must be a non-empty string" }, { "name": "a fractional created time is an error", "args": [ null, { "id": "evt_1", "type": "invoice.paid", "created": 1772800000.5, "object": { "id": "in_2", "object": "invoice", "customer": "cus_9", "subscription": "sub_1Pz", "status": "paid" } } ], "expectError": "event created must be a whole number of seconds" }, { "name": "an object that is not a JSON object is an error", "args": [ null, { "id": "evt_1", "type": "invoice.paid", "created": 1772800000, "object": [ "in_2" ] } ], "expectError": "event object must be a JSON object" }, { "name": "a period end that is text is an error", "args": [ null, { "id": "evt_1", "type": "customer.subscription.created", "created": 1772800000, "object": { "id": "sub_1Pz", "object": "subscription", "customer": "cus_9", "status": "active", "cancel_at_period_end": false, "cancel_at": null, "canceled_at": null, "ended_at": null, "trial_end": null, "latest_invoice": "in_1", "current_period_start": 1772323200, "current_period_end": "soon", "items": { "object": "list", "data": [ { "id": "si_1", "price": { "id": "price_pro", "object": "price" }, "quantity": 1 } ] } } } ], "expectError": "subscription field current_period_end must be a whole number or null" }, { "name": "a first invoice without its customer is an error", "args": [ null, { "id": "evt_1", "type": "invoice.paid", "created": 1772800000, "object": { "id": "in_2", "object": "invoice", "subscription": "sub_1Pz", "status": "paid" } } ], "expectError": "invoice object needs customer" }, { "name": "an event that is not an object is an error", "args": [ null, "evt_1" ], "expectError": "event must be a JSON object" }, { "name": "an event without a type is an error", "args": [ null, { "id": "evt_1", "created": 1772800000, "object": { "id": "in_2" } } ], "expectError": "event type must be a non-empty string" } ]