@deiondz/better-auth-razorpay 2.0.13 → 2.0.14

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/README.md CHANGED
@@ -354,7 +354,7 @@ All endpoints are prefixed with `/api/auth/razorpay/` (or your configured `baseP
354
354
  | Cancel | `POST` | `subscription/cancel` | Cancel by local subscription ID. Body: `subscriptionId`, `immediately?`. |
355
355
  | Restore | `POST` | `subscription/restore` | Restore a subscription scheduled to cancel. Body: `subscriptionId`. |
356
356
  | List | `GET` | `subscription/list` | List active/trialing subscriptions. Query: `referenceId?` (default: current user). |
357
- | Get plans | `GET` | `get-plans` | Return configured plans (name, monthlyPlanId, annualPlanId, limits, freeTrial). |
357
+ | Get plans | `GET` | `get-plans` | Return configured plans with price details (name, monthlyPlanId, annualPlanId, limits, freeTrial, monthly/annual amount, currency, period from Razorpay). |
358
358
  | Webhook | `POST` | `webhook` | Razorpay webhook URL; configure in Razorpay Dashboard. |
359
359
 
360
360
  ### 1. Get Plans
@@ -363,6 +363,8 @@ Retrieve all configured subscription plans (from plugin config; no Razorpay API
363
363
 
364
364
  **Endpoint:** `GET /api/auth/razorpay/get-plans`
365
365
 
366
+ Each plan in the response includes optional **price details** (`monthly`, `annual`) when available from Razorpay: `amount` (smallest currency unit, e.g. paise/cents), `currency`, `period` (e.g. monthly, yearly), and `interval`. Omitted if the plan fetch fails or the variant is not configured.
367
+
366
368
  **Authentication:** Not required (public endpoint)
367
369
 
368
370
  **Response:**
@@ -370,7 +372,7 @@ Retrieve all configured subscription plans (from plugin config; no Razorpay API
370
372
  ```typescript
371
373
  {
372
374
  success: true,
373
- data: Array<{ name: string; monthlyPlanId: string; annualPlanId?: string; limits?: Record<string, number>; freeTrial?: { days: number } }>
375
+ data: Array<{ name: string; monthlyPlanId: string; annualPlanId?: string; limits?: Record<string, number>; freeTrial?: { days: number }; monthly?: { amount: number; currency: string; period: string; interval?: number }; annual?: { amount: number; currency: string; period: string; interval?: number } }>
374
376
  }
375
377
  ```
376
378
 
@@ -1,10 +1,10 @@
1
- import { S as SubscriptionRecord } from '../types-BC0odu_S.js';
1
+ import { S as SubscriptionRecord } from '../types-3dNrA0qB.js';
2
2
  import * as _tanstack_react_query from '@tanstack/react-query';
3
3
  import { UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
4
4
  import * as react from 'react';
5
5
  import { ReactNode } from 'react';
6
- import { c as RazorpayAuthClient, d as CancelSubscriptionResponse, a as CancelSubscriptionInput, e as CreateOrUpdateSubscriptionResponse, C as CreateOrUpdateSubscriptionInput, P as PlanSummary, f as RestoreSubscriptionResponse, b as RestoreSubscriptionInput, g as ListSubscriptionsResponse, h as VerifyPaymentResponse, V as VerifyPaymentInput, L as ListSubscriptionsInput } from '../types-B91GdcpF.js';
7
- export { G as GetPlansResponse, i as RazorpayApiError, R as RazorpayApiResult, j as RazorpayClientActions } from '../types-B91GdcpF.js';
6
+ import { c as RazorpayAuthClient, d as CancelSubscriptionResponse, a as CancelSubscriptionInput, e as CreateOrUpdateSubscriptionResponse, C as CreateOrUpdateSubscriptionInput, P as PlanSummary, f as RestoreSubscriptionResponse, b as RestoreSubscriptionInput, g as ListSubscriptionsResponse, h as VerifyPaymentResponse, V as VerifyPaymentInput, L as ListSubscriptionsInput } from '../types-CKR2ILS1.js';
7
+ export { G as GetPlansResponse, i as RazorpayApiError, R as RazorpayApiResult, j as RazorpayClientActions } from '../types-CKR2ILS1.js';
8
8
  import 'razorpay';
9
9
 
10
10
  /**
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SubscriptionRecord } from './types-BC0odu_S.js';
1
+ import { S as SubscriptionRecord } from './types-3dNrA0qB.js';
2
2
  import { razorpayPlugin } from './index.js';
3
- import { R as RazorpayApiResult, P as PlanSummary, L as ListSubscriptionsInput, C as CreateOrUpdateSubscriptionInput, a as CancelSubscriptionInput, b as RestoreSubscriptionInput, V as VerifyPaymentInput } from './types-B91GdcpF.js';
3
+ import { R as RazorpayApiResult, P as PlanSummary, L as ListSubscriptionsInput, C as CreateOrUpdateSubscriptionInput, a as CancelSubscriptionInput, b as RestoreSubscriptionInput, V as VerifyPaymentInput } from './types-CKR2ILS1.js';
4
4
  import 'razorpay';
5
5
  import 'better-auth';
6
6
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BetterAuthPlugin } from 'better-auth';
2
- import { R as RazorpayPluginOptions } from './types-BC0odu_S.js';
3
- export { O as OnWebhookEventCallback, a as RazorpayApiResponse, b as RazorpayErrorResponse, c as RazorpayPlan, d as RazorpaySubscription, e as RazorpaySuccessResponse, f as RazorpayUserRecord, g as RazorpayWebhookContext, h as RazorpayWebhookEvent, i as RazorpayWebhookPayload, S as SubscriptionRecord, j as SubscriptionStatus } from './types-BC0odu_S.js';
2
+ import { R as RazorpayPluginOptions } from './types-3dNrA0qB.js';
3
+ export { O as OnWebhookEventCallback, a as RazorpayApiResponse, b as RazorpayErrorResponse, c as RazorpayPlan, d as RazorpaySubscription, e as RazorpaySuccessResponse, f as RazorpayUserRecord, g as RazorpayWebhookContext, h as RazorpayWebhookEvent, i as RazorpayWebhookPayload, S as SubscriptionRecord, j as SubscriptionStatus } from './types-3dNrA0qB.js';
4
4
  import 'razorpay';
5
5
 
6
6
  interface WebhookResult {
package/dist/index.js CHANGED
@@ -4481,24 +4481,48 @@ import { createAuthEndpoint as createAuthEndpoint3 } from "better-auth/api";
4481
4481
  async function resolvePlans2(plans) {
4482
4482
  return typeof plans === "function" ? plans() : plans;
4483
4483
  }
4484
- var getPlans = (options) => createAuthEndpoint3("/razorpay/get-plans", { method: "GET" }, async (_ctx) => {
4484
+ async function fetchPlanPrice(razorpay, planId) {
4485
+ try {
4486
+ const plan = await razorpay.plans.fetch(planId);
4487
+ const item = plan?.item;
4488
+ if (item && typeof item.amount === "number" && typeof item.currency === "string") {
4489
+ return {
4490
+ amount: item.amount,
4491
+ currency: item.currency,
4492
+ period: typeof plan.period === "string" ? plan.period : "monthly",
4493
+ interval: typeof plan.interval === "number" ? plan.interval : void 0
4494
+ };
4495
+ }
4496
+ } catch {
4497
+ }
4498
+ return void 0;
4499
+ }
4500
+ var getPlans = (razorpay, options) => createAuthEndpoint3("/razorpay/get-plans", { method: "GET" }, async (_ctx) => {
4485
4501
  try {
4486
4502
  const subOpts = options.subscription;
4487
4503
  if (!subOpts?.enabled) {
4488
4504
  return { success: true, data: [] };
4489
4505
  }
4490
4506
  const plans = await resolvePlans2(subOpts.plans);
4491
- return {
4492
- success: true,
4493
- data: plans.map((p) => ({
4494
- name: p.name,
4495
- monthlyPlanId: p.monthlyPlanId,
4496
- annualPlanId: p.annualPlanId,
4497
- description: p.description,
4498
- limits: p.limits,
4499
- freeTrial: p.freeTrial ? { days: p.freeTrial.days } : void 0
4500
- }))
4501
- };
4507
+ const data = await Promise.all(
4508
+ plans.map(async (p) => {
4509
+ const [monthly, annual] = await Promise.all([
4510
+ fetchPlanPrice(razorpay, p.monthlyPlanId),
4511
+ p.annualPlanId ? fetchPlanPrice(razorpay, p.annualPlanId) : Promise.resolve(void 0)
4512
+ ]);
4513
+ return {
4514
+ name: p.name,
4515
+ monthlyPlanId: p.monthlyPlanId,
4516
+ annualPlanId: p.annualPlanId,
4517
+ description: p.description,
4518
+ limits: p.limits,
4519
+ freeTrial: p.freeTrial ? { days: p.freeTrial.days } : void 0,
4520
+ monthly,
4521
+ annual
4522
+ };
4523
+ })
4524
+ );
4525
+ return { success: true, data };
4502
4526
  } catch (error) {
4503
4527
  return handleRazorpayError(error);
4504
4528
  }
@@ -4967,7 +4991,7 @@ var razorpayPlugin = (options) => {
4967
4991
  "subscription/cancel": cancelSubscription(razorpay),
4968
4992
  "subscription/restore": restoreSubscription(razorpay),
4969
4993
  "subscription/list": listSubscriptions({ subscription: subOpts }),
4970
- "get-plans": getPlans({ subscription: subOpts }),
4994
+ "get-plans": getPlans(razorpay, { subscription: subOpts }),
4971
4995
  ...razorpayKeySecret ? { "verify-payment": verifyPayment(razorpayKeySecret) } : {},
4972
4996
  webhook: webhook(razorpayWebhookSecret, options.onWebhookEvent ?? void 0, {
4973
4997
  subscription: subOpts,