mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-20 20:26:55 -05:00
feat(stripe): add support for locale option to upgradeSubscription (#7421)
This commit is contained in:
@@ -215,11 +215,11 @@ To create a subscription, use the `subscription.upgrade` method:
|
||||
```ts
|
||||
type upgradeSubscription = {
|
||||
/**
|
||||
* The name of the plan to upgrade to.
|
||||
* The name of the plan to upgrade to.
|
||||
*/
|
||||
plan: string = "pro"
|
||||
/**
|
||||
* Whether to upgrade to an annual plan.
|
||||
* Whether to upgrade to an annual plan.
|
||||
*/
|
||||
annual?: boolean = true
|
||||
/**
|
||||
@@ -242,6 +242,11 @@ type upgradeSubscription = {
|
||||
* Number of seats to upgrade to (if applicable).
|
||||
*/
|
||||
seats?: number = 1
|
||||
/**
|
||||
* The IETF language tag of the locale Checkout is displayed in.
|
||||
* If not provided or set to `auto`, the browser's locale is used.
|
||||
*/
|
||||
locale?: string
|
||||
/**
|
||||
* The URL to which Stripe should send customers when payment or setup is complete.
|
||||
*/
|
||||
@@ -255,7 +260,7 @@ type upgradeSubscription = {
|
||||
*/
|
||||
returnUrl?: string
|
||||
/**
|
||||
* Disable redirect after successful subscription.
|
||||
* Disable redirect after successful subscription.
|
||||
*/
|
||||
disableRedirect: boolean = false
|
||||
}
|
||||
@@ -271,7 +276,8 @@ await authClient.subscription.upgrade({
|
||||
cancelUrl: "/pricing",
|
||||
annual: true, // Optional: upgrade to an annual plan
|
||||
referenceId: "org_123", // Optional: defaults based on customerType
|
||||
seats: 5 // Optional: for team plans
|
||||
seats: 5, // Optional: for team plans
|
||||
locale: "en" // Optional: display checkout in English
|
||||
});
|
||||
```
|
||||
|
||||
@@ -466,7 +472,8 @@ To create a [Stripe billing portal session](https://docs.stripe.com/api/customer
|
||||
```ts
|
||||
type createBillingPortal = {
|
||||
/**
|
||||
* The IETF language tag of the locale customer portal is displayed in. If blank or auto, browser's locale is used.
|
||||
* The IETF language tag of the locale Customer Portal is displayed in.
|
||||
* If not provided or set to `auto`, the browser's locale is used.
|
||||
*/
|
||||
locale?: string
|
||||
/**
|
||||
|
||||
@@ -158,6 +158,19 @@ const upgradeSubscriptionBodySchema = z.object({
|
||||
description: "Number of seats to upgrade to (if applicable). Eg: 1",
|
||||
})
|
||||
.optional(),
|
||||
/**
|
||||
* The IETF language tag of the locale Checkout is displayed in.
|
||||
* If not provided or set to `auto`, the browser's locale is used.
|
||||
*/
|
||||
locale: z
|
||||
.custom<StripeType.Checkout.Session.Locale>((localization) => {
|
||||
return typeof localization === "string";
|
||||
})
|
||||
.meta({
|
||||
description:
|
||||
"The locale to display Checkout in. Eg: 'en', 'ko'. If not provided or set to `auto`, the browser's locale is used.",
|
||||
})
|
||||
.optional(),
|
||||
/**
|
||||
* The URL to which Stripe should send customers when payment or setup is complete.
|
||||
*/
|
||||
@@ -691,6 +704,7 @@ export const upgradeSubscription = (options: StripeOptions) => {
|
||||
: {
|
||||
customer_email: user.email,
|
||||
}),
|
||||
locale: ctx.body.locale,
|
||||
success_url: getUrl(
|
||||
ctx,
|
||||
`${
|
||||
@@ -1412,10 +1426,18 @@ export const subscriptionSuccess = (options: StripeOptions) => {
|
||||
};
|
||||
|
||||
const createBillingPortalBodySchema = z.object({
|
||||
/**
|
||||
* The IETF language tag of the locale Customer Portal is displayed in.
|
||||
* If not provided or set to `auto`, the browser's locale is used.
|
||||
*/
|
||||
locale: z
|
||||
.custom<StripeType.Checkout.Session.Locale>((localization) => {
|
||||
return typeof localization === "string";
|
||||
})
|
||||
.meta({
|
||||
description:
|
||||
"The IETF language tag of the locale Customer Portal is displayed in. Eg: 'en', 'ko'. If not provided or set to `auto`, the browser's locale is used.",
|
||||
})
|
||||
.optional(),
|
||||
referenceId: z.string().optional(),
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user