@better-auth/stripe 1.8.0-beta.3 → 1.8.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { l as StripePlan, n as stripe } from "./index-BDmSmcUM.mjs";
1
+ import { l as StripePlan, n as stripe } from "./index-BGbjIjTq.mjs";
2
2
  //#region src/error-codes.d.ts
3
3
  export declare const STRIPE_ERROR_CODES: {
4
4
  UNAUTHORIZED: import("better-auth").RawError<"UNAUTHORIZED">;
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-CSLu0Cqn.mjs";
1
+ import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-B3tEwy96.mjs";
2
2
  //#region src/client.ts
3
3
  const stripeClient = (options) => {
4
4
  return {
@@ -849,7 +849,10 @@ declare const stripe: <O extends StripeOptions>(options: O) => {
849
849
  }[]>;
850
850
  subscriptionSuccess: import("better-call").StrictEndpoint<"/subscription/success", {
851
851
  method: "GET";
852
- query: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
852
+ query: import("zod").ZodOptional<import("zod").ZodObject<{
853
+ callbackURL: import("zod").ZodOptional<import("zod").ZodString>;
854
+ checkoutSessionId: import("zod").ZodOptional<import("zod").ZodString>;
855
+ }, import("zod/v4/core").$strip>>;
853
856
  metadata: {
854
857
  openapi: {
855
858
  operationId: string;
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as CheckoutSessionLocale, c as StripeOptions, d as SubscriptionOptions, f as WithActiveOrganizationId, i as CheckoutSessionLineItem, l as StripePlan, n as stripe, o as CustomerType, p as WithStripeCustomerId, r as AuthorizeReferenceAction, s as StripeCtxSession, t as StripePlugin, u as Subscription } from "./index-BDmSmcUM.mjs";
1
+ import { a as CheckoutSessionLocale, c as StripeOptions, d as SubscriptionOptions, f as WithActiveOrganizationId, i as CheckoutSessionLineItem, l as StripePlan, n as stripe, o as CustomerType, p as WithStripeCustomerId, r as AuthorizeReferenceAction, s as StripeCtxSession, t as StripePlugin, u as Subscription } from "./index-BGbjIjTq.mjs";
2
2
  export { type AuthorizeReferenceAction, type CheckoutSessionLineItem, type CheckoutSessionLocale, type CustomerType, type StripeCtxSession, type StripeOptions, type StripePlan, StripePlugin, type Subscription, type SubscriptionOptions, type WithActiveOrganizationId, type WithStripeCustomerId, stripe };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-CSLu0Cqn.mjs";
1
+ import { n as STRIPE_ERROR_CODES, t as PACKAGE_VERSION } from "./version-B3tEwy96.mjs";
2
2
  import { APIError, HIDE_METADATA } from "better-auth";
3
3
  import { defu } from "defu";
4
4
  import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
@@ -1384,23 +1384,33 @@ const listActiveSubscriptions = (options) => {
1384
1384
  return ctx.json(subs);
1385
1385
  });
1386
1386
  };
1387
- const subscriptionSuccessQuerySchema = z.record(z.string(), z.any()).optional();
1387
+ const subscriptionSuccessQuerySchema = z.object({
1388
+ callbackURL: z.string().optional(),
1389
+ checkoutSessionId: z.string().optional()
1390
+ }).optional();
1391
+ /**
1392
+ * Fill the Stripe "{CHECKOUT_SESSION_ID}" template variable in callbackURL.
1393
+ * @see https://docs.stripe.com/payments/checkout/custom-success-page?payment-ui=stripe-hosted#modify-the-success-url
1394
+ */
1395
+ function fillCheckoutSessionId(callbackURL, checkoutSessionId) {
1396
+ return callbackURL.replaceAll("{CHECKOUT_SESSION_ID}", checkoutSessionId);
1397
+ }
1388
1398
  const subscriptionSuccess = (options) => {
1389
1399
  const client = options.stripeClient;
1390
1400
  return createAuthEndpoint("/subscription/success", {
1391
1401
  method: "GET",
1392
1402
  query: subscriptionSuccessQuerySchema,
1393
1403
  metadata: { openapi: { operationId: "handleSubscriptionSuccess" } },
1394
- use: [originCheck((ctx) => ctx.query.callbackURL)]
1404
+ use: [originCheck((ctx) => {
1405
+ const { callbackURL, checkoutSessionId } = ctx.query ?? {};
1406
+ if (!callbackURL || !checkoutSessionId) return callbackURL;
1407
+ return [callbackURL, fillCheckoutSessionId(callbackURL, checkoutSessionId)];
1408
+ })]
1395
1409
  }, async (ctx) => {
1396
1410
  let callbackURL = ctx.query?.callbackURL || "/";
1397
1411
  if (!await getSessionFromCtx(ctx)) throw ctx.redirect(getUrl(ctx, callbackURL));
1398
1412
  if (!ctx.query?.checkoutSessionId) throw ctx.redirect(getUrl(ctx, callbackURL));
1399
- /**
1400
- * Replace the Stripe {CHECKOUT_SESSION_ID} template variable in callbackURL.
1401
- * @see https://docs.stripe.com/payments/checkout/custom-success-page?payment-ui=stripe-hosted#modify-the-success-url
1402
- */
1403
- callbackURL = callbackURL.replaceAll("{CHECKOUT_SESSION_ID}", ctx.query.checkoutSessionId);
1413
+ callbackURL = fillCheckoutSessionId(callbackURL, ctx.query.checkoutSessionId);
1404
1414
  const checkoutSession = await client.checkout.sessions.retrieve(ctx.query.checkoutSessionId).catch((error) => {
1405
1415
  ctx.context.logger.error("Error retrieving checkout session from Stripe", error);
1406
1416
  return null;
@@ -30,6 +30,6 @@ const STRIPE_ERROR_CODES = defineErrorCodes({
30
30
  });
31
31
  //#endregion
32
32
  //#region src/version.ts
33
- const PACKAGE_VERSION = "1.8.0-beta.3";
33
+ const PACKAGE_VERSION = "1.8.0-beta.4";
34
34
  //#endregion
35
35
  export { STRIPE_ERROR_CODES as n, PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/stripe",
3
- "version": "1.8.0-beta.3",
3
+ "version": "1.8.0-beta.4",
4
4
  "description": "Stripe plugin for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -58,14 +58,14 @@
58
58
  "better-call": "1.4.4",
59
59
  "stripe": "^23.0.0",
60
60
  "tsdown": "0.23.1",
61
- "@better-auth/core": "1.8.0-beta.3",
62
- "better-auth": "1.8.0-beta.3"
61
+ "@better-auth/core": "1.8.0-beta.4",
62
+ "better-auth": "1.8.0-beta.4"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "better-call": "1.4.4",
66
66
  "stripe": "^18 || ^19 || ^20 || ^21 || ^22 || ^23",
67
- "@better-auth/core": "^1.8.0-beta.3",
68
- "better-auth": "^1.8.0-beta.3"
67
+ "@better-auth/core": "^1.8.0-beta.4",
68
+ "better-auth": "^1.8.0-beta.4"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "tsdown",