-
Notifications
You must be signed in to change notification settings - Fork 331
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
fix: speed up team upgrade #9902
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,18 @@ const createStripeSubscription: MutationResolvers['createStripeSubscription'] = | |
return standardError(new Error('Organization already has a subscription'), {userId: viewerId}) | ||
} | ||
const {email} = viewer | ||
const customer = stripeId | ||
? await manager.retrieveCustomer(stripeId) | ||
: await manager.createCustomer(orgId, email) | ||
const {id: customerId} = customer | ||
const res = await manager.attachPaymentToCustomer(customerId, paymentMethodId) | ||
if (res instanceof Error) return standardError(res, {userId: viewerId}) | ||
// wait until the payment is attached to the customer before updating the default payment method | ||
await manager.updateDefaultPaymentMethod(customerId, paymentMethodId) | ||
let customer: Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer> | ||
if (stripeId) { | ||
customer = await manager.retrieveCustomer(stripeId) | ||
const {id: customerId} = customer | ||
const res = await manager.attachPaymentToCustomer(customerId, paymentMethodId) | ||
if (res instanceof Error) return standardError(res, {userId: viewerId}) | ||
// wait until the payment is attached to the customer before updating the default payment method | ||
await manager.updateDefaultPaymentMethod(customerId, paymentMethodId) | ||
} else { | ||
customer = await manager.createCustomer(orgId, email, paymentMethodId) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And we could remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was thinking about that! but since our DB is colocated it's usually only a couple ms so I figured probably better to be safe than sorry in case the write failed for some reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second look, we should completely get rid of the write to the DB here! |
||
const subscription = await manager.createTeamSubscription(customer.id, orgId, orgUsersCount) | ||
|
||
const latestInvoice = subscription.latest_invoice as Stripe.Invoice | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const defaultTier = process.env.IS_ENTERPRISE ? 'enterprise' : 'starter' | ||
export const defaultTier = process.env.IS_ENTERPRISE === 'true' ? 'enterprise' : 'starter' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the edge case where a user is upgrading for a second time, we could use a
Promise.all
to speed things up a bit here? Something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried this...
nope, gotta attach first. ah well, not too bad since re-upgrade is such an edge case!