Skip to content

Commit

Permalink
billing: migrate personal users to hacker api fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelecerati committed Jul 7, 2023
1 parent a432b97 commit 987ff9d
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/api/src/controllers/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,21 @@ app.post("/migrate-personal-users", async (req, res) => {
user.newStripeProductId !== "growth_1" &&
user.newStripeProductId !== "scale_1"
) {
const customer = await req.stripe.customers.get({
email: user.email,
});

const items = await req.stripe.prices.list({
lookup_keys: products["prod_O9XuIjn7EqYRVW"].lookupKeys,
});

const subscription = await req.stripe.subscriptions.update({
cancel_at_period_end: false,
customer: customer.id,
items: items.data.map((item) => ({ price: item.id })),
});
const subscription = await req.stripe.subscriptions.update(
user.stripeCustomerSubscriptionId,
{
billing_cycle_anchor: "now",
cancel_at_period_end: false,
items: items.data.map((item) => ({ price: item.id })),
}
);

await db.user.update(user.id, {
stripeCustomerId: customer.id,
stripeCustomerId: user.stripeCustomerId,
stripeProductId: "prod_O9XuIjn7EqYRVW",
stripeCustomerSubscriptionId: subscription.id,
stripeCustomerPaymentMethodId: null,
Expand Down

0 comments on commit 987ff9d

Please sign in to comment.