Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixed bug with persisting offer redemptions for existing free members #20571

Conversation

cmraible
Copy link
Contributor

@cmraible cmraible commented Jul 9, 2024

ref https://linear.app/tryghost/issue/ENG-1251/support-escalation-re-offers-not-tracking

  • Offer Redemptions were not being persisted in the database for existing free members who upgrade to a paid plan with an offer, which resulted in inaccurate offer redemption counts. This made it difficult to assess the performance of an offer.
  • Previously, Ghost recorded an offer redemption in the DB in response to the SubscriptionCreatedEvent, under the assumption that the offer details would be included in this event. This assumption was valid for brand new members starting a subscription with an offer, but not for existing free members upgrading to a paid plan with an offer.
  • For existing free members, the subscription is first stored in Ghost in response to the customer.subscription.created Stripe webhook. At this point, the offer/discount is not attached to the subscription, so the SubscriptionCreatedEvent triggers without the offer information, and the offer redemption is not recorded. After the checkout.session.completed webhook is received (which does include the offer details), the subscription is updated in Ghost, but the Offer Redemption is not stored.
  • For brand new members, the customer.subscription.created webhook no-ops, because the member and Stripe Customer don't exist yet. Therefore, the subscription is first created in Ghost in response to the checkout.session.completed webhook, which does include the offer information, so the offer information is included in the SubscriptionCreatedEvent and the offer redemption is recorded as expected.
  • This change adds an explicit OfferRedemptionEvent, which triggers either: (1) when a new subscription is created with an offer (as in the case of a brand new member), or (2) when an existing subscription is first updated to include an offer (as in the case of an existing free member upgrading with an offer). The Offer Redemption is then persisted in the DB in response to the OfferRedemptionEvent rather than the SubscriptionCreatedEvent.

ref https://linear.app/tryghost/issue/ENG-1251/support-escalation-re-offers-not-tracking

- Previously, Ghost recorded an offer redemption in the DB in response to the SubscriptionCreatedEvent, under the assumption that the offer details would be included in this event.
- However, for existing free members, the SubscriptionCreatedEvent first occurs in response to the `subscription.created` Stripe webhook, which does not include the offer details.
- The offer details are only included in the `checkout.session.completed` webhook, which updated the subscription in the DB to include the offer details, but this update did not trigger the offer redemption.
- Consequently, Ghost wasn't recording offer redemptions for existing free members who were redeeming an offer for a paid subscription.
- This change adds an explicit `OfferRedemptionEvent`, which triggers either when a new subscription is created with an offer (as in the case of a brand new member), or when an existing subscription is first updated to include an offer (as in the case of an existing free member upgrading with an offer).
@cmraible cmraible changed the title 🐛 Fixed offer redemptions not recording for existing free members 🐛 Fixed bug preventing offer redemptions from being stored for existing members Jul 9, 2024
@cmraible cmraible changed the title 🐛 Fixed bug preventing offer redemptions from being stored for existing members 🐛 Fixed bug with persisting offer redemptions for existing free members Jul 9, 2024
@cmraible cmraible marked this pull request as ready for review July 9, 2024 23:00
@cmraible cmraible merged commit bf895e6 into TryGhost:main Jul 9, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant