🚸 (billing) Use Stripe checkout page for new subscription with existing customer

This commit is contained in:
Baptiste Arnaud
2023-05-05 14:20:02 -04:00
parent e15e27f0b4
commit b9f94cdf19
3 changed files with 95 additions and 44 deletions

View File

@@ -47,11 +47,17 @@ export const ChangePlanForm = ({ workspace, onUpgradeSuccess }: Props) => {
description: error.message,
})
},
onSuccess: ({ workspace: { plan } }) => {
onSuccess: ({ workspace, checkoutUrl }) => {
if (checkoutUrl) {
window.location.href = checkoutUrl
return
}
onUpgradeSuccess()
showToast({
status: 'success',
description: scopedT('updateSuccessToast.description', { plan }),
description: scopedT('updateSuccessToast.description', {
plan: workspace?.plan,
}),
})
},
})
@@ -83,7 +89,10 @@ export const ChangePlanForm = ({ workspace, onUpgradeSuccess }: Props) => {
isYearly,
} as const
if (workspace.stripeId) {
updateSubscription(newSubscription)
updateSubscription({
...newSubscription,
returnUrl: window.location.href,
})
} else {
setPreCheckoutPlan(newSubscription)
}