@alexasomba/better-auth-paystack 1.1.0 → 1.2.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/README.md +22 -2
- package/dist/client.d.mts +33 -1
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +15 -0
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +166 -89
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +539 -108
- package/dist/index.mjs.map +1 -1
- package/dist/{types-BVSLYZGY.d.mts → types-BOpjdQrr.d.mts} +63 -16
- package/dist/types-BOpjdQrr.d.mts.map +1 -0
- package/package.json +13 -13
- package/dist/types-BVSLYZGY.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,9 @@ A TypeScript-first plugin that integrates Paystack into [Better Auth](https://ww
|
|
|
10
10
|
- [x] **Auto Customer Creation**: Optional Paystack customer creation on user sign up or organization creation.
|
|
11
11
|
- [x] **Trial Management**: Configurable trial periods with built-in abuse prevention logic.
|
|
12
12
|
- [x] **Organization Billing**: Associate subscriptions with organizations and authorize access via roles.
|
|
13
|
-
- [x] **Enforced Limits**: Automatic enforcement of seat
|
|
13
|
+
- [x] **Enforced Limits & Seats**: Automatic enforcement of member seat upgrades and resource limits (teams).
|
|
14
|
+
- [x] **Scheduled Changes**: Defer subscription updates or cancellations to the end of the billing cycle.
|
|
15
|
+
- [x] **Proration**: Immediate mid-cycle prorated charges for seat and plan upgrades.
|
|
14
16
|
- [x] **Popup Modal Flow**: Optional support for Paystack's inline checkout experience via `@alexasomba/paystack-browser`.
|
|
15
17
|
- [x] **Webhook Security**: Pre-configured signature verification (HMAC-SHA512).
|
|
16
18
|
- [x] **Transaction History**: Built-in support for listing and viewing local transaction records.
|
|
@@ -207,6 +209,25 @@ if (data?.accessCode) {
|
|
|
207
209
|
}
|
|
208
210
|
```
|
|
209
211
|
|
|
212
|
+
### Scheduled Changes & Cancellation
|
|
213
|
+
|
|
214
|
+
Defer changes to the end of the current billing cycle:
|
|
215
|
+
- **Upgrades**: Pass `scheduleAtPeriodEnd: true` in `initializeTransaction()`.
|
|
216
|
+
- **Cancellations**: Use `authClient.subscription.cancel({ atPeriodEnd: true })` to keep the subscription active until the period ends.
|
|
217
|
+
|
|
218
|
+
### Mid-Cycle Proration (`prorateAndCharge`)
|
|
219
|
+
|
|
220
|
+
The plugin can dynamically calculate the cost difference for immediate mid-cycle upgrades (like adding more seats).
|
|
221
|
+
If the user has a saved Paystack authorization code, the plugin will execute a prorated charge for the remaining cycle days and immediately sync the new amount/seats.
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
await authClient.paystack.transaction.initialize({
|
|
225
|
+
plan: "pro",
|
|
226
|
+
quantity: 5, // Upgrading seats
|
|
227
|
+
prorateAndCharge: true, // Will calculate and charge the prorated amount instantly
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
210
231
|
### Trial Abuse Prevention
|
|
211
232
|
|
|
212
233
|
The plugin checks the `referenceId` history. If a trial was ever used (active, expired, or trialing), it will not be granted again, preventing resubscribe-abuse.
|
|
@@ -514,7 +535,6 @@ Future features planned for upcoming versions:
|
|
|
514
535
|
### Future Considerations
|
|
515
536
|
|
|
516
537
|
- [ ] Multi-currency support improvements
|
|
517
|
-
- [ ] Proration for plan upgrades/downgrades
|
|
518
538
|
- [ ] Invoice generation
|
|
519
539
|
- [ ] Payment retry logic for failed renewals
|
|
520
540
|
|
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as PaystackTransaction, s as Subscription } from "./types-
|
|
1
|
+
import { a as PaystackProduct, o as PaystackTransaction, s as Subscription } from "./types-BOpjdQrr.mjs";
|
|
2
2
|
import { paystack } from "./index.mjs";
|
|
3
3
|
import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
4
4
|
|
|
@@ -25,6 +25,9 @@ declare const paystackClient: <O extends {
|
|
|
25
25
|
quantity?: number;
|
|
26
26
|
referenceId?: string;
|
|
27
27
|
product?: string;
|
|
28
|
+
scheduleAtPeriodEnd?: boolean;
|
|
29
|
+
cancelAtPeriodEnd?: boolean;
|
|
30
|
+
prorateAndCharge?: boolean;
|
|
28
31
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
29
32
|
url: string;
|
|
30
33
|
reference: string;
|
|
@@ -46,6 +49,9 @@ declare const paystackClient: <O extends {
|
|
|
46
49
|
quantity?: number;
|
|
47
50
|
referenceId?: string;
|
|
48
51
|
product?: string;
|
|
52
|
+
scheduleAtPeriodEnd?: boolean;
|
|
53
|
+
cancelAtPeriodEnd?: boolean;
|
|
54
|
+
prorateAndCharge?: boolean;
|
|
49
55
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
50
56
|
url: string;
|
|
51
57
|
reference: string;
|
|
@@ -58,6 +64,7 @@ declare const paystackClient: <O extends {
|
|
|
58
64
|
cancel: (data: {
|
|
59
65
|
subscriptionCode: string;
|
|
60
66
|
emailToken?: string;
|
|
67
|
+
atPeriodEnd?: boolean;
|
|
61
68
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
62
69
|
status: string;
|
|
63
70
|
}>>;
|
|
@@ -102,6 +109,7 @@ declare const paystackClient: <O extends {
|
|
|
102
109
|
disable: (data: {
|
|
103
110
|
subscriptionCode: string;
|
|
104
111
|
emailToken?: string;
|
|
112
|
+
atPeriodEnd?: boolean;
|
|
105
113
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
106
114
|
status: string;
|
|
107
115
|
}>>;
|
|
@@ -126,6 +134,9 @@ declare const paystackClient: <O extends {
|
|
|
126
134
|
quantity?: number;
|
|
127
135
|
referenceId?: string;
|
|
128
136
|
product?: string;
|
|
137
|
+
scheduleAtPeriodEnd?: boolean;
|
|
138
|
+
cancelAtPeriodEnd?: boolean;
|
|
139
|
+
prorateAndCharge?: boolean;
|
|
129
140
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
130
141
|
url: string;
|
|
131
142
|
reference: string;
|
|
@@ -158,6 +169,9 @@ declare const paystackClient: <O extends {
|
|
|
158
169
|
quantity?: number;
|
|
159
170
|
referenceId?: string;
|
|
160
171
|
product?: string;
|
|
172
|
+
scheduleAtPeriodEnd?: boolean;
|
|
173
|
+
cancelAtPeriodEnd?: boolean;
|
|
174
|
+
prorateAndCharge?: boolean;
|
|
161
175
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
162
176
|
url: string;
|
|
163
177
|
reference: string;
|
|
@@ -176,6 +190,9 @@ declare const paystackClient: <O extends {
|
|
|
176
190
|
quantity?: number;
|
|
177
191
|
referenceId?: string;
|
|
178
192
|
product?: string;
|
|
193
|
+
scheduleAtPeriodEnd?: boolean;
|
|
194
|
+
cancelAtPeriodEnd?: boolean;
|
|
195
|
+
prorateAndCharge?: boolean;
|
|
179
196
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
180
197
|
url: string;
|
|
181
198
|
reference: string;
|
|
@@ -185,6 +202,7 @@ declare const paystackClient: <O extends {
|
|
|
185
202
|
cancel: (data: {
|
|
186
203
|
subscriptionCode: string;
|
|
187
204
|
emailToken?: string;
|
|
205
|
+
atPeriodEnd?: boolean;
|
|
188
206
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
189
207
|
status: string;
|
|
190
208
|
}>>;
|
|
@@ -217,6 +235,7 @@ declare const paystackClient: <O extends {
|
|
|
217
235
|
disable: (data: {
|
|
218
236
|
subscriptionCode: string;
|
|
219
237
|
emailToken?: string;
|
|
238
|
+
atPeriodEnd?: boolean;
|
|
220
239
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
221
240
|
status: string;
|
|
222
241
|
}>>;
|
|
@@ -239,6 +258,9 @@ declare const paystackClient: <O extends {
|
|
|
239
258
|
quantity?: number;
|
|
240
259
|
referenceId?: string;
|
|
241
260
|
product?: string;
|
|
261
|
+
scheduleAtPeriodEnd?: boolean;
|
|
262
|
+
cancelAtPeriodEnd?: boolean;
|
|
263
|
+
prorateAndCharge?: boolean;
|
|
242
264
|
}, options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
243
265
|
url: string;
|
|
244
266
|
reference: string;
|
|
@@ -272,6 +294,16 @@ declare const paystackClient: <O extends {
|
|
|
272
294
|
status: string;
|
|
273
295
|
count: number;
|
|
274
296
|
}>>;
|
|
297
|
+
syncPlans: () => Promise<BetterFetchResponse<{
|
|
298
|
+
status: string;
|
|
299
|
+
count: number;
|
|
300
|
+
}>>;
|
|
301
|
+
listProducts: (options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
302
|
+
products: PaystackProduct[];
|
|
303
|
+
}>>;
|
|
304
|
+
listPlans: (options?: BetterFetchOption) => Promise<BetterFetchResponse<{
|
|
305
|
+
plans: unknown[];
|
|
306
|
+
}>>;
|
|
275
307
|
};
|
|
276
308
|
};
|
|
277
309
|
};
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;cAOa,cAAA;EAEX,YAAA;AAAA,GAGA,QAAA,GAAW,CAAA;;sBAIe,UAAA,QAAkB,QAAA;uBACvB,WAAA;;MADK;;;;QAGxB,IAAA;QACA,KAAA;QACA,MAAA;QACA,SAAA;QACA,QAAA,GAAW,MAAA;QACX,WAAA;QACA,WAAA;QACA,QAAA;QACA,QAAA;QACA,WAAA;QACA,OAAA;MAAA,GACA,OAAA,GAAY,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QACxC,GAAA;QACA,SAAA;QACA,UAAA;QACA,QAAA;MAAA;
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;cAOa,cAAA;EAEX,YAAA;AAAA,GAGA,QAAA,GAAW,CAAA;;sBAIe,UAAA,QAAkB,QAAA;uBACvB,WAAA;;MADK;;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AAA;;QAcwC,SAAA;MAAA,GAAmB,OAAA,GAAY,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QACnG,MAAA;QACA,SAAA;QACA,IAAA;MAAA;;QAauC,KAAA,GAAQ,MAAA;MAAA,GAAyB,OAAA,GAAiB,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QACrH,YAAA,EAAc,mBAAA;MAAA;;QAW0B,KAAA,GAAQ,MAAA;MAAA,GAAyB,OAAA,GAAiB,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QACtH,aAAA,EAAe,YAAA;MAAA;;QAWiC,gBAAA;MAAA,GAA0B,OAAA,GAAY,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QAClH,IAAA;MAAA;uBAmGsB,OAAA,CAAQ,mBAAA,CAAoB,MAAA;0BAKzB,OAAA,CAAQ,mBAAA;QAAsB,MAAA;QAAgB,KAAA;MAAA;uBAKjD,OAAA,CAAQ,mBAAA;QAAsB,MAAA;QAAgB,KAAA;MAAA;+BAKpC,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QAC1D,QAAA,EAAU,eAAA;MAAA;4BASiB,iBAAA,KAAoB,OAAA,CAAQ,mBAAA;QACvD,KAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/dist/client.mjs
CHANGED
|
@@ -94,6 +94,21 @@ const paystackClient = (_options) => {
|
|
|
94
94
|
},
|
|
95
95
|
syncProducts: async () => {
|
|
96
96
|
return $fetch("paystack/sync-products", { method: "POST" });
|
|
97
|
+
},
|
|
98
|
+
syncPlans: async () => {
|
|
99
|
+
return $fetch("paystack/sync-plans", { method: "POST" });
|
|
100
|
+
},
|
|
101
|
+
listProducts: async (options) => {
|
|
102
|
+
return $fetch("paystack/list-products", {
|
|
103
|
+
method: "GET",
|
|
104
|
+
...options
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
listPlans: async (options) => {
|
|
108
|
+
return $fetch("paystack/list-plans", {
|
|
109
|
+
method: "GET",
|
|
110
|
+
...options
|
|
111
|
+
});
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
114
|
};
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth\";\nimport type { BetterFetchResponse, BetterFetchOption, BetterFetch } from \"@better-fetch/fetch\";\n\nimport type { PaystackTransaction, Subscription } from \"./types\";\n\nimport type { paystack } from \"./index\";\n\nexport const paystackClient = <\n\tO extends {\n\t\tsubscription: boolean;\n\t},\n>(\n\t\t_options?: O,\n\t) => {\n\treturn {\n\t\tid: \"paystack\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof paystack>,\n\t\tgetActions: ($fetch: BetterFetch) => {\n\t\t\tconst initializeTransaction = async (data: {\n\t\t\t\tplan?: string;\n\t\t\t\temail?: string;\n\t\t\t\tamount?: number;\n\t\t\t\treference?: string;\n\t\t\t\tmetadata?: Record<string, unknown>;\n\t\t\t\tcallbackUrl?: string;\n\t\t\t\tcallbackURL?: string;\n\t\t\t\tcurrency?: string;\n\t\t\t\tquantity?: number;\n\t\t\t\treferenceId?: string;\n\t\t\t\tproduct?: string;\n\t\t\t}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\turl: string;\n\t\t\t\treference: string;\n\t\t\t\taccessCode: string;\n\t\t\t\tredirect: boolean;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\turl: string;\n\t\t\t\t\treference: string;\n\t\t\t\t\taccessCode: string;\n\t\t\t\t\tredirect: boolean;\n\t\t\t\t}>(\"paystack/initialize-transaction\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst verifyTransaction = async (data: { reference: string }, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tstatus: string;\n\t\t\t\treference: string;\n\t\t\t\tdata: unknown;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tstatus: string;\n\t\t\t\t\treference: string;\n\t\t\t\t\tdata: unknown;\n\t\t\t\t}>(\"paystack/verify-transaction\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst listTransactions = async (data: { query?: Record<string, unknown> } = {}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\ttransactions: PaystackTransaction[];\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\ttransactions: PaystackTransaction[];\n\t\t\t\t}>(\"paystack/list-transactions\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: data.query,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst listSubscriptions = async (data: { query?: Record<string, unknown> } = {}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tsubscriptions: Subscription[];\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tsubscriptions: Subscription[];\n\t\t\t\t}>(\"paystack/list-subscriptions\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: data.query,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst getSubscriptionManageLink = async (data: { subscriptionCode: string }, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tlink: string;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tlink: string;\n\t\t\t\t}>(\"paystack/get-subscription-manage-link\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst cancelSubscription = async (data: {\n\t\t\t\tsubscriptionCode: string;\n\t\t\t\temailToken?: string;\n\t\t\t}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tstatus: string;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tstatus: string;\n\t\t\t\t}>(\"paystack/disable-subscription\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst restoreSubscription = async (data: {\n\t\t\t\tsubscriptionCode: string;\n\t\t\t\temailToken?: string;\n\t\t\t}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tstatus: string;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tstatus: string;\n\t\t\t\t}>(\"paystack/enable-subscription\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tsubscription: {\n\t\t\t\t\t/**\n
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth\";\nimport type { BetterFetchResponse, BetterFetchOption, BetterFetch } from \"@better-fetch/fetch\";\n\nimport type { PaystackProduct, PaystackTransaction, Subscription } from \"./types\";\n\nimport type { paystack } from \"./index\";\n\nexport const paystackClient = <\n\tO extends {\n\t\tsubscription: boolean;\n\t},\n>(\n\t\t_options?: O,\n\t) => {\n\treturn {\n\t\tid: \"paystack\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof paystack>,\n\t\tgetActions: ($fetch: BetterFetch) => {\n\t\t\tconst initializeTransaction = async (data: {\n\t\t\t\tplan?: string;\n\t\t\t\temail?: string;\n\t\t\t\tamount?: number;\n\t\t\t\treference?: string;\n\t\t\t\tmetadata?: Record<string, unknown>;\n\t\t\t\tcallbackUrl?: string;\n\t\t\t\tcallbackURL?: string;\n\t\t\t\tcurrency?: string;\n\t\t\t\tquantity?: number;\n\t\t\t\treferenceId?: string;\n\t\t\t\tproduct?: string;\n\t\t\t\tscheduleAtPeriodEnd?: boolean;\n\t\t\t\tcancelAtPeriodEnd?: boolean;\n\t\t\t\tprorateAndCharge?: boolean;\n\t\t\t}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\turl: string;\n\t\t\t\treference: string;\n\t\t\t\taccessCode: string;\n\t\t\t\tredirect: boolean;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\turl: string;\n\t\t\t\t\treference: string;\n\t\t\t\t\taccessCode: string;\n\t\t\t\t\tredirect: boolean;\n\t\t\t\t}>(\"paystack/initialize-transaction\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst verifyTransaction = async (data: { reference: string }, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tstatus: string;\n\t\t\t\treference: string;\n\t\t\t\tdata: unknown;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tstatus: string;\n\t\t\t\t\treference: string;\n\t\t\t\t\tdata: unknown;\n\t\t\t\t}>(\"paystack/verify-transaction\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst listTransactions = async (data: { query?: Record<string, unknown> } = {}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\ttransactions: PaystackTransaction[];\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\ttransactions: PaystackTransaction[];\n\t\t\t\t}>(\"paystack/list-transactions\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: data.query,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst listSubscriptions = async (data: { query?: Record<string, unknown> } = {}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tsubscriptions: Subscription[];\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tsubscriptions: Subscription[];\n\t\t\t\t}>(\"paystack/list-subscriptions\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: data.query,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst getSubscriptionManageLink = async (data: { subscriptionCode: string }, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tlink: string;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tlink: string;\n\t\t\t\t}>(\"paystack/get-subscription-manage-link\", {\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tquery: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst cancelSubscription = async (data: {\n\t\t\t\tsubscriptionCode: string;\n\t\t\t\temailToken?: string;\n\t\t\t\tatPeriodEnd?: boolean;\n\t\t\t}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tstatus: string;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tstatus: string;\n\t\t\t\t}>(\"paystack/disable-subscription\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst restoreSubscription = async (data: {\n\t\t\t\tsubscriptionCode: string;\n\t\t\t\temailToken?: string;\n\t\t\t}, options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\tstatus: string;\n\t\t\t}>> => {\n\t\t\t\treturn $fetch<{\n\t\t\t\t\tstatus: string;\n\t\t\t\t}>(\"paystack/enable-subscription\", {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\tbody: data,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tsubscription: {\n\t\t\t\t\t/**\n\t\t\t\t\t * Initialize a transaction to upgrade or creating a subscription.\n\t\t\t\t\t */\n\t\t\t\t\tupgrade: initializeTransaction,\n\t\t\t\t\t/**\n\t\t\t\t\t * Initialize a payment to create a subscription.\n\t\t\t\t\t */\n\t\t\t\t\tcreate: initializeTransaction,\n\t\t\t\t\t/**\n\t\t\t\t\t * Disable a subscription.\n\t\t\t\t\t */\n\t\t\t\t\tcancel: cancelSubscription,\n\t\t\t\t\t/**\n\t\t\t\t\t * Enable a subscription.\n\t\t\t\t\t */\n\t\t\t\t\trestore: restoreSubscription,\n\t\t\t\t\t/**\n\t\t\t\t\t * List subscriptions for the user.\n\t\t\t\t\t */\n\t\t\t\t\tlist: listSubscriptions,\n\t\t\t\t\t/**\n\t\t\t\t\t * Get a link to manage the subscription on Paystack.\n\t\t\t\t\t */\n\t\t\t\t\tbillingPortal: getSubscriptionManageLink,\n\t\t\t\t\t/**\n\t\t\t\t\t * Aliases for legacy/demo usage.\n\t\t\t\t\t */\n\t\t\t\t\tlistLocal: listSubscriptions,\n\t\t\t\t\tmanageLink: getSubscriptionManageLink,\n\t\t\t\t\tdisable: cancelSubscription,\n\t\t\t\t\tenable: restoreSubscription,\n\t\t\t\t},\n\t\t\t\tpaystack: {\n\t\t\t\t\ttransaction: {\n\t\t\t\t\t\tinitialize: initializeTransaction,\n\t\t\t\t\t\tverify: verifyTransaction,\n\t\t\t\t\t\tlist: listTransactions,\n\t\t\t\t\t},\n\t\t\t\t\tsubscription: {\n\t\t\t\t\t\tcreate: initializeTransaction,\n\t\t\t\t\t\tupgrade: initializeTransaction,\n\t\t\t\t\t\tcancel: cancelSubscription,\n\t\t\t\t\t\trestore: restoreSubscription,\n\t\t\t\t\t\tlist: listSubscriptions,\n\t\t\t\t\t\tbillingPortal: getSubscriptionManageLink,\n\t\t\t\t\t\tlistLocal: listSubscriptions,\n\t\t\t\t\t\tmanageLink: getSubscriptionManageLink,\n\t\t\t\t\t\tdisable: cancelSubscription,\n\t\t\t\t\t\tenable: restoreSubscription,\n\t\t\t\t\t},\n\t\t\t\t\tinitializeTransaction,\n\t\t\t\t\tverifyTransaction,\n\t\t\t\t\tlistTransactions,\n\t\t\t\t\tlistSubscriptions,\n\t\t\t\t\tgetSubscriptionManageLink,\n\t\t\t\t\tgetConfig: async (): Promise<BetterFetchResponse<Record<string, unknown>>> => {\n\t\t\t\t\t\treturn $fetch<Record<string, unknown>>(\"paystack/get-config\", {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tsyncProducts: async (): Promise<BetterFetchResponse<{ status: string; count: number }>> => {\n\t\t\t\t\t\treturn $fetch<{ status: string; count: number }>(\"paystack/sync-products\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tsyncPlans: async (): Promise<BetterFetchResponse<{ status: string; count: number }>> => {\n\t\t\t\t\t\treturn $fetch<{ status: string; count: number }>(\"paystack/sync-plans\", {\n\t\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tlistProducts: async (options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\t\t\tproducts: PaystackProduct[];\n\t\t\t\t\t}>> => {\n\t\t\t\t\t\treturn $fetch<{\n\t\t\t\t\t\t\tproducts: PaystackProduct[];\n\t\t\t\t\t\t}>(\"paystack/list-products\", {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t\t...options,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\tlistPlans: async (options?: BetterFetchOption): Promise<BetterFetchResponse<{\n\t\t\t\t\t\tplans: unknown[];\n\t\t\t\t\t}>> => {\n\t\t\t\t\t\treturn $fetch<{\n\t\t\t\t\t\t\tplans: unknown[];\n\t\t\t\t\t\t}>(\"paystack/list-plans\", {\n\t\t\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\t\t\t...options,\n\t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