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

Store Stripe's Subscription.customer to subscriptions.customer column in the database #233

Open
satococoa opened this issue Dec 16, 2024 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@satococoa
Copy link
Contributor

Task Description

We currently need to make API calls to Stripe each time to get the Subscription.customer information, as it's not stored in our database. This information is required for:

  • Building a customer portal
  • Reporting usage-based billing

To improve performance and reliability, we need to store this information in our subscriptions table.

Background

Current implementation requires Stripe API calls for each operation:

  • // FIXME: if we have customer id in subscriptions table, we can use it directly
    const subscription = await stripe.subscriptions.retrieve(subscriptionId);
    customerId =
    typeof subscription.customer === "string"
    ? subscription.customer
    : subscription.customer.id;
  • const subscription = await stripe.subscriptions.retrieve(subscriptionId);
    const session = await stripe.billingPortal.sessions.create({
    customer: subscription.customer as string,
    return_url: `${siteUrl}/settings/team`,
    });

Implementation Steps

  1. Add customer column to subscriptions table (nullable initially)
  2. Migrate existing subscriptions by fetching customer data from Stripe API
  3. Modify the column to be NOT NULL

Reference

@satococoa satococoa added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 16, 2024
@satococoa satococoa changed the title Store Stipe's Subscription.customer to subscriptions.customer column in the database Store Stripe's Subscription.customer to subscriptions.customer column in the database Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant