@haatlabs-core/billing 0.21.0 → 0.22.0

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.
@@ -33,6 +33,19 @@ export type PaymentProviderName = (typeof PaymentProviderName)[keyof typeof Paym
33
33
  /** The gateways with a hosted checkout page and an account-wide key. Shopify billing is not one. */
34
34
  export declare const isGateway: (value: string) => value is "stripe" | "razorpay";
35
35
  export declare const isProvider: (value: string) => value is PaymentProviderName;
36
+ /**
37
+ * How often a price is charged. A yearly price is for twelve months; a yearly
38
+ * subscription's allowance is still for each month.
39
+ */
40
+ export declare const PriceInterval: {
41
+ readonly MONTH: "MONTH";
42
+ readonly YEAR: "YEAR";
43
+ };
44
+ export type PriceInterval = (typeof PriceInterval)[keyof typeof PriceInterval];
45
+ export declare const PriceIntervalSchema: z.ZodEnum<{
46
+ readonly MONTH: "MONTH";
47
+ readonly YEAR: "YEAR";
48
+ }>;
36
49
  export declare const CheckoutRequestSchema: z.ZodObject<{
37
50
  planCode: z.ZodString;
38
51
  provider: z.ZodEnum<{
@@ -41,6 +54,10 @@ export declare const CheckoutRequestSchema: z.ZodObject<{
41
54
  readonly shopify: "shopify";
42
55
  }>;
43
56
  currency: z.ZodOptional<z.ZodString>;
57
+ interval: z.ZodOptional<z.ZodEnum<{
58
+ readonly MONTH: "MONTH";
59
+ readonly YEAR: "YEAR";
60
+ }>>;
44
61
  }, z.core.$strip>;
45
62
  export type CheckoutRequest = z.infer<typeof CheckoutRequestSchema>;
46
63
  /** A product's name, where an app sells several (see `DEFAULT_PRODUCT`). */
@@ -62,6 +79,10 @@ export type CancelRenewalResponse = z.infer<typeof CancelRenewalResponseSchema>;
62
79
  /** A plan bought through Shopify's billing, from inside Shopify admin: Shopify sets the price. */
63
80
  export declare const ShopifyCheckoutRequestSchema: z.ZodObject<{
64
81
  planCode: z.ZodString;
82
+ interval: z.ZodOptional<z.ZodEnum<{
83
+ readonly MONTH: "MONTH";
84
+ readonly YEAR: "YEAR";
85
+ }>>;
65
86
  }, z.core.$strip>;
66
87
  export type ShopifyCheckoutRequest = z.infer<typeof ShopifyCheckoutRequestSchema>;
67
88
  /** The paid plan Shopify is charging the store for, or null when it is charging for none. */
@@ -73,7 +94,7 @@ export declare const ShopifyPlanResponseSchema: z.ZodObject<{
73
94
  }, z.core.$strip>;
74
95
  export type ShopifyPlanResponse = z.infer<typeof ShopifyPlanResponseSchema>;
75
96
  /**
76
- * A plan's monthly price at one gateway. `priceRef` is the gateway's own ID for it (a Stripe
97
+ * A plan's price at one gateway, monthly unless `interval` says YEAR. `priceRef` is the gateway's own ID for it (a Stripe
77
98
  * price ID, a Razorpay plan ID), an identifier and not a secret. `amountMinor` is in the
78
99
  * currency's smallest unit and is what the pages show; the gateway charges what its own
79
100
  * price says, so keep the two the same.
@@ -87,6 +108,10 @@ export declare const PlanPriceSeedSchema: z.ZodObject<{
87
108
  priceRef: z.ZodString;
88
109
  currency: z.ZodString;
89
110
  amountMinor: z.ZodNumber;
111
+ interval: z.ZodDefault<z.ZodEnum<{
112
+ readonly MONTH: "MONTH";
113
+ readonly YEAR: "YEAR";
114
+ }>>;
90
115
  }, z.core.$strip>;
91
116
  /** The plans an administrator can put an organization on. */
92
117
  export declare const AdminPlanListSchema: z.ZodObject<{
@@ -136,6 +161,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
136
161
  start: z.ZodString;
137
162
  end: z.ZodString;
138
163
  }, z.core.$strip>;
164
+ interval: z.ZodDefault<z.ZodEnum<{
165
+ readonly MONTH: "MONTH";
166
+ readonly YEAR: "YEAR";
167
+ }>>;
139
168
  metrics: z.ZodArray<z.ZodObject<{
140
169
  metric: z.ZodEnum<{ [k_1 in M]: k_1; } extends infer T ? { [k in keyof T]: T[k]; } : never>;
141
170
  used: z.ZodNumber;
@@ -168,6 +197,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
168
197
  }>;
169
198
  currency: z.ZodString;
170
199
  amountMinor: z.ZodNumber;
200
+ interval: z.ZodDefault<z.ZodEnum<{
201
+ readonly MONTH: "MONTH";
202
+ readonly YEAR: "YEAR";
203
+ }>>;
171
204
  }, z.core.$strip>>;
172
205
  }, z.core.$strip>>;
173
206
  providers: z.ZodArray<z.ZodEnum<{
@@ -195,6 +228,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
195
228
  priceRef: z.ZodString;
196
229
  currency: z.ZodString;
197
230
  amountMinor: z.ZodNumber;
231
+ interval: z.ZodDefault<z.ZodEnum<{
232
+ readonly MONTH: "MONTH";
233
+ readonly YEAR: "YEAR";
234
+ }>>;
198
235
  }, z.core.$strip>>>;
199
236
  }, z.core.$strip>;
200
237
  planSeedFile: z.ZodObject<{
@@ -217,6 +254,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
217
254
  priceRef: z.ZodString;
218
255
  currency: z.ZodString;
219
256
  amountMinor: z.ZodNumber;
257
+ interval: z.ZodDefault<z.ZodEnum<{
258
+ readonly MONTH: "MONTH";
259
+ readonly YEAR: "YEAR";
260
+ }>>;
220
261
  }, z.core.$strip>>>;
221
262
  }, z.core.$strip>>;
222
263
  }, z.core.$strict>;
@@ -32,6 +32,8 @@ __export(contracts_exports, {
32
32
  PLAN_PRIORITY_KEY: () => PLAN_PRIORITY_KEY,
33
33
  PaymentProviderName: () => PaymentProviderName,
34
34
  PlanPriceSeedSchema: () => PlanPriceSeedSchema,
35
+ PriceInterval: () => PriceInterval,
36
+ PriceIntervalSchema: () => PriceIntervalSchema,
35
37
  ProductSchema: () => ProductSchema,
36
38
  ShopifyCheckoutRequestSchema: () => ShopifyCheckoutRequestSchema,
37
39
  ShopifyPlanResponseSchema: () => ShopifyPlanResponseSchema,
@@ -61,6 +63,8 @@ const PaymentProviderName = {
61
63
  };
62
64
  const isGateway = (value) => value === "stripe" || value === "razorpay";
63
65
  const isProvider = (value) => Object.hasOwn(PaymentProviderName, value);
66
+ const PriceInterval = { MONTH: "MONTH", YEAR: "YEAR" };
67
+ const PriceIntervalSchema = import_zod.z.enum(PriceInterval);
64
68
  const MAX_PLAN_CODE_LENGTH = 40;
65
69
  const MAX_PLAN_NAME_LENGTH = 80;
66
70
  const currency = import_zod.z.string().regex(/^[A-Z]{3}$/);
@@ -68,14 +72,18 @@ const CheckoutRequestSchema = import_zod.z.object({
68
72
  planCode: import_zod.z.string().min(1).max(MAX_PLAN_CODE_LENGTH),
69
73
  provider: import_zod.z.enum(PaymentProviderName),
70
74
  /** Which of the plan's prices at that gateway; needed when it has more than one. */
71
- currency: currency.optional()
75
+ currency: currency.optional(),
76
+ /** Monthly or yearly; monthly when left out. */
77
+ interval: PriceIntervalSchema.optional()
72
78
  });
73
79
  const ProductSchema = import_zod.z.string().regex(/^[a-z][a-z0-9-]{0,31}$/, "not a product name");
74
80
  const CancelRequestSchema = import_zod.z.object({ product: ProductSchema.optional() }).optional();
75
81
  const CheckoutResponseSchema = import_zod.z.object({ url: import_zod.z.url() });
76
82
  const CancelRenewalResponseSchema = import_zod.z.object({ cancelled: import_zod.z.literal(true) });
77
83
  const ShopifyCheckoutRequestSchema = import_zod.z.object({
78
- planCode: import_zod.z.string().min(1).max(MAX_PLAN_CODE_LENGTH)
84
+ planCode: import_zod.z.string().min(1).max(MAX_PLAN_CODE_LENGTH),
85
+ /** Monthly (every 30 days at Shopify) or yearly; monthly when left out. */
86
+ interval: PriceIntervalSchema.optional()
79
87
  });
80
88
  const ShopifyPlanResponseSchema = import_zod.z.object({
81
89
  plan: import_zod.z.object({ code: import_zod.z.string(), name: import_zod.z.string() }).nullable()
@@ -86,7 +94,8 @@ const PlanPriceSeedSchema = import_zod.z.object({
86
94
  message: "Put the gateway's real ID here, not a placeholder"
87
95
  }),
88
96
  currency,
89
- amountMinor: import_zod.z.number().int().positive()
97
+ amountMinor: import_zod.z.number().int().positive(),
98
+ interval: PriceIntervalSchema.default("MONTH")
90
99
  });
91
100
  const calendarDay = import_zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
92
101
  const AdminPlanListSchema = import_zod.z.object({
@@ -115,6 +124,8 @@ function billingSchemas(catalog) {
115
124
  plan: import_zod.z.object({ code: import_zod.z.string(), name: import_zod.z.string() }),
116
125
  /** The billing period: `start` is its first day, `end` the first day after it. */
117
126
  period: import_zod.z.object({ start: day, end: day }),
127
+ /** How often the plan held is charged for; a yearly one's period is still a month. */
128
+ interval: PriceIntervalSchema.default("MONTH"),
118
129
  metrics: import_zod.z.array(import_zod.z.object({ metric, used: import_zod.z.number().int().nonnegative(), limit })),
119
130
  /** The gateway charging for the plan, or null when nothing is being charged. */
120
131
  managedBy: import_zod.z.enum(PaymentProviderName).nullable()
@@ -132,11 +143,13 @@ function billingSchemas(catalog) {
132
143
  }).optional(),
133
144
  /** What the plan allows at most; null: no cap of its own. */
134
145
  caps: import_zod.z.object(keyed(catalog.caps, import_zod.z.number().int().nullable().optional())).optional(),
135
- /** Per month, in the currency's smallest unit, through each gateway offered here. */
146
+ /** For each interval, in the currency's smallest unit, through each gateway offered here. */
136
147
  prices: import_zod.z.array(import_zod.z.object({
137
148
  provider: import_zod.z.enum(PaymentProviderName),
138
149
  currency: import_zod.z.string(),
139
- amountMinor: import_zod.z.number().int().positive()
150
+ amountMinor: import_zod.z.number().int().positive(),
151
+ /** A server from before yearly prices sends none: its prices are monthly. */
152
+ interval: PriceIntervalSchema.default("MONTH")
140
153
  }))
141
154
  })),
142
155
  /** The gateways a plan can be bought through here. Empty: nothing is for sale. */
@@ -161,7 +174,7 @@ function billingSchemas(catalog) {
161
174
  /** Whether the plan's work goes ahead of ordinary work. Left out: it does not. */
162
175
  priority: import_zod.z.boolean().default(false),
163
176
  /** What the plan costs through each gateway it is sold through. None: not for sale. */
164
- prices: import_zod.z.array(PlanPriceSeedSchema).default([]).refine((prices) => new Set(prices.map((price) => `${price.provider}:${price.currency}`)).size === prices.length, { message: "A plan can have one price for each gateway and currency" })
177
+ prices: import_zod.z.array(PlanPriceSeedSchema).default([]).refine((prices) => new Set(prices.map((price) => `${price.provider}:${price.currency}:${price.interval}`)).size === prices.length, { message: "A plan can have one price for each gateway, currency and interval" })
165
178
  });
166
179
  const planSeedFile = import_zod.z.strictObject({ plans: import_zod.z.array(planSeed).min(1) }).refine((file) => {
167
180
  const products = new Set(file.plans.map((plan) => plan.product ?? DEFAULT_PRODUCT));
@@ -192,6 +205,8 @@ function billingSchemas(catalog) {
192
205
  PLAN_PRIORITY_KEY,
193
206
  PaymentProviderName,
194
207
  PlanPriceSeedSchema,
208
+ PriceInterval,
209
+ PriceIntervalSchema,
195
210
  ProductSchema,
196
211
  ShopifyCheckoutRequestSchema,
197
212
  ShopifyPlanResponseSchema,
@@ -1,13 +1,21 @@
1
1
  import { AppError } from '@haatlabs-core/errors';
2
+ import type { PriceInterval } from './contracts.js';
2
3
  export type GatewayName = 'stripe' | 'razorpay';
3
4
  export interface CheckoutInput {
4
5
  organizationId: string;
5
6
  planCode: string;
6
7
  /** The gateway's own ID for the plan's price (a Stripe price, a Razorpay plan). */
7
8
  priceRef: string;
9
+ /** How often the price charges; monthly when left out. Stripe's price says so itself. */
10
+ interval?: PriceInterval;
8
11
  customerEmail: string;
9
12
  successUrl: string;
10
13
  cancelUrl: string;
14
+ /**
15
+ * The end of the organization's free trial: the first charge waits for it when it is
16
+ * still to come (Razorpay's `start_at`). Left out, or past: charged from today.
17
+ */
18
+ trialEndsAt?: Date;
11
19
  }
12
20
  /**
13
21
  * What a gateway's webhook says about a subscription. `active`: paid up for the period
@@ -27,6 +35,11 @@ export type SubscriptionEvent = {
27
35
  periodEnd: Date;
28
36
  /** When the gateway produced the event: events can arrive late and out of order. */
29
37
  occurredAt: Date;
38
+ /**
39
+ * True for an authorisation made during a free trial: the plan holds from now, but
40
+ * nothing is charged until `periodEnd`, when the trial ends.
41
+ */
42
+ trial?: true;
30
43
  } | {
31
44
  kind: 'ended';
32
45
  provider: GatewayName;
@@ -64,9 +77,11 @@ export declare function hmacMatches(secret: string, payload: string | Buffer, si
64
77
  * Sends a request to a gateway and returns its JSON. A failure is reported with a fixed
65
78
  * message: the gateway's own text can repeat keys and identifiers, so it is never passed on.
66
79
  */
67
- export declare function callGateway(fetchImpl: typeof fetch, url: string, init: {
80
+ export declare function callGateway(fetchImpl: typeof fetch, url: string,
81
+ /** A POST with `body`; a GET (a read) without one. */
82
+ init: {
68
83
  headers: Record<string, string>;
69
- body: string;
84
+ body?: string;
70
85
  }): Promise<Record<string, unknown>>;
71
86
  /** The hosted page a customer is sent to must be a plain https address. */
72
87
  export declare function hostedPage(value: unknown): {
@@ -55,9 +55,9 @@ async function callGateway(fetchImpl, url, init) {
55
55
  let response;
56
56
  try {
57
57
  response = await fetchImpl(url, {
58
- method: "POST",
58
+ method: init.body === void 0 ? "GET" : "POST",
59
59
  headers: init.headers,
60
- body: init.body,
60
+ ...init.body === void 0 ? {} : { body: init.body },
61
61
  redirect: "error",
62
62
  signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
63
63
  });
@@ -1,5 +1,6 @@
1
+ import type { PriceInterval } from './contracts.js';
1
2
  import type { CheckoutInput, PaymentGateway, SubscriptionEvent } from './gateway.js';
2
- /** A monthly plan to create at Razorpay. */
3
+ /** A monthly or yearly plan to create at Razorpay. */
3
4
  export interface RazorpayPlanInput {
4
5
  /** Shown to the customer on Razorpay's page and emails, e.g. "Catalogpix Pro". */
5
6
  name: string;
@@ -7,6 +8,8 @@ export interface RazorpayPlanInput {
7
8
  currency: string;
8
9
  /** In the currency's smallest unit (paise, cents). */
9
10
  amountMinor: number;
11
+ /** How often it charges; monthly when left out. */
12
+ interval?: PriceInterval;
10
13
  notes?: Record<string, string>;
11
14
  }
12
15
  export interface RazorpayOptions {
@@ -22,18 +25,24 @@ export declare class RazorpayGateway implements PaymentGateway {
22
25
  readonly name = "razorpay";
23
26
  private readonly fetchImpl;
24
27
  constructor(options: RazorpayOptions);
25
- private post;
28
+ /** A POST with `body`; a GET without one. */
29
+ private request;
26
30
  /** Razorpay's hosted page has no return address: the customer comes back on their own. */
27
- createCheckout(input: CheckoutInput): Promise<{
31
+ createCheckout(input: CheckoutInput, now?: Date): Promise<{
28
32
  url: string;
29
33
  }>;
30
34
  readWebhook(rawBody: Buffer, headers: Record<string, string | undefined>, now?: Date): SubscriptionEvent | null;
31
35
  /**
32
- * Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
36
+ * Creates a monthly (or yearly) plan at Razorpay and returns its ID, the `priceRef` a plan's price is
33
37
  * recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
34
38
  * changes one: a new amount is a new plan. A currency the account is not enabled for is
35
39
  * refused as PAYMENT_PROVIDER_ERROR.
36
40
  */
37
41
  createPlan(input: RazorpayPlanInput): Promise<string>;
42
+ /**
43
+ * Stops renewal at the end of the cycle paid for. A subscription not charged yet (bought
44
+ * during a free trial, `authenticated` until `start_at`) has no such cycle: it is
45
+ * cancelled now, so it never charges, and its `subscription.cancelled` webhook ends the plan.
46
+ */
38
47
  cancelAtPeriodEnd(subscriptionRef: string): Promise<void>;
39
48
  }
@@ -23,7 +23,8 @@ module.exports = __toCommonJS(razorpay_exports);
23
23
  var import_errors = require("@haatlabs-core/errors");
24
24
  var import_gateway = require("./gateway.js");
25
25
  const API = "https://api.razorpay.com/v1";
26
- const BILLING_CYCLES = 120;
26
+ const BILLING_CYCLES = { MONTH: 120, YEAR: 10 };
27
+ const PERIOD = { MONTH: "monthly", YEAR: "yearly" };
27
28
  const PAID_UP = /* @__PURE__ */ new Set([
28
29
  "subscription.activated",
29
30
  "subscription.charged",
@@ -36,6 +37,7 @@ const ENDED = /* @__PURE__ */ new Set([
36
37
  "subscription.completed",
37
38
  "subscription.paused"
38
39
  ]);
40
+ const NOT_STARTED = /* @__PURE__ */ new Set(["created", "authenticated"]);
39
41
  const FINISHED = /* @__PURE__ */ new Set(["subscription.cancelled", "subscription.completed"]);
40
42
  const REFERENCE_ID = /^[A-Za-z0-9_]{1,128}$/;
41
43
  class RazorpayGateway {
@@ -46,22 +48,25 @@ class RazorpayGateway {
46
48
  this.options = options;
47
49
  this.fetchImpl = options.fetch ?? fetch;
48
50
  }
49
- post(path, body) {
51
+ /** A POST with `body`; a GET without one. */
52
+ request(path, body) {
50
53
  const credentials = Buffer.from(`${this.options.keyId}:${this.options.keySecret}`);
51
54
  return (0, import_gateway.callGateway)(this.fetchImpl, `${API}${path}`, {
52
55
  headers: {
53
56
  Authorization: `Basic ${credentials.toString("base64")}`,
54
- "Content-Type": "application/json"
57
+ ...body === void 0 ? {} : { "Content-Type": "application/json" }
55
58
  },
56
- body: JSON.stringify(body)
59
+ ...body === void 0 ? {} : { body: JSON.stringify(body) }
57
60
  });
58
61
  }
59
62
  /** Razorpay's hosted page has no return address: the customer comes back on their own. */
60
- async createCheckout(input) {
61
- const subscription = await this.post("/subscriptions", {
63
+ async createCheckout(input, now = /* @__PURE__ */ new Date()) {
64
+ const startAt = input.trialEndsAt && input.trialEndsAt > now ? Math.floor(input.trialEndsAt.getTime() / import_gateway.MS_PER_SECOND) : null;
65
+ const subscription = await this.request("/subscriptions", {
62
66
  plan_id: input.priceRef,
63
- total_count: BILLING_CYCLES,
67
+ total_count: BILLING_CYCLES[input.interval ?? "MONTH"],
64
68
  customer_notify: 1,
69
+ ...startAt === null ? {} : { start_at: startAt },
65
70
  // Returned on every webhook for the subscription: how it names the organization.
66
71
  notes: { organization_id: input.organizationId, plan_code: input.planCode }
67
72
  });
@@ -93,10 +98,12 @@ class RazorpayGateway {
93
98
  occurredAt
94
99
  };
95
100
  }
96
- if (!PAID_UP.has(name))
101
+ const startAt = (0, import_gateway.instant)(subscription.start_at);
102
+ const trial = name === "subscription.authenticated" && startAt !== null && startAt > occurredAt;
103
+ if (!trial && !PAID_UP.has(name))
97
104
  return null;
98
- const periodStart = (0, import_gateway.instant)(subscription.current_start);
99
- const periodEnd = (0, import_gateway.instant)(subscription.current_end);
105
+ const periodStart = trial ? occurredAt : (0, import_gateway.instant)(subscription.current_start);
106
+ const periodEnd = trial ? startAt : (0, import_gateway.instant)(subscription.current_end);
100
107
  if (!periodStart || !periodEnd)
101
108
  return null;
102
109
  return {
@@ -109,18 +116,19 @@ class RazorpayGateway {
109
116
  customerRef: (0, import_gateway.text)(subscription.customer_id),
110
117
  periodStart,
111
118
  periodEnd,
112
- occurredAt
119
+ occurredAt,
120
+ ...trial ? { trial: true } : {}
113
121
  };
114
122
  }
115
123
  /**
116
- * Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
124
+ * Creates a monthly (or yearly) plan at Razorpay and returns its ID, the `priceRef` a plan's price is
117
125
  * recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
118
126
  * changes one: a new amount is a new plan. A currency the account is not enabled for is
119
127
  * refused as PAYMENT_PROVIDER_ERROR.
120
128
  */
121
129
  async createPlan(input) {
122
- const plan = await this.post("/plans", {
123
- period: "monthly",
130
+ const plan = await this.request("/plans", {
131
+ period: PERIOD[input.interval ?? "MONTH"],
124
132
  interval: 1,
125
133
  item: { name: input.name, amount: input.amountMinor, currency: input.currency },
126
134
  ...input.notes ? { notes: input.notes } : {}
@@ -130,10 +138,16 @@ class RazorpayGateway {
130
138
  throw (0, import_gateway.gatewayError)(false);
131
139
  return id;
132
140
  }
141
+ /**
142
+ * Stops renewal at the end of the cycle paid for. A subscription not charged yet (bought
143
+ * during a free trial, `authenticated` until `start_at`) has no such cycle: it is
144
+ * cancelled now, so it never charges, and its `subscription.cancelled` webhook ends the plan.
145
+ */
133
146
  async cancelAtPeriodEnd(subscriptionRef) {
134
- await this.post(`/subscriptions/${(0, import_gateway.requireReference)(subscriptionRef)}/cancel`, {
135
- cancel_at_cycle_end: 1
136
- });
147
+ const path = `/subscriptions/${(0, import_gateway.requireReference)(subscriptionRef)}`;
148
+ const status = (0, import_gateway.text)((await this.request(path)).status);
149
+ const started = status === null || !NOT_STARTED.has(status);
150
+ await this.request(`${path}/cancel`, { cancel_at_cycle_end: started ? 1 : 0 });
137
151
  }
138
152
  }
139
153
  // Annotate the CommonJS export names for ESM import in node:
@@ -43,13 +43,16 @@ export interface ShopifyPlanPorts {
43
43
  test: boolean;
44
44
  createdAt: Date;
45
45
  currentPeriodEnd: Date | null;
46
+ /** Shopify's `AppPricingInterval`; every 30 days when left out. */
47
+ interval?: string;
46
48
  }[]>;
47
49
  onRecord(): Promise<ShopifyPlanRecord | null>;
48
- /** The plans sold through Shopify. */
50
+ /** The plans sold through Shopify, each price monthly unless `interval` is YEAR. */
49
51
  prices(): Promise<{
50
52
  planCode: string;
51
53
  planName: string;
52
54
  priceRef: string;
55
+ interval?: string;
53
56
  }[]>;
54
57
  apply(change: ShopifyPlanChange): Promise<'applied' | 'duplicate' | 'ignored'>;
55
58
  /**
@@ -27,6 +27,14 @@ module.exports = __toCommonJS(shopify_plan_exports);
27
27
  const SHOPIFY_PROVIDER = "shopify";
28
28
  const PERIOD_MS = 30 * 864e5;
29
29
  const DECIMAL = 10;
30
+ const yearAfter = (from, years) => {
31
+ const year = from.getUTCFullYear() + years;
32
+ const month = from.getUTCMonth();
33
+ const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
34
+ const moved = new Date(from);
35
+ moved.setUTCFullYear(year, month, Math.min(from.getUTCDate(), lastDay));
36
+ return moved;
37
+ };
30
38
  const shopifySubscriptionName = (appName, planName) => `${appName} ${planName}`;
31
39
  function decimalAmount(amountMinor, currency) {
32
40
  const digits = new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits ?? 2;
@@ -55,10 +63,12 @@ async function reconcileShopifyPlan(ports, input) {
55
63
  });
56
64
  return { state: "ended" };
57
65
  }
58
- const plan = (await ports.prices()).find((price) => shopifySubscriptionName(input.appName, price.planName) === newest.name);
66
+ const yearly = newest.interval === "ANNUAL";
67
+ const plan = (await ports.prices()).find((price) => shopifySubscriptionName(input.appName, price.planName) === newest.name && price.interval === "YEAR" === yearly);
59
68
  if (!plan)
60
69
  return { state: "unmatched", name: newest.name };
61
- const periodEnd = newest.currentPeriodEnd ?? new Date(newest.createdAt.getTime() + PERIOD_MS);
70
+ const periodEnd = newest.currentPeriodEnd ?? (yearly ? yearAfter(newest.createdAt, 1) : new Date(newest.createdAt.getTime() + PERIOD_MS));
71
+ const periodStart = yearly ? yearAfter(periodEnd, -1) : new Date(periodEnd.getTime() - PERIOD_MS);
62
72
  const running = ownedBy(record, input.storeRef) && record.subscriptionRef === newest.id;
63
73
  const eventId = running ? `active:${newest.id}:${periodEnd.toISOString()}` : `active:${newest.id}:${periodEnd.toISOString()}:${now.toISOString()}`;
64
74
  const outcome = await ports.apply({
@@ -70,7 +80,7 @@ async function reconcileShopifyPlan(ports, input) {
70
80
  subscriptionRef: newest.id,
71
81
  customerRef: input.storeRef,
72
82
  // Never a period that has not started: the plan would not be in force until it did.
73
- periodStart: new Date(Math.min(periodEnd.getTime() - PERIOD_MS, now.getTime())),
83
+ periodStart: new Date(Math.min(periodStart.getTime(), now.getTime())),
74
84
  periodEnd,
75
85
  occurredAt: now,
76
86
  // Shopify keeps one subscription for the app in a shop: a new one took the old one's place.
@@ -33,6 +33,19 @@ export type PaymentProviderName = (typeof PaymentProviderName)[keyof typeof Paym
33
33
  /** The gateways with a hosted checkout page and an account-wide key. Shopify billing is not one. */
34
34
  export declare const isGateway: (value: string) => value is "stripe" | "razorpay";
35
35
  export declare const isProvider: (value: string) => value is PaymentProviderName;
36
+ /**
37
+ * How often a price is charged. A yearly price is for twelve months; a yearly
38
+ * subscription's allowance is still for each month.
39
+ */
40
+ export declare const PriceInterval: {
41
+ readonly MONTH: "MONTH";
42
+ readonly YEAR: "YEAR";
43
+ };
44
+ export type PriceInterval = (typeof PriceInterval)[keyof typeof PriceInterval];
45
+ export declare const PriceIntervalSchema: z.ZodEnum<{
46
+ readonly MONTH: "MONTH";
47
+ readonly YEAR: "YEAR";
48
+ }>;
36
49
  export declare const CheckoutRequestSchema: z.ZodObject<{
37
50
  planCode: z.ZodString;
38
51
  provider: z.ZodEnum<{
@@ -41,6 +54,10 @@ export declare const CheckoutRequestSchema: z.ZodObject<{
41
54
  readonly shopify: "shopify";
42
55
  }>;
43
56
  currency: z.ZodOptional<z.ZodString>;
57
+ interval: z.ZodOptional<z.ZodEnum<{
58
+ readonly MONTH: "MONTH";
59
+ readonly YEAR: "YEAR";
60
+ }>>;
44
61
  }, z.core.$strip>;
45
62
  export type CheckoutRequest = z.infer<typeof CheckoutRequestSchema>;
46
63
  /** A product's name, where an app sells several (see `DEFAULT_PRODUCT`). */
@@ -62,6 +79,10 @@ export type CancelRenewalResponse = z.infer<typeof CancelRenewalResponseSchema>;
62
79
  /** A plan bought through Shopify's billing, from inside Shopify admin: Shopify sets the price. */
63
80
  export declare const ShopifyCheckoutRequestSchema: z.ZodObject<{
64
81
  planCode: z.ZodString;
82
+ interval: z.ZodOptional<z.ZodEnum<{
83
+ readonly MONTH: "MONTH";
84
+ readonly YEAR: "YEAR";
85
+ }>>;
65
86
  }, z.core.$strip>;
66
87
  export type ShopifyCheckoutRequest = z.infer<typeof ShopifyCheckoutRequestSchema>;
67
88
  /** The paid plan Shopify is charging the store for, or null when it is charging for none. */
@@ -73,7 +94,7 @@ export declare const ShopifyPlanResponseSchema: z.ZodObject<{
73
94
  }, z.core.$strip>;
74
95
  export type ShopifyPlanResponse = z.infer<typeof ShopifyPlanResponseSchema>;
75
96
  /**
76
- * A plan's monthly price at one gateway. `priceRef` is the gateway's own ID for it (a Stripe
97
+ * A plan's price at one gateway, monthly unless `interval` says YEAR. `priceRef` is the gateway's own ID for it (a Stripe
77
98
  * price ID, a Razorpay plan ID), an identifier and not a secret. `amountMinor` is in the
78
99
  * currency's smallest unit and is what the pages show; the gateway charges what its own
79
100
  * price says, so keep the two the same.
@@ -87,6 +108,10 @@ export declare const PlanPriceSeedSchema: z.ZodObject<{
87
108
  priceRef: z.ZodString;
88
109
  currency: z.ZodString;
89
110
  amountMinor: z.ZodNumber;
111
+ interval: z.ZodDefault<z.ZodEnum<{
112
+ readonly MONTH: "MONTH";
113
+ readonly YEAR: "YEAR";
114
+ }>>;
90
115
  }, z.core.$strip>;
91
116
  /** The plans an administrator can put an organization on. */
92
117
  export declare const AdminPlanListSchema: z.ZodObject<{
@@ -136,6 +161,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
136
161
  start: z.ZodString;
137
162
  end: z.ZodString;
138
163
  }, z.core.$strip>;
164
+ interval: z.ZodDefault<z.ZodEnum<{
165
+ readonly MONTH: "MONTH";
166
+ readonly YEAR: "YEAR";
167
+ }>>;
139
168
  metrics: z.ZodArray<z.ZodObject<{
140
169
  metric: z.ZodEnum<{ [k_1 in M]: k_1; } extends infer T ? { [k in keyof T]: T[k]; } : never>;
141
170
  used: z.ZodNumber;
@@ -168,6 +197,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
168
197
  }>;
169
198
  currency: z.ZodString;
170
199
  amountMinor: z.ZodNumber;
200
+ interval: z.ZodDefault<z.ZodEnum<{
201
+ readonly MONTH: "MONTH";
202
+ readonly YEAR: "YEAR";
203
+ }>>;
171
204
  }, z.core.$strip>>;
172
205
  }, z.core.$strip>>;
173
206
  providers: z.ZodArray<z.ZodEnum<{
@@ -195,6 +228,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
195
228
  priceRef: z.ZodString;
196
229
  currency: z.ZodString;
197
230
  amountMinor: z.ZodNumber;
231
+ interval: z.ZodDefault<z.ZodEnum<{
232
+ readonly MONTH: "MONTH";
233
+ readonly YEAR: "YEAR";
234
+ }>>;
198
235
  }, z.core.$strip>>>;
199
236
  }, z.core.$strip>;
200
237
  planSeedFile: z.ZodObject<{
@@ -217,6 +254,10 @@ export declare function billingSchemas<M extends string, C extends string, F ext
217
254
  priceRef: z.ZodString;
218
255
  currency: z.ZodString;
219
256
  amountMinor: z.ZodNumber;
257
+ interval: z.ZodDefault<z.ZodEnum<{
258
+ readonly MONTH: "MONTH";
259
+ readonly YEAR: "YEAR";
260
+ }>>;
220
261
  }, z.core.$strip>>>;
221
262
  }, z.core.$strip>>;
222
263
  }, z.core.$strict>;
package/dist/contracts.js CHANGED
@@ -28,6 +28,12 @@ export const PaymentProviderName = {
28
28
  /** The gateways with a hosted checkout page and an account-wide key. Shopify billing is not one. */
29
29
  export const isGateway = (value) => value === 'stripe' || value === 'razorpay';
30
30
  export const isProvider = (value) => Object.hasOwn(PaymentProviderName, value);
31
+ /**
32
+ * How often a price is charged. A yearly price is for twelve months; a yearly
33
+ * subscription's allowance is still for each month.
34
+ */
35
+ export const PriceInterval = { MONTH: 'MONTH', YEAR: 'YEAR' };
36
+ export const PriceIntervalSchema = z.enum(PriceInterval);
31
37
  const MAX_PLAN_CODE_LENGTH = 40;
32
38
  const MAX_PLAN_NAME_LENGTH = 80;
33
39
  const currency = z.string().regex(/^[A-Z]{3}$/);
@@ -36,6 +42,8 @@ export const CheckoutRequestSchema = z.object({
36
42
  provider: z.enum(PaymentProviderName),
37
43
  /** Which of the plan's prices at that gateway; needed when it has more than one. */
38
44
  currency: currency.optional(),
45
+ /** Monthly or yearly; monthly when left out. */
46
+ interval: PriceIntervalSchema.optional(),
39
47
  });
40
48
  /** A product's name, where an app sells several (see `DEFAULT_PRODUCT`). */
41
49
  export const ProductSchema = z.string().regex(/^[a-z][a-z0-9-]{0,31}$/, 'not a product name');
@@ -47,13 +55,15 @@ export const CancelRenewalResponseSchema = z.object({ cancelled: z.literal(true)
47
55
  /** A plan bought through Shopify's billing, from inside Shopify admin: Shopify sets the price. */
48
56
  export const ShopifyCheckoutRequestSchema = z.object({
49
57
  planCode: z.string().min(1).max(MAX_PLAN_CODE_LENGTH),
58
+ /** Monthly (every 30 days at Shopify) or yearly; monthly when left out. */
59
+ interval: PriceIntervalSchema.optional(),
50
60
  });
51
61
  /** The paid plan Shopify is charging the store for, or null when it is charging for none. */
52
62
  export const ShopifyPlanResponseSchema = z.object({
53
63
  plan: z.object({ code: z.string(), name: z.string() }).nullable(),
54
64
  });
55
65
  /**
56
- * A plan's monthly price at one gateway. `priceRef` is the gateway's own ID for it (a Stripe
66
+ * A plan's price at one gateway, monthly unless `interval` says YEAR. `priceRef` is the gateway's own ID for it (a Stripe
57
67
  * price ID, a Razorpay plan ID), an identifier and not a secret. `amountMinor` is in the
58
68
  * currency's smallest unit and is what the pages show; the gateway charges what its own
59
69
  * price says, so keep the two the same.
@@ -68,6 +78,7 @@ export const PlanPriceSeedSchema = z.object({
68
78
  }),
69
79
  currency,
70
80
  amountMinor: z.number().int().positive(),
81
+ interval: PriceIntervalSchema.default('MONTH'),
71
82
  });
72
83
  const calendarDay = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
73
84
  /** The plans an administrator can put an organization on. */
@@ -108,6 +119,8 @@ export function billingSchemas(catalog) {
108
119
  plan: z.object({ code: z.string(), name: z.string() }),
109
120
  /** The billing period: `start` is its first day, `end` the first day after it. */
110
121
  period: z.object({ start: day, end: day }),
122
+ /** How often the plan held is charged for; a yearly one's period is still a month. */
123
+ interval: PriceIntervalSchema.default('MONTH'),
111
124
  metrics: z.array(z.object({ metric, used: z.number().int().nonnegative(), limit })),
112
125
  /** The gateway charging for the plan, or null when nothing is being charged. */
113
126
  managedBy: z.enum(PaymentProviderName).nullable(),
@@ -127,11 +140,13 @@ export function billingSchemas(catalog) {
127
140
  .optional(),
128
141
  /** What the plan allows at most; null: no cap of its own. */
129
142
  caps: z.object(keyed(catalog.caps, z.number().int().nullable().optional())).optional(),
130
- /** Per month, in the currency's smallest unit, through each gateway offered here. */
143
+ /** For each interval, in the currency's smallest unit, through each gateway offered here. */
131
144
  prices: z.array(z.object({
132
145
  provider: z.enum(PaymentProviderName),
133
146
  currency: z.string(),
134
147
  amountMinor: z.number().int().positive(),
148
+ /** A server from before yearly prices sends none: its prices are monthly. */
149
+ interval: PriceIntervalSchema.default('MONTH'),
135
150
  })),
136
151
  })),
137
152
  /** The gateways a plan can be bought through here. Empty: nothing is for sale. */
@@ -162,8 +177,8 @@ export function billingSchemas(catalog) {
162
177
  prices: z
163
178
  .array(PlanPriceSeedSchema)
164
179
  .default([])
165
- .refine((prices) => new Set(prices.map((price) => `${price.provider}:${price.currency}`)).size ===
166
- prices.length, { message: 'A plan can have one price for each gateway and currency' }),
180
+ .refine((prices) => new Set(prices.map((price) => `${price.provider}:${price.currency}:${price.interval}`))
181
+ .size === prices.length, { message: 'A plan can have one price for each gateway, currency and interval' }),
167
182
  });
168
183
  /** A file of plans, with their limits and gateway prices, to create or update. */
169
184
  const planSeedFile = z
@@ -1 +1 @@
1
- {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,yFAAyF;AACzF,4FAA4F;AAC5F,gGAAgG;AAEhG,gGAAgG;AAChG,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAElF,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAW,CAAC;AAGxF,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC,wFAAwF;AACxF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,WAAW,OAAO,EAAE,CAAC;AAEhF,iEAAiE;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,qCAAqC,CAAC;AAExE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,kBAAkB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE;CACjD,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;CACV,CAAC;AAGX,oGAAoG;AACpG,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAkC,EAAE,CACzE,KAAK,KAAK,QAAQ,IAAI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C,KAAK,CAAC,MAAM,CACf,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,eAAe,CAAC,KAAK,OAAO,CAC1E,CAAC,MAAM,KAAK,CAAC,CACjB,CAAC;IACJ,CAAC,EACD,EAAE,OAAO,EAAE,sCAAsC,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,CACrE;SACA,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACzF,OAAO,EAAE,4BAA4B;QACrC,IAAI,EAAE,CAAC,OAAO,CAAC;KAChB,CAAC;SACD,MAAM,CACL,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,CAClE,CAAC;QACF,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC;IAC5C,CAAC,EACD,EAAE,OAAO,EAAE,6CAA6C,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,CAC5E,CAAC;IAEJ,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;AACrE,CAAC"}
package/dist/gateway.d.ts CHANGED
@@ -1,13 +1,21 @@
1
1
  import { AppError } from '@haatlabs-core/errors';
2
+ import type { PriceInterval } from './contracts.js';
2
3
  export type GatewayName = 'stripe' | 'razorpay';
3
4
  export interface CheckoutInput {
4
5
  organizationId: string;
5
6
  planCode: string;
6
7
  /** The gateway's own ID for the plan's price (a Stripe price, a Razorpay plan). */
7
8
  priceRef: string;
9
+ /** How often the price charges; monthly when left out. Stripe's price says so itself. */
10
+ interval?: PriceInterval;
8
11
  customerEmail: string;
9
12
  successUrl: string;
10
13
  cancelUrl: string;
14
+ /**
15
+ * The end of the organization's free trial: the first charge waits for it when it is
16
+ * still to come (Razorpay's `start_at`). Left out, or past: charged from today.
17
+ */
18
+ trialEndsAt?: Date;
11
19
  }
12
20
  /**
13
21
  * What a gateway's webhook says about a subscription. `active`: paid up for the period
@@ -27,6 +35,11 @@ export type SubscriptionEvent = {
27
35
  periodEnd: Date;
28
36
  /** When the gateway produced the event: events can arrive late and out of order. */
29
37
  occurredAt: Date;
38
+ /**
39
+ * True for an authorisation made during a free trial: the plan holds from now, but
40
+ * nothing is charged until `periodEnd`, when the trial ends.
41
+ */
42
+ trial?: true;
30
43
  } | {
31
44
  kind: 'ended';
32
45
  provider: GatewayName;
@@ -64,9 +77,11 @@ export declare function hmacMatches(secret: string, payload: string | Buffer, si
64
77
  * Sends a request to a gateway and returns its JSON. A failure is reported with a fixed
65
78
  * message: the gateway's own text can repeat keys and identifiers, so it is never passed on.
66
79
  */
67
- export declare function callGateway(fetchImpl: typeof fetch, url: string, init: {
80
+ export declare function callGateway(fetchImpl: typeof fetch, url: string,
81
+ /** A POST with `body`; a GET (a read) without one. */
82
+ init: {
68
83
  headers: Record<string, string>;
69
- body: string;
84
+ body?: string;
70
85
  }): Promise<Record<string, unknown>>;
71
86
  /** The hosted page a customer is sent to must be a plain https address. */
72
87
  export declare function hostedPage(value: unknown): {
package/dist/gateway.js CHANGED
@@ -25,13 +25,15 @@ export function hmacMatches(secret, payload, signature) {
25
25
  * Sends a request to a gateway and returns its JSON. A failure is reported with a fixed
26
26
  * message: the gateway's own text can repeat keys and identifiers, so it is never passed on.
27
27
  */
28
- export async function callGateway(fetchImpl, url, init) {
28
+ export async function callGateway(fetchImpl, url,
29
+ /** A POST with `body`; a GET (a read) without one. */
30
+ init) {
29
31
  let response;
30
32
  try {
31
33
  response = await fetchImpl(url, {
32
- method: 'POST',
34
+ method: init.body === undefined ? 'GET' : 'POST',
33
35
  headers: init.headers,
34
- body: init.body,
36
+ ...(init.body === undefined ? {} : { body: init.body }),
35
37
  redirect: 'error',
36
38
  signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
37
39
  });
@@ -1 +1 @@
1
- {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,aAAa,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAiElE,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AACnC,iGAAiG;AACjG,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAE1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAgC,EAAE,CAChE,IAAI,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,2BAA2B,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAkB,EAAsC,EAAE,CACrF,kBAAkB,CAChB,gBAAgB,CAAC,sBAAsB,EACvC,2CAA2C,EAC3C,EAAE,SAAS,EAAE,CACd,CAAC;AAEJ,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,iBAAiB,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,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;IAC9D,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC;IACjC,CAAC,CAAC,IAAI,CAAC;AAEX,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAA2B,EAAE,CAChE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAE,KAAiC,CAAC,CAAC,CAAC,EAAE,CAAC;AAExF,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,8BAA8B,CAAC,CAAC;IAClF,CAAC;AACH,CAAC"}
@@ -1,5 +1,6 @@
1
+ import type { PriceInterval } from './contracts.js';
1
2
  import type { CheckoutInput, PaymentGateway, SubscriptionEvent } from './gateway.js';
2
- /** A monthly plan to create at Razorpay. */
3
+ /** A monthly or yearly plan to create at Razorpay. */
3
4
  export interface RazorpayPlanInput {
4
5
  /** Shown to the customer on Razorpay's page and emails, e.g. "Catalogpix Pro". */
5
6
  name: string;
@@ -7,6 +8,8 @@ export interface RazorpayPlanInput {
7
8
  currency: string;
8
9
  /** In the currency's smallest unit (paise, cents). */
9
10
  amountMinor: number;
11
+ /** How often it charges; monthly when left out. */
12
+ interval?: PriceInterval;
10
13
  notes?: Record<string, string>;
11
14
  }
12
15
  export interface RazorpayOptions {
@@ -22,18 +25,24 @@ export declare class RazorpayGateway implements PaymentGateway {
22
25
  readonly name = "razorpay";
23
26
  private readonly fetchImpl;
24
27
  constructor(options: RazorpayOptions);
25
- private post;
28
+ /** A POST with `body`; a GET without one. */
29
+ private request;
26
30
  /** Razorpay's hosted page has no return address: the customer comes back on their own. */
27
- createCheckout(input: CheckoutInput): Promise<{
31
+ createCheckout(input: CheckoutInput, now?: Date): Promise<{
28
32
  url: string;
29
33
  }>;
30
34
  readWebhook(rawBody: Buffer, headers: Record<string, string | undefined>, now?: Date): SubscriptionEvent | null;
31
35
  /**
32
- * Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
36
+ * Creates a monthly (or yearly) plan at Razorpay and returns its ID, the `priceRef` a plan's price is
33
37
  * recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
34
38
  * changes one: a new amount is a new plan. A currency the account is not enabled for is
35
39
  * refused as PAYMENT_PROVIDER_ERROR.
36
40
  */
37
41
  createPlan(input: RazorpayPlanInput): Promise<string>;
42
+ /**
43
+ * Stops renewal at the end of the cycle paid for. A subscription not charged yet (bought
44
+ * during a free trial, `authenticated` until `start_at`) has no such cycle: it is
45
+ * cancelled now, so it never charges, and its `subscription.cancelled` webhook ends the plan.
46
+ */
38
47
  cancelAtPeriodEnd(subscriptionRef: string): Promise<void>;
39
48
  }
package/dist/razorpay.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { AppError, CoreErrorCode as ErrorCode } from '@haatlabs-core/errors';
2
- import { callGateway, gatewayError, hmacMatches, hostedPage, instant, invalidSignature, parseJson, record, requireReference, text, } from './gateway.js';
2
+ import { callGateway, gatewayError, hmacMatches, hostedPage, instant, invalidSignature, MS_PER_SECOND, parseJson, record, requireReference, text, } from './gateway.js';
3
3
  const API = 'https://api.razorpay.com/v1';
4
4
  /**
5
- * Razorpay needs a fixed number of billing cycles. This is ten years of monthly cycles;
6
- * the subscription "completes" after that and the customer subscribes again.
5
+ * Razorpay needs a fixed number of billing cycles. This is ten years of them, monthly or
6
+ * yearly; the subscription "completes" after that and the customer subscribes again.
7
7
  */
8
- const BILLING_CYCLES = 120;
8
+ const BILLING_CYCLES = { MONTH: 120, YEAR: 10 };
9
+ const PERIOD = { MONTH: 'monthly', YEAR: 'yearly' };
9
10
  const PAID_UP = new Set([
10
11
  'subscription.activated',
11
12
  'subscription.charged',
@@ -19,6 +20,8 @@ const ENDED = new Set([
19
20
  'subscription.completed',
20
21
  'subscription.paused',
21
22
  ]);
23
+ /** A subscription Razorpay has not charged for yet: created, or authorised to start later. */
24
+ const NOT_STARTED = new Set(['created', 'authenticated']);
22
25
  /** Over for good; the others can still be charged or resumed. */
23
26
  const FINISHED = new Set(['subscription.cancelled', 'subscription.completed']);
24
27
  /** An ID Razorpay issues: letters, digits and underscores. */
@@ -32,22 +35,28 @@ export class RazorpayGateway {
32
35
  this.options = options;
33
36
  this.fetchImpl = options.fetch ?? fetch;
34
37
  }
35
- post(path, body) {
38
+ /** A POST with `body`; a GET without one. */
39
+ request(path, body) {
36
40
  const credentials = Buffer.from(`${this.options.keyId}:${this.options.keySecret}`);
37
41
  return callGateway(this.fetchImpl, `${API}${path}`, {
38
42
  headers: {
39
43
  Authorization: `Basic ${credentials.toString('base64')}`,
40
- 'Content-Type': 'application/json',
44
+ ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
41
45
  },
42
- body: JSON.stringify(body),
46
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
43
47
  });
44
48
  }
45
49
  /** Razorpay's hosted page has no return address: the customer comes back on their own. */
46
- async createCheckout(input) {
47
- const subscription = await this.post('/subscriptions', {
50
+ async createCheckout(input, now = new Date()) {
51
+ // Bought during a free trial: authorised today, first charged when the trial ends.
52
+ const startAt = input.trialEndsAt && input.trialEndsAt > now
53
+ ? Math.floor(input.trialEndsAt.getTime() / MS_PER_SECOND)
54
+ : null;
55
+ const subscription = await this.request('/subscriptions', {
48
56
  plan_id: input.priceRef,
49
- total_count: BILLING_CYCLES,
57
+ total_count: BILLING_CYCLES[input.interval ?? 'MONTH'],
50
58
  customer_notify: 1,
59
+ ...(startAt === null ? {} : { start_at: startAt }),
51
60
  // Returned on every webhook for the subscription: how it names the organization.
52
61
  notes: { organization_id: input.organizationId, plan_code: input.planCode },
53
62
  });
@@ -79,10 +88,14 @@ export class RazorpayGateway {
79
88
  occurredAt,
80
89
  };
81
90
  }
82
- if (!PAID_UP.has(name))
91
+ // Bought during a free trial (`start_at` still to come): authorised now, first charged
92
+ // when the trial ends. The plan is the organization's from now until then.
93
+ const startAt = instant(subscription.start_at);
94
+ const trial = name === 'subscription.authenticated' && startAt !== null && startAt > occurredAt;
95
+ if (!trial && !PAID_UP.has(name))
83
96
  return null;
84
- const periodStart = instant(subscription.current_start);
85
- const periodEnd = instant(subscription.current_end);
97
+ const periodStart = trial ? occurredAt : instant(subscription.current_start);
98
+ const periodEnd = trial ? startAt : instant(subscription.current_end);
86
99
  // Authorised but not charged yet: the charge's own event carries the period.
87
100
  if (!periodStart || !periodEnd)
88
101
  return null;
@@ -97,17 +110,18 @@ export class RazorpayGateway {
97
110
  periodStart,
98
111
  periodEnd,
99
112
  occurredAt,
113
+ ...(trial ? { trial: true } : {}),
100
114
  };
101
115
  }
102
116
  /**
103
- * Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
117
+ * Creates a monthly (or yearly) plan at Razorpay and returns its ID, the `priceRef` a plan's price is
104
118
  * recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
105
119
  * changes one: a new amount is a new plan. A currency the account is not enabled for is
106
120
  * refused as PAYMENT_PROVIDER_ERROR.
107
121
  */
108
122
  async createPlan(input) {
109
- const plan = await this.post('/plans', {
110
- period: 'monthly',
123
+ const plan = await this.request('/plans', {
124
+ period: PERIOD[input.interval ?? 'MONTH'],
111
125
  interval: 1,
112
126
  item: { name: input.name, amount: input.amountMinor, currency: input.currency },
113
127
  ...(input.notes ? { notes: input.notes } : {}),
@@ -117,10 +131,17 @@ export class RazorpayGateway {
117
131
  throw gatewayError(false);
118
132
  return id;
119
133
  }
134
+ /**
135
+ * Stops renewal at the end of the cycle paid for. A subscription not charged yet (bought
136
+ * during a free trial, `authenticated` until `start_at`) has no such cycle: it is
137
+ * cancelled now, so it never charges, and its `subscription.cancelled` webhook ends the plan.
138
+ */
120
139
  async cancelAtPeriodEnd(subscriptionRef) {
121
- await this.post(`/subscriptions/${requireReference(subscriptionRef)}/cancel`, {
122
- cancel_at_cycle_end: 1,
123
- });
140
+ const path = `/subscriptions/${requireReference(subscriptionRef)}`;
141
+ // Razorpay's own word on whether it has started, never a guess from what is on record.
142
+ const status = text((await this.request(path)).status);
143
+ const started = status === null || !NOT_STARTED.has(status);
144
+ await this.request(`${path}/cancel`, { cancel_at_cycle_end: started ? 1 : 0 });
124
145
  }
125
146
  }
126
147
  //# sourceMappingURL=razorpay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"razorpay.js","sourceRoot":"","sources":["../src/razorpay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,IAAI,GACL,MAAM,cAAc,CAAC;AAGtB,MAAM,GAAG,GAAG,6BAA6B,CAAC;AAC1C;;;GAGG;AACH,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,OAAO,GAAwB,IAAI,GAAG,CAAC;IAC3C,wBAAwB;IACxB,sBAAsB;IACtB,sBAAsB;CACvB,CAAC,CAAC;AACH,4FAA4F;AAC5F,MAAM,KAAK,GAAwB,IAAI,GAAG,CAAC;IACzC,sBAAsB;IACtB,qBAAqB;IACrB,wBAAwB;IACxB,wBAAwB;IACxB,qBAAqB;CACtB,CAAC,CAAC;AACH,iEAAiE;AACjE,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,CAAC,wBAAwB,EAAE,wBAAwB,CAAC,CAAC,CAAC;AAapG,8DAA8D;AAC9D,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAU7C,8DAA8D;AAC9D,MAAM,OAAO,eAAe;IAIG;IAHpB,IAAI,GAAG,UAAU,CAAC;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AAC,CAAC;IACjF,CAAC;CACF"}
@@ -43,13 +43,16 @@ export interface ShopifyPlanPorts {
43
43
  test: boolean;
44
44
  createdAt: Date;
45
45
  currentPeriodEnd: Date | null;
46
+ /** Shopify's `AppPricingInterval`; every 30 days when left out. */
47
+ interval?: string;
46
48
  }[]>;
47
49
  onRecord(): Promise<ShopifyPlanRecord | null>;
48
- /** The plans sold through Shopify. */
50
+ /** The plans sold through Shopify, each price monthly unless `interval` is YEAR. */
49
51
  prices(): Promise<{
50
52
  planCode: string;
51
53
  planName: string;
52
54
  priceRef: string;
55
+ interval?: string;
53
56
  }[]>;
54
57
  apply(change: ShopifyPlanChange): Promise<'applied' | 'duplicate' | 'ignored'>;
55
58
  /**
@@ -1,6 +1,18 @@
1
1
  export const SHOPIFY_PROVIDER = 'shopify';
2
2
  const PERIOD_MS = 30 * 86_400_000;
3
3
  const DECIMAL = 10;
4
+ /**
5
+ * `years` years after `from` (before it, when negative), the same day and time (UTC); from
6
+ * 29 February into a year without one, the 28th, never 1 March.
7
+ */
8
+ const yearAfter = (from, years) => {
9
+ const year = from.getUTCFullYear() + years;
10
+ const month = from.getUTCMonth();
11
+ const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
12
+ const moved = new Date(from);
13
+ moved.setUTCFullYear(year, month, Math.min(from.getUTCDate(), lastDay));
14
+ return moved;
15
+ };
4
16
  /**
5
17
  * What a merchant sees on their Shopify invoice, and how a subscription is tied to a plan:
6
18
  * the app's name, then the plan's.
@@ -52,10 +64,15 @@ export async function reconcileShopifyPlan(ports, input) {
52
64
  });
53
65
  return { state: 'ended' };
54
66
  }
55
- const plan = (await ports.prices()).find((price) => shopifySubscriptionName(input.appName, price.planName) === newest.name);
67
+ // A plan's monthly and yearly charges have the same name: how often it bills tells them apart.
68
+ const yearly = newest.interval === 'ANNUAL';
69
+ const plan = (await ports.prices()).find((price) => shopifySubscriptionName(input.appName, price.planName) === newest.name &&
70
+ (price.interval === 'YEAR') === yearly);
56
71
  if (!plan)
57
72
  return { state: 'unmatched', name: newest.name };
58
- const periodEnd = newest.currentPeriodEnd ?? new Date(newest.createdAt.getTime() + PERIOD_MS);
73
+ const periodEnd = newest.currentPeriodEnd ??
74
+ (yearly ? yearAfter(newest.createdAt, 1) : new Date(newest.createdAt.getTime() + PERIOD_MS));
75
+ const periodStart = yearly ? yearAfter(periodEnd, -1) : new Date(periodEnd.getTime() - PERIOD_MS);
59
76
  const running = ownedBy(record, input.storeRef) && record.subscriptionRef === newest.id;
60
77
  // One event for each period while the subscription simply runs on, so repeating a sync
61
78
  // changes nothing. Anything else is a start (new, changed, or back after ending) and
@@ -72,7 +89,7 @@ export async function reconcileShopifyPlan(ports, input) {
72
89
  subscriptionRef: newest.id,
73
90
  customerRef: input.storeRef,
74
91
  // Never a period that has not started: the plan would not be in force until it did.
75
- periodStart: new Date(Math.min(periodEnd.getTime() - PERIOD_MS, now.getTime())),
92
+ periodStart: new Date(Math.min(periodStart.getTime(), now.getTime())),
76
93
  periodEnd,
77
94
  occurredAt: now,
78
95
  // Shopify keeps one subscription for the app in a shop: a new one took the old one's place.
@@ -1 +1 @@
1
- {"version":3,"file":"shopify-plan.js","sourceRoot":"","sources":["../src/shopify-plan.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAC1C,MAAM,SAAS,GAAG,EAAE,GAAG,UAAU,CAAC;AAClC,MAAM,OAAO,GAAG,EAAE,CAAC;AAEnB;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,QAAgB,EAAU,EAAE,CACnF,GAAG,OAAO,IAAI,QAAQ,EAAE,CAAC;AAE3B,kGAAkG;AAClG,MAAM,UAAU,aAAa,CAAC,WAAmB,EAAE,QAAgB;IACjE,MAAM,MAAM,GACV,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,eAAe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AAE,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE;KACpC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haatlabs-core/billing",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Payment gateways (Stripe, Razorpay, manual) and Shopify plan billing behind one interface.",
5
5
  "keywords": [
6
6
  "haatlabs",
@@ -54,13 +54,13 @@
54
54
  ]
55
55
  },
56
56
  "dependencies": {
57
- "@haatlabs-core/errors": "0.21.0",
58
- "@haatlabs-core/logger": "0.21.0"
57
+ "@haatlabs-core/logger": "0.22.0",
58
+ "@haatlabs-core/errors": "0.22.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "zod": "^4.6.5",
62
- "@haatlabs-core/tsconfig": "0.21.0",
63
- "@haatlabs-core/vitest-config": "0.21.0"
62
+ "@haatlabs-core/vitest-config": "0.22.0",
63
+ "@haatlabs-core/tsconfig": "0.22.0"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "zod": "^4.6.5"