@haatlabs-core/billing 0.13.0 → 0.15.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.
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/razorpay.d.ts +17 -0
- package/dist/cjs/razorpay.js +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/razorpay.d.ts +17 -0
- package/dist/razorpay.js +21 -1
- package/dist/razorpay.js.map +1 -1
- package/package.json +5 -5
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { CheckoutInput, GatewayName, PaymentGateway, SubscriptionEvent } fr
|
|
|
4
4
|
export { StripeGateway } from './stripe.js';
|
|
5
5
|
export type { StripeOptions } from './stripe.js';
|
|
6
6
|
export { RazorpayGateway } from './razorpay.js';
|
|
7
|
-
export type { RazorpayOptions } from './razorpay.js';
|
|
7
|
+
export type { RazorpayOptions, RazorpayPlanInput } from './razorpay.js';
|
|
8
8
|
export { SHOPIFY_PROVIDER, decimalAmount, endOwnedShopifyPlan, reconcileShopifyPlan, shopifySubscriptionName, } from './shopify-plan.js';
|
|
9
9
|
export type { ShopifyPlanChange, ShopifyPlanOutcome, ShopifyPlanPorts, ShopifyPlanRecord, } from './shopify-plan.js';
|
|
10
10
|
export { StoreBillingSync } from './store-billing-sync.js';
|
package/dist/cjs/razorpay.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { CheckoutInput, PaymentGateway, SubscriptionEvent } from './gateway.js';
|
|
2
|
+
/** A monthly plan to create at Razorpay. */
|
|
3
|
+
export interface RazorpayPlanInput {
|
|
4
|
+
/** Shown to the customer on Razorpay's page and emails, e.g. "Catalogpix Pro". */
|
|
5
|
+
name: string;
|
|
6
|
+
/** ISO 4217, upper case. */
|
|
7
|
+
currency: string;
|
|
8
|
+
/** In the currency's smallest unit (paise, cents). */
|
|
9
|
+
amountMinor: number;
|
|
10
|
+
notes?: Record<string, string>;
|
|
11
|
+
}
|
|
2
12
|
export interface RazorpayOptions {
|
|
3
13
|
keyId: string;
|
|
4
14
|
keySecret: string;
|
|
@@ -18,5 +28,12 @@ export declare class RazorpayGateway implements PaymentGateway {
|
|
|
18
28
|
url: string;
|
|
19
29
|
}>;
|
|
20
30
|
readWebhook(rawBody: Buffer, headers: Record<string, string | undefined>, now?: Date): SubscriptionEvent | null;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
|
|
33
|
+
* recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
|
|
34
|
+
* changes one: a new amount is a new plan. A currency the account is not enabled for is
|
|
35
|
+
* refused as PAYMENT_PROVIDER_ERROR.
|
|
36
|
+
*/
|
|
37
|
+
createPlan(input: RazorpayPlanInput): Promise<string>;
|
|
21
38
|
cancelAtPeriodEnd(subscriptionRef: string): Promise<void>;
|
|
22
39
|
}
|
package/dist/cjs/razorpay.js
CHANGED
|
@@ -37,6 +37,7 @@ const ENDED = /* @__PURE__ */ new Set([
|
|
|
37
37
|
"subscription.paused"
|
|
38
38
|
]);
|
|
39
39
|
const FINISHED = /* @__PURE__ */ new Set(["subscription.cancelled", "subscription.completed"]);
|
|
40
|
+
const REFERENCE_ID = /^[A-Za-z0-9_]{1,128}$/;
|
|
40
41
|
class RazorpayGateway {
|
|
41
42
|
options;
|
|
42
43
|
name = "razorpay";
|
|
@@ -111,6 +112,24 @@ class RazorpayGateway {
|
|
|
111
112
|
occurredAt
|
|
112
113
|
};
|
|
113
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
|
|
117
|
+
* recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
|
|
118
|
+
* changes one: a new amount is a new plan. A currency the account is not enabled for is
|
|
119
|
+
* refused as PAYMENT_PROVIDER_ERROR.
|
|
120
|
+
*/
|
|
121
|
+
async createPlan(input) {
|
|
122
|
+
const plan = await this.post("/plans", {
|
|
123
|
+
period: "monthly",
|
|
124
|
+
interval: 1,
|
|
125
|
+
item: { name: input.name, amount: input.amountMinor, currency: input.currency },
|
|
126
|
+
...input.notes ? { notes: input.notes } : {}
|
|
127
|
+
});
|
|
128
|
+
const id = (0, import_gateway.text)(plan.id);
|
|
129
|
+
if (!id || !REFERENCE_ID.test(id))
|
|
130
|
+
throw (0, import_gateway.gatewayError)(false);
|
|
131
|
+
return id;
|
|
132
|
+
}
|
|
114
133
|
async cancelAtPeriodEnd(subscriptionRef) {
|
|
115
134
|
await this.post(`/subscriptions/${(0, import_gateway.requireReference)(subscriptionRef)}/cancel`, {
|
|
116
135
|
cancel_at_cycle_end: 1
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { CheckoutInput, GatewayName, PaymentGateway, SubscriptionEvent } fr
|
|
|
4
4
|
export { StripeGateway } from './stripe.js';
|
|
5
5
|
export type { StripeOptions } from './stripe.js';
|
|
6
6
|
export { RazorpayGateway } from './razorpay.js';
|
|
7
|
-
export type { RazorpayOptions } from './razorpay.js';
|
|
7
|
+
export type { RazorpayOptions, RazorpayPlanInput } from './razorpay.js';
|
|
8
8
|
export { SHOPIFY_PROVIDER, decimalAmount, endOwnedShopifyPlan, reconcileShopifyPlan, shopifySubscriptionName, } from './shopify-plan.js';
|
|
9
9
|
export type { ShopifyPlanChange, ShopifyPlanOutcome, ShopifyPlanPorts, ShopifyPlanRecord, } from './shopify-plan.js';
|
|
10
10
|
export { StoreBillingSync } from './store-billing-sync.js';
|
package/dist/razorpay.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { CheckoutInput, PaymentGateway, SubscriptionEvent } from './gateway.js';
|
|
2
|
+
/** A monthly plan to create at Razorpay. */
|
|
3
|
+
export interface RazorpayPlanInput {
|
|
4
|
+
/** Shown to the customer on Razorpay's page and emails, e.g. "Catalogpix Pro". */
|
|
5
|
+
name: string;
|
|
6
|
+
/** ISO 4217, upper case. */
|
|
7
|
+
currency: string;
|
|
8
|
+
/** In the currency's smallest unit (paise, cents). */
|
|
9
|
+
amountMinor: number;
|
|
10
|
+
notes?: Record<string, string>;
|
|
11
|
+
}
|
|
2
12
|
export interface RazorpayOptions {
|
|
3
13
|
keyId: string;
|
|
4
14
|
keySecret: string;
|
|
@@ -18,5 +28,12 @@ export declare class RazorpayGateway implements PaymentGateway {
|
|
|
18
28
|
url: string;
|
|
19
29
|
}>;
|
|
20
30
|
readWebhook(rawBody: Buffer, headers: Record<string, string | undefined>, now?: Date): SubscriptionEvent | null;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
|
|
33
|
+
* recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
|
|
34
|
+
* changes one: a new amount is a new plan. A currency the account is not enabled for is
|
|
35
|
+
* refused as PAYMENT_PROVIDER_ERROR.
|
|
36
|
+
*/
|
|
37
|
+
createPlan(input: RazorpayPlanInput): Promise<string>;
|
|
21
38
|
cancelAtPeriodEnd(subscriptionRef: string): Promise<void>;
|
|
22
39
|
}
|
package/dist/razorpay.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AppError, CoreErrorCode as ErrorCode } from '@haatlabs-core/errors';
|
|
2
|
-
import { callGateway, hmacMatches, hostedPage, instant, invalidSignature, parseJson, record, requireReference, text, } from './gateway.js';
|
|
2
|
+
import { callGateway, gatewayError, hmacMatches, hostedPage, instant, invalidSignature, parseJson, record, requireReference, text, } from './gateway.js';
|
|
3
3
|
const API = 'https://api.razorpay.com/v1';
|
|
4
4
|
/**
|
|
5
5
|
* Razorpay needs a fixed number of billing cycles. This is ten years of monthly cycles;
|
|
@@ -21,6 +21,8 @@ const ENDED = new Set([
|
|
|
21
21
|
]);
|
|
22
22
|
/** Over for good; the others can still be charged or resumed. */
|
|
23
23
|
const FINISHED = new Set(['subscription.cancelled', 'subscription.completed']);
|
|
24
|
+
/** An ID Razorpay issues: letters, digits and underscores. */
|
|
25
|
+
const REFERENCE_ID = /^[A-Za-z0-9_]{1,128}$/;
|
|
24
26
|
/** Razorpay Subscriptions through its hosted payment page. */
|
|
25
27
|
export class RazorpayGateway {
|
|
26
28
|
options;
|
|
@@ -97,6 +99,24 @@ export class RazorpayGateway {
|
|
|
97
99
|
occurredAt,
|
|
98
100
|
};
|
|
99
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a monthly plan at Razorpay and returns its ID, the `priceRef` a plan's price is
|
|
104
|
+
* recorded with. A plan is made in the mode of the keys (Test or Live), and Razorpay never
|
|
105
|
+
* changes one: a new amount is a new plan. A currency the account is not enabled for is
|
|
106
|
+
* refused as PAYMENT_PROVIDER_ERROR.
|
|
107
|
+
*/
|
|
108
|
+
async createPlan(input) {
|
|
109
|
+
const plan = await this.post('/plans', {
|
|
110
|
+
period: 'monthly',
|
|
111
|
+
interval: 1,
|
|
112
|
+
item: { name: input.name, amount: input.amountMinor, currency: input.currency },
|
|
113
|
+
...(input.notes ? { notes: input.notes } : {}),
|
|
114
|
+
});
|
|
115
|
+
const id = text(plan.id);
|
|
116
|
+
if (!id || !REFERENCE_ID.test(id))
|
|
117
|
+
throw gatewayError(false);
|
|
118
|
+
return id;
|
|
119
|
+
}
|
|
100
120
|
async cancelAtPeriodEnd(subscriptionRef) {
|
|
101
121
|
await this.post(`/subscriptions/${requireReference(subscriptionRef)}/cancel`, {
|
|
102
122
|
cancel_at_cycle_end: 1,
|
package/dist/razorpay.js.map
CHANGED
|
@@ -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,WAAW,EACX,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,IAAI,GACL,MAAM,cAAc,C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,CAAC,eAAe,CAAC,SAAS,EAAE;YAC5E,mBAAmB,EAAE,CAAC;SACvB,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haatlabs-core/billing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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.
|
|
58
|
-
"@haatlabs-core/logger": "0.
|
|
57
|
+
"@haatlabs-core/errors": "0.15.0",
|
|
58
|
+
"@haatlabs-core/logger": "0.15.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"zod": "^4.6.5",
|
|
62
|
-
"@haatlabs-core/vitest-config": "0.
|
|
63
|
-
"@haatlabs-core/tsconfig": "0.
|
|
62
|
+
"@haatlabs-core/vitest-config": "0.15.0",
|
|
63
|
+
"@haatlabs-core/tsconfig": "0.15.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"zod": "^4.6.5"
|