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

[subs 2] Add purchase endpoints #3196

Merged
merged 13 commits into from
Jan 3, 2025

Conversation

rafaelbsky
Copy link
Contributor

@rafaelbsky rafaelbsky commented Dec 6, 2024

(supersedes #3156 and #3160)

This PR adds 4 endpoints to bsky and the necessary underlying calls to bsync to implement them:

  1. app.bsky.purchase.getSubscriptions:
    1. Used to fetch the active subscriptions for a user. It is called roughly once per app load.
    2. This calls bsync, which calls RevenueCat.
  2. app.bsky.purchase.getFeatures:
    1. Used to fetch what paid features the client app should enable for the user (example: enable selecting a custom color).
    2. Reads cached data from the dataplane, doesn't reach out to RevenueCat.
    3. The dataplane read path is still to be done in a future PR. It will be done through bsync providing a scan... GRPC endpoint that the indexing infrastructure will call. That scan... method will serve data that bsync either obtained by being triggered by a webhook event, or by being called in the app.bsky.purchase.refreshCache flow.
  3. app.bsky.purchase.getSubscriptionGroup:
    1. This is used when the user navigates to the screen to subscribe and we need to show the possible options (depends on the platform, etc).
    2. This calls bsync. In this case, bsync doesn't need to call RevenueCat, it replies with in-memory data. The return data here is basically just a configuration. Still, we do it in bsync so bsky can remain completely agnostic regarding any purchase-related configuration.
  4. app.bsky.purchase.refreshCache:
    1. Use by the user (and possibly support agents) to refresh the dataplane cache. Refreshing this cache possibly affects the data returned by app.bsky.purchase.getFeatures (if that was out-of-date, this is what makes it be refreshed).
    2. This calls bsync, which calls RevenueCat.

You can skip the codegen commit when reviewing.

Notable points:

  1. bsky knows nothing about RevenueCat.
  2. bsync knows about RevenueCat, but only in a few contained points.
    1. In the webhook listener, which is RevenueCat-specific.
    2. Some configs have "revenue cat" in their names, as they are used to build the RevenueCatClient.
    3. Previously we only had RevenueCatClient, which was used in multiple places in bsync. In this PR I abstracted RevenueCatClient away into a PurchasesClient, that does the mapping between RevenueCat formats and our formats. PurchasesClient is now called in multiple places instead of RevenueCatClient. Note also that PurchasesClient is what does the mappings between entitlements, products, etc. Since those rely on configs for the Stripe identifiers, I preferred to put that logic inside a class than in individual functions (like it was in the POC), so I can inject the config.

@rafaelbsky rafaelbsky changed the title subscription endpoints purchase endpoints Dec 6, 2024
@rafaelbsky rafaelbsky changed the base branch from main to bsync-subscription-listener December 6, 2024 19:47
@rafaelbsky rafaelbsky force-pushed the bsky-bsync-subscription-endpoints branch 7 times, most recently from be12e9d to 76a80ab Compare December 7, 2024 19:17
@rafaelbsky rafaelbsky changed the title purchase endpoints Purchase endpoints Dec 7, 2024
@rafaelbsky rafaelbsky changed the title Purchase endpoints Add purchase endpoints Dec 7, 2024
@rafaelbsky rafaelbsky marked this pull request as ready for review December 7, 2024 19:50
@rafaelbsky rafaelbsky force-pushed the bsky-bsync-subscription-endpoints branch 3 times, most recently from 6842680 to a00a74a Compare December 9, 2024 22:52
Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, just left a handful of small comments.

packages/bsky/src/api/app/bsky/purchase/refreshCache.ts Outdated Show resolved Hide resolved
packages/bsync/src/purchases/purchasesClient.ts Outdated Show resolved Hide resolved
packages/bsync/src/purchases/purchasesClient.ts Outdated Show resolved Hide resolved
packages/bsync/tests/purchases.test.ts Outdated Show resolved Hide resolved
packages/bsync/tests/purchases.test.ts Show resolved Hide resolved
@rafaelbsky rafaelbsky force-pushed the bsync-subscription-listener branch from 3d5b943 to 67cfef3 Compare December 12, 2024 18:35
@rafaelbsky rafaelbsky changed the title Add purchase endpoints [subs 2] Add purchase endpoints Jan 3, 2025
Base automatically changed from bsync-subscription-listener to subscriptions-backend January 3, 2025 15:33
@rafaelbsky rafaelbsky force-pushed the bsky-bsync-subscription-endpoints branch from 8a4fc95 to 4d8784d Compare January 3, 2025 15:39
@rafaelbsky rafaelbsky merged commit 529e52b into subscriptions-backend Jan 3, 2025
14 checks passed
@rafaelbsky rafaelbsky deleted the bsky-bsync-subscription-endpoints branch January 3, 2025 15:45
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.

4 participants