@unify-payment/node 0.0.7 → 0.0.8

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
@@ -15,9 +15,11 @@ UnifyPayment is a TypeScript package that provides a unified interface for integ
15
15
  - **LemonSqueezy:** (Checkout, Webhook) will add more functionality later.
16
16
  - **SSLCommerz:** (Checkout) will add more functionality later.
17
17
  - **PayPal:** (Checkout) will add more functionality later.
18
+ - **Bkash:** (Checkout) will add more functionality later.
19
+ - **Nagad:** (Checkout) will add more functionality later.
18
20
  - **RazorPay:** (upcoming).
21
+ - **Shopify:** (upcoming).
19
22
  - **GooglePay:** (planing).
20
- - **Shopify:** (planing).
21
23
 
22
24
  ## Installation
23
25
 
@@ -0,0 +1,383 @@
1
+ import Stripe$1, { Stripe as Stripe$2 } from 'stripe';
2
+
3
+ interface IBkashCheckoutOptions {
4
+ mode: "0011";
5
+ payerReference: string;
6
+ callbackURL: string;
7
+ amount: string;
8
+ currency: "BDT";
9
+ intent: "sale";
10
+ merchantInvoiceNumber: string;
11
+ merchantAssociationInfo?: string;
12
+ }
13
+ interface IBkashPayloadProps {
14
+ apiUrl: string;
15
+ username: string;
16
+ password: string;
17
+ app_key: string;
18
+ app_secret: string;
19
+ }
20
+
21
+ type TFetchOptions = {
22
+ method?: string;
23
+ headers?: Record<string, string>;
24
+ body?: BodyInit;
25
+ };
26
+ declare class UnifyFetch {
27
+ jsonFetch<T>(url: string, options?: TFetchOptions): Promise<[T, Response]>;
28
+ axios<T>(url: string, options?: TFetchOptions): Promise<[T, Request]>;
29
+ }
30
+
31
+ declare class Bkash extends UnifyFetch {
32
+ private options;
33
+ constructor(options: IBkashPayloadProps);
34
+ private getAppKey;
35
+ private getApiBaseUrl;
36
+ private getApiRequestHeaders;
37
+ getAccessToken(): Promise<string>;
38
+ getCheckoutUrl(options: IBkashCheckoutOptions): Promise<string>;
39
+ }
40
+
41
+ type TLemonSqueezyWebhookEvents = "order_created" | "order_refunded" | "subscription_created" | "subscription_updated" | "subscription_cancelled" | "subscription_resumed" | "subscription_expired" | "subscription_paused" | "subscription_unpaused" | "subscription_payment_success" | "subscription_payment_failed" | "subscription_payment_recovered" | "subscription_payment_refunded" | "license_key_created" | "license_key_updated";
42
+ type TWebhookEventResponse = {
43
+ error: Error;
44
+ } | {
45
+ event: ILemonSqueezyWebhookEeventResponse;
46
+ type: TLemonSqueezyWebhookEvents;
47
+ };
48
+ interface ILemonSqueezyWebhookEeventResponse {
49
+ meta: {
50
+ event_name: string;
51
+ custom_data: {
52
+ customer_id: number;
53
+ };
54
+ };
55
+ data: {
56
+ type: "orders" | "subscriptions";
57
+ id: string;
58
+ attributes: {
59
+ store_id: number;
60
+ customer_id: number;
61
+ identifier: string;
62
+ order_number: number;
63
+ user_name: string;
64
+ user_email: string;
65
+ currency: string;
66
+ currency_rate: string;
67
+ subtotal: number;
68
+ discount_total: number;
69
+ tax: number;
70
+ total: number;
71
+ subtotal_usd: number;
72
+ discount_total_usd: number;
73
+ tax_usd: number;
74
+ total_usd: number;
75
+ tax_name: string;
76
+ tax_rate: string;
77
+ status: string;
78
+ status_formatted: string;
79
+ refunded: boolean;
80
+ refunded_at: any;
81
+ subtotal_formatted: string;
82
+ discount_total_formatted: string;
83
+ tax_formatted: string;
84
+ total_formatted: string;
85
+ first_order_item: {
86
+ id: number;
87
+ order_id: number;
88
+ product_id: number;
89
+ variant_id: number;
90
+ product_name: string;
91
+ variant_name: string;
92
+ price: number;
93
+ created_at: string;
94
+ updated_at: string;
95
+ deleted_at: any;
96
+ test_mode: boolean;
97
+ };
98
+ urls: {
99
+ receipt: string;
100
+ };
101
+ created_at: string;
102
+ updated_at: string;
103
+ };
104
+ relationships: {
105
+ store: {
106
+ links: {
107
+ related: string;
108
+ self: string;
109
+ };
110
+ };
111
+ customer: {
112
+ links: {
113
+ related: string;
114
+ self: string;
115
+ };
116
+ };
117
+ "order-items": {
118
+ links: {
119
+ related: string;
120
+ self: string;
121
+ };
122
+ };
123
+ subscriptions: {
124
+ links: {
125
+ related: string;
126
+ self: string;
127
+ };
128
+ };
129
+ "license-keys": {
130
+ links: {
131
+ related: string;
132
+ self: string;
133
+ };
134
+ };
135
+ "discount-redemptions": {
136
+ links: {
137
+ related: string;
138
+ self: string;
139
+ };
140
+ };
141
+ };
142
+ links: {
143
+ self: string;
144
+ };
145
+ };
146
+ }
147
+ interface ILemonSqueezyCheckoutOptions {
148
+ type: "checkouts";
149
+ attributes?: {
150
+ custom_price?: number;
151
+ product_options?: {
152
+ redirect_url?: string;
153
+ enabled_variants?: number[];
154
+ };
155
+ checkout_options?: {
156
+ button_color: string;
157
+ };
158
+ checkout_data?: {
159
+ discount_code?: string;
160
+ custom?: {
161
+ user_id: number;
162
+ };
163
+ };
164
+ expires_at?: string;
165
+ preview?: boolean;
166
+ };
167
+ relationships: {
168
+ store: {
169
+ data: {
170
+ type: string;
171
+ id: string;
172
+ };
173
+ };
174
+ variant: {
175
+ data: {
176
+ type: string;
177
+ id: string;
178
+ };
179
+ };
180
+ };
181
+ }
182
+
183
+ declare class LemonSqueezy extends UnifyFetch {
184
+ private apiKey;
185
+ constructor(apiKey: string);
186
+ private getApiBaseUrl;
187
+ private getApiRequestHeaders;
188
+ getCheckoutUrl(options: ILemonSqueezyCheckoutOptions): Promise<string>;
189
+ verifySignature(payload: {
190
+ signature: string;
191
+ secret: string;
192
+ body: string;
193
+ x_event: string;
194
+ }): Promise<TWebhookEventResponse>;
195
+ }
196
+
197
+ interface INagadOptions {
198
+ merchant_id: string;
199
+ merchant_number: string;
200
+ private_key: string;
201
+ public_key: string;
202
+ callbackURL: string;
203
+ apiVersion: string;
204
+ is_live: boolean;
205
+ }
206
+ type INagadClientType = "PC_WEB" | "MOBILE_WEB" | "MOBILE_APP" | "WALLET_WEB_VIEW" | "BILL_KEY";
207
+ interface INagadCreatePaymentArgs {
208
+ orderId: string;
209
+ amount: string;
210
+ productDetails: Record<string, string>;
211
+ ip: string;
212
+ clientType: INagadClientType;
213
+ }
214
+
215
+ declare class Nagad extends UnifyFetch {
216
+ private options;
217
+ constructor(options: INagadOptions);
218
+ private getApiBaseUrl;
219
+ private getMerchantId;
220
+ private getMerchantNumber;
221
+ private getPrivateKey;
222
+ private getPublicKey;
223
+ private getTimeStamp;
224
+ private getCallbackUrl;
225
+ private getApiHeaders;
226
+ private createHash;
227
+ private encrypt;
228
+ private decrypt;
229
+ private sign;
230
+ private confirmPayment;
231
+ getCheckoutUrl(options: INagadCreatePaymentArgs): Promise<string>;
232
+ }
233
+
234
+ interface IPaypalOptions {
235
+ clientId: string;
236
+ clientSecret: string;
237
+ sandbox?: boolean;
238
+ }
239
+ interface IPaypalPayload {
240
+ intent: "CAPTURE";
241
+ purchase_units: {
242
+ items: {
243
+ name: string;
244
+ description: string;
245
+ quantity: number;
246
+ unit_amount: {
247
+ currency_code: "USD" | "EUR";
248
+ value: string;
249
+ };
250
+ }[];
251
+ amount: {
252
+ currency_code: "USD" | "EUR";
253
+ value: string;
254
+ breakdown: {
255
+ item_total: {
256
+ currency_code: "USD" | "EUR";
257
+ value: string;
258
+ };
259
+ };
260
+ };
261
+ }[];
262
+ application_context: {
263
+ return_url: string;
264
+ cancel_url: string;
265
+ shipping_preference?: "NO_SHIPPING";
266
+ user_action?: "PAY_NOW";
267
+ brand_name?: string;
268
+ };
269
+ }
270
+
271
+ declare class Paypal extends UnifyFetch {
272
+ private options;
273
+ constructor(options: IPaypalOptions);
274
+ private getApiBaseUrl;
275
+ private getClientId;
276
+ private getClientSecret;
277
+ private getApiCheckoutUrl;
278
+ getAccessToken(): Promise<string>;
279
+ getCheckoutUrl(payload: IPaypalPayload): Promise<string>;
280
+ }
281
+
282
+ type ISSLCommerzCreateCheckoutPayload = {
283
+ tran_id: string;
284
+ store_id: string;
285
+ store_passwd: string;
286
+ total_amount: number;
287
+ currency: "USD" | "EUR";
288
+ success_url?: string;
289
+ cancel_url?: string;
290
+ cus_name: string;
291
+ cus_email: string;
292
+ cus_add1: string;
293
+ cus_add2?: string;
294
+ cus_city: string;
295
+ cus_state: string;
296
+ cus_postcode: string;
297
+ cus_country: string;
298
+ cus_phone: string;
299
+ cus_fax?: string;
300
+ shipping_method: "NO";
301
+ product_name: string;
302
+ product_category: string;
303
+ product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
304
+ } | {
305
+ tran_id: string;
306
+ store_id: string;
307
+ store_passwd: string;
308
+ total_amount: number;
309
+ currency: "USD" | "EUR";
310
+ success_url?: string;
311
+ cancel_url?: string;
312
+ cus_name: string;
313
+ cus_email: string;
314
+ cus_add1: string;
315
+ cus_add2?: string;
316
+ cus_city: string;
317
+ cus_state: string;
318
+ cus_postcode: string;
319
+ cus_country: string;
320
+ cus_phone: string;
321
+ cus_fax?: string;
322
+ shipping_method: "YES";
323
+ ship_name: string;
324
+ ship_add1: string;
325
+ ship_add2?: string;
326
+ ship_city: string;
327
+ ship_state: string;
328
+ ship_postcode: string;
329
+ ship_country: string;
330
+ product_name: string;
331
+ product_category: string;
332
+ product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
333
+ };
334
+ type ISSLCommerzOptions = {
335
+ apiUrl: string;
336
+ store_id: string;
337
+ store_url?: string;
338
+ store_passwd: string;
339
+ };
340
+
341
+ declare class SSLCommerz extends UnifyFetch {
342
+ private options;
343
+ constructor(options: ISSLCommerzOptions);
344
+ private getApiBaseUrl;
345
+ private getApiCheckoutUrl;
346
+ private getApiValidationUrl;
347
+ private getApiRefundUrl;
348
+ private getApiRefundQueryUrl;
349
+ private getApiTransactionQueryBySessionIdUrl;
350
+ private getApiTransactionQueryByTransactionIdUrl;
351
+ private getApiHeaders;
352
+ private urlFormEncode;
353
+ getCheckoutUrl(payload: ISSLCommerzCreateCheckoutPayload): Promise<string>;
354
+ }
355
+
356
+ type TStripeWebhookEventResponse = {
357
+ error: Error;
358
+ } | {
359
+ event: Stripe$1.Event;
360
+ };
361
+
362
+ declare class Stripe {
363
+ private apiKey;
364
+ private stripe;
365
+ constructor(apiKey: string, config?: Stripe$2.StripeConfig);
366
+ getCheckoutUrl(params: Stripe$2.Checkout.SessionCreateParams): Promise<string>;
367
+ verifySignature(payload: {
368
+ signature: string;
369
+ secret: string;
370
+ body: string;
371
+ }): Promise<TStripeWebhookEventResponse>;
372
+ }
373
+
374
+ declare const UnifyPayment: {
375
+ LemonSqueezy: typeof LemonSqueezy;
376
+ Bkash: typeof Bkash;
377
+ Paypal: typeof Paypal;
378
+ SSLCommerz: typeof SSLCommerz;
379
+ Stripe: typeof Stripe;
380
+ Nagad: typeof Nagad;
381
+ };
382
+
383
+ export { UnifyPayment };
@@ -0,0 +1,383 @@
1
+ import Stripe$1, { Stripe as Stripe$2 } from 'stripe';
2
+
3
+ interface IBkashCheckoutOptions {
4
+ mode: "0011";
5
+ payerReference: string;
6
+ callbackURL: string;
7
+ amount: string;
8
+ currency: "BDT";
9
+ intent: "sale";
10
+ merchantInvoiceNumber: string;
11
+ merchantAssociationInfo?: string;
12
+ }
13
+ interface IBkashPayloadProps {
14
+ apiUrl: string;
15
+ username: string;
16
+ password: string;
17
+ app_key: string;
18
+ app_secret: string;
19
+ }
20
+
21
+ type TFetchOptions = {
22
+ method?: string;
23
+ headers?: Record<string, string>;
24
+ body?: BodyInit;
25
+ };
26
+ declare class UnifyFetch {
27
+ jsonFetch<T>(url: string, options?: TFetchOptions): Promise<[T, Response]>;
28
+ axios<T>(url: string, options?: TFetchOptions): Promise<[T, Request]>;
29
+ }
30
+
31
+ declare class Bkash extends UnifyFetch {
32
+ private options;
33
+ constructor(options: IBkashPayloadProps);
34
+ private getAppKey;
35
+ private getApiBaseUrl;
36
+ private getApiRequestHeaders;
37
+ getAccessToken(): Promise<string>;
38
+ getCheckoutUrl(options: IBkashCheckoutOptions): Promise<string>;
39
+ }
40
+
41
+ type TLemonSqueezyWebhookEvents = "order_created" | "order_refunded" | "subscription_created" | "subscription_updated" | "subscription_cancelled" | "subscription_resumed" | "subscription_expired" | "subscription_paused" | "subscription_unpaused" | "subscription_payment_success" | "subscription_payment_failed" | "subscription_payment_recovered" | "subscription_payment_refunded" | "license_key_created" | "license_key_updated";
42
+ type TWebhookEventResponse = {
43
+ error: Error;
44
+ } | {
45
+ event: ILemonSqueezyWebhookEeventResponse;
46
+ type: TLemonSqueezyWebhookEvents;
47
+ };
48
+ interface ILemonSqueezyWebhookEeventResponse {
49
+ meta: {
50
+ event_name: string;
51
+ custom_data: {
52
+ customer_id: number;
53
+ };
54
+ };
55
+ data: {
56
+ type: "orders" | "subscriptions";
57
+ id: string;
58
+ attributes: {
59
+ store_id: number;
60
+ customer_id: number;
61
+ identifier: string;
62
+ order_number: number;
63
+ user_name: string;
64
+ user_email: string;
65
+ currency: string;
66
+ currency_rate: string;
67
+ subtotal: number;
68
+ discount_total: number;
69
+ tax: number;
70
+ total: number;
71
+ subtotal_usd: number;
72
+ discount_total_usd: number;
73
+ tax_usd: number;
74
+ total_usd: number;
75
+ tax_name: string;
76
+ tax_rate: string;
77
+ status: string;
78
+ status_formatted: string;
79
+ refunded: boolean;
80
+ refunded_at: any;
81
+ subtotal_formatted: string;
82
+ discount_total_formatted: string;
83
+ tax_formatted: string;
84
+ total_formatted: string;
85
+ first_order_item: {
86
+ id: number;
87
+ order_id: number;
88
+ product_id: number;
89
+ variant_id: number;
90
+ product_name: string;
91
+ variant_name: string;
92
+ price: number;
93
+ created_at: string;
94
+ updated_at: string;
95
+ deleted_at: any;
96
+ test_mode: boolean;
97
+ };
98
+ urls: {
99
+ receipt: string;
100
+ };
101
+ created_at: string;
102
+ updated_at: string;
103
+ };
104
+ relationships: {
105
+ store: {
106
+ links: {
107
+ related: string;
108
+ self: string;
109
+ };
110
+ };
111
+ customer: {
112
+ links: {
113
+ related: string;
114
+ self: string;
115
+ };
116
+ };
117
+ "order-items": {
118
+ links: {
119
+ related: string;
120
+ self: string;
121
+ };
122
+ };
123
+ subscriptions: {
124
+ links: {
125
+ related: string;
126
+ self: string;
127
+ };
128
+ };
129
+ "license-keys": {
130
+ links: {
131
+ related: string;
132
+ self: string;
133
+ };
134
+ };
135
+ "discount-redemptions": {
136
+ links: {
137
+ related: string;
138
+ self: string;
139
+ };
140
+ };
141
+ };
142
+ links: {
143
+ self: string;
144
+ };
145
+ };
146
+ }
147
+ interface ILemonSqueezyCheckoutOptions {
148
+ type: "checkouts";
149
+ attributes?: {
150
+ custom_price?: number;
151
+ product_options?: {
152
+ redirect_url?: string;
153
+ enabled_variants?: number[];
154
+ };
155
+ checkout_options?: {
156
+ button_color: string;
157
+ };
158
+ checkout_data?: {
159
+ discount_code?: string;
160
+ custom?: {
161
+ user_id: number;
162
+ };
163
+ };
164
+ expires_at?: string;
165
+ preview?: boolean;
166
+ };
167
+ relationships: {
168
+ store: {
169
+ data: {
170
+ type: string;
171
+ id: string;
172
+ };
173
+ };
174
+ variant: {
175
+ data: {
176
+ type: string;
177
+ id: string;
178
+ };
179
+ };
180
+ };
181
+ }
182
+
183
+ declare class LemonSqueezy extends UnifyFetch {
184
+ private apiKey;
185
+ constructor(apiKey: string);
186
+ private getApiBaseUrl;
187
+ private getApiRequestHeaders;
188
+ getCheckoutUrl(options: ILemonSqueezyCheckoutOptions): Promise<string>;
189
+ verifySignature(payload: {
190
+ signature: string;
191
+ secret: string;
192
+ body: string;
193
+ x_event: string;
194
+ }): Promise<TWebhookEventResponse>;
195
+ }
196
+
197
+ interface INagadOptions {
198
+ merchant_id: string;
199
+ merchant_number: string;
200
+ private_key: string;
201
+ public_key: string;
202
+ callbackURL: string;
203
+ apiVersion: string;
204
+ is_live: boolean;
205
+ }
206
+ type INagadClientType = "PC_WEB" | "MOBILE_WEB" | "MOBILE_APP" | "WALLET_WEB_VIEW" | "BILL_KEY";
207
+ interface INagadCreatePaymentArgs {
208
+ orderId: string;
209
+ amount: string;
210
+ productDetails: Record<string, string>;
211
+ ip: string;
212
+ clientType: INagadClientType;
213
+ }
214
+
215
+ declare class Nagad extends UnifyFetch {
216
+ private options;
217
+ constructor(options: INagadOptions);
218
+ private getApiBaseUrl;
219
+ private getMerchantId;
220
+ private getMerchantNumber;
221
+ private getPrivateKey;
222
+ private getPublicKey;
223
+ private getTimeStamp;
224
+ private getCallbackUrl;
225
+ private getApiHeaders;
226
+ private createHash;
227
+ private encrypt;
228
+ private decrypt;
229
+ private sign;
230
+ private confirmPayment;
231
+ getCheckoutUrl(options: INagadCreatePaymentArgs): Promise<string>;
232
+ }
233
+
234
+ interface IPaypalOptions {
235
+ clientId: string;
236
+ clientSecret: string;
237
+ sandbox?: boolean;
238
+ }
239
+ interface IPaypalPayload {
240
+ intent: "CAPTURE";
241
+ purchase_units: {
242
+ items: {
243
+ name: string;
244
+ description: string;
245
+ quantity: number;
246
+ unit_amount: {
247
+ currency_code: "USD" | "EUR";
248
+ value: string;
249
+ };
250
+ }[];
251
+ amount: {
252
+ currency_code: "USD" | "EUR";
253
+ value: string;
254
+ breakdown: {
255
+ item_total: {
256
+ currency_code: "USD" | "EUR";
257
+ value: string;
258
+ };
259
+ };
260
+ };
261
+ }[];
262
+ application_context: {
263
+ return_url: string;
264
+ cancel_url: string;
265
+ shipping_preference?: "NO_SHIPPING";
266
+ user_action?: "PAY_NOW";
267
+ brand_name?: string;
268
+ };
269
+ }
270
+
271
+ declare class Paypal extends UnifyFetch {
272
+ private options;
273
+ constructor(options: IPaypalOptions);
274
+ private getApiBaseUrl;
275
+ private getClientId;
276
+ private getClientSecret;
277
+ private getApiCheckoutUrl;
278
+ getAccessToken(): Promise<string>;
279
+ getCheckoutUrl(payload: IPaypalPayload): Promise<string>;
280
+ }
281
+
282
+ type ISSLCommerzCreateCheckoutPayload = {
283
+ tran_id: string;
284
+ store_id: string;
285
+ store_passwd: string;
286
+ total_amount: number;
287
+ currency: "USD" | "EUR";
288
+ success_url?: string;
289
+ cancel_url?: string;
290
+ cus_name: string;
291
+ cus_email: string;
292
+ cus_add1: string;
293
+ cus_add2?: string;
294
+ cus_city: string;
295
+ cus_state: string;
296
+ cus_postcode: string;
297
+ cus_country: string;
298
+ cus_phone: string;
299
+ cus_fax?: string;
300
+ shipping_method: "NO";
301
+ product_name: string;
302
+ product_category: string;
303
+ product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
304
+ } | {
305
+ tran_id: string;
306
+ store_id: string;
307
+ store_passwd: string;
308
+ total_amount: number;
309
+ currency: "USD" | "EUR";
310
+ success_url?: string;
311
+ cancel_url?: string;
312
+ cus_name: string;
313
+ cus_email: string;
314
+ cus_add1: string;
315
+ cus_add2?: string;
316
+ cus_city: string;
317
+ cus_state: string;
318
+ cus_postcode: string;
319
+ cus_country: string;
320
+ cus_phone: string;
321
+ cus_fax?: string;
322
+ shipping_method: "YES";
323
+ ship_name: string;
324
+ ship_add1: string;
325
+ ship_add2?: string;
326
+ ship_city: string;
327
+ ship_state: string;
328
+ ship_postcode: string;
329
+ ship_country: string;
330
+ product_name: string;
331
+ product_category: string;
332
+ product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
333
+ };
334
+ type ISSLCommerzOptions = {
335
+ apiUrl: string;
336
+ store_id: string;
337
+ store_url?: string;
338
+ store_passwd: string;
339
+ };
340
+
341
+ declare class SSLCommerz extends UnifyFetch {
342
+ private options;
343
+ constructor(options: ISSLCommerzOptions);
344
+ private getApiBaseUrl;
345
+ private getApiCheckoutUrl;
346
+ private getApiValidationUrl;
347
+ private getApiRefundUrl;
348
+ private getApiRefundQueryUrl;
349
+ private getApiTransactionQueryBySessionIdUrl;
350
+ private getApiTransactionQueryByTransactionIdUrl;
351
+ private getApiHeaders;
352
+ private urlFormEncode;
353
+ getCheckoutUrl(payload: ISSLCommerzCreateCheckoutPayload): Promise<string>;
354
+ }
355
+
356
+ type TStripeWebhookEventResponse = {
357
+ error: Error;
358
+ } | {
359
+ event: Stripe$1.Event;
360
+ };
361
+
362
+ declare class Stripe {
363
+ private apiKey;
364
+ private stripe;
365
+ constructor(apiKey: string, config?: Stripe$2.StripeConfig);
366
+ getCheckoutUrl(params: Stripe$2.Checkout.SessionCreateParams): Promise<string>;
367
+ verifySignature(payload: {
368
+ signature: string;
369
+ secret: string;
370
+ body: string;
371
+ }): Promise<TStripeWebhookEventResponse>;
372
+ }
373
+
374
+ declare const UnifyPayment: {
375
+ LemonSqueezy: typeof LemonSqueezy;
376
+ Bkash: typeof Bkash;
377
+ Paypal: typeof Paypal;
378
+ SSLCommerz: typeof SSLCommerz;
379
+ Stripe: typeof Stripe;
380
+ Nagad: typeof Nagad;
381
+ };
382
+
383
+ export { UnifyPayment };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";var K=Object.create;var m=Object.defineProperty,x=Object.defineProperties,D=Object.getOwnPropertyDescriptor,$=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,P=Object.getOwnPropertySymbols,z=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var U=(s,t,e)=>t in s?m(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,y=(s,t)=>{for(var e in t||(t={}))R.call(t,e)&&U(s,e,t[e]);if(P)for(var e of P(t))M.call(t,e)&&U(s,e,t[e]);return s},T=(s,t)=>x(s,$(t));var F=(s,t)=>{for(var e in t)m(s,e,{get:t[e],enumerable:!0})},w=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of j(t))!R.call(s,a)&&a!==e&&m(s,a,{get:()=>t[a],enumerable:!(r=D(t,a))||r.enumerable});return s};var u=(s,t,e)=>(e=s!=null?K(z(s)):{},w(t||!s||!s.__esModule?m(e,"default",{value:s,enumerable:!0}):e,s)),H=s=>w(m({},"__esModule",{value:!0}),s);var i=(s,t,e)=>new Promise((r,a)=>{var n=p=>{try{c(e.next(p))}catch(l){a(l)}},h=p=>{try{c(e.throw(p))}catch(l){a(l)}},c=p=>p.done?r(p.value):Promise.resolve(p.value).then(n,h);c((e=e.apply(s,t)).next())});var L={};F(L,{UnifyPayment:()=>_});module.exports=H(L);var b=u(require("axios"));var o=class{jsonFetch(t,e){return i(this,null,function*(){let r=yield fetch(t,e);return[yield r.json(),r]})}axios(t,e){return i(this,null,function*(){let r=yield(0,b.default)({url:t,method:e==null?void 0:e.method,headers:e==null?void 0:e.headers,data:e==null?void 0:e.body});return[r.data,r.request]})}};var I=class extends o{constructor(e){super();this.options=e}getAppKey(){return this.options.app_key}getApiBaseUrl(){return this.options.apiUrl}getApiRequestHeaders(){return{"Content-Type":"application/json",Accept:"application/json",username:this.options.username,password:this.options.password}}getAccessToken(){return i(this,null,function*(){let[e]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/token/grant`,{method:"POST",headers:this.getApiRequestHeaders(),body:JSON.stringify({app_key:this.options.app_key,app_secret:this.options.app_secret})});if("errorMessage"in e)throw new Error(e.errorMessage);return e.id_token})}getCheckoutUrl(e){return i(this,null,function*(){let r=yield this.getAccessToken(),[a]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/create`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-App-Key":this.getAppKey(),Authorization:`Bearer ${r}`},body:JSON.stringify(e)});if("errorMessage"in a)throw new Error(a.errorMessage);return a.bkashURL})}};var v=class extends o{constructor(e){super();this.apiKey=e}getApiBaseUrl(){return"https://api.lemonsqueezy.com/v1"}getApiRequestHeaders(){return{Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:`Bearer ${this.apiKey}`}}getCheckoutUrl(e){return i(this,null,function*(){let[r]=yield this.jsonFetch(`${this.getApiBaseUrl()}/checkouts`,{method:"POST",body:JSON.stringify({data:e}),headers:this.getApiRequestHeaders()});if("errors"in r)throw new Error(r.errors[0].detail);return r.data.attributes.url})}verifySignature(e){return i(this,null,function*(){try{let r=new TextEncoder,a=yield crypto.subtle.importKey("raw",r.encode(e.secret),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),n=yield crypto.subtle.sign("HMAC",a,r.encode(e.body));if(Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("")!==e.signature)throw new Error("Invalid signature");return{event:JSON.parse(e.body),type:e.x_event}}catch(r){return{error:r}}})}};var A=u(require("dayjs")),B=u(require("dayjs/plugin/timezone")),E=u(require("dayjs/plugin/utc"));var g=u(require("crypto")),N=u(require("node-rsa"));var k=class extends o{constructor(e){super();this.options=e;A.default.extend(B.default),A.default.extend(E.default)}getApiBaseUrl(){return this.options.is_live?"https://api.mynagad.com/api/dfs":"http://sandbox.mynagad.com:10080/remote-payment-gateway-1.0/api/dfs"}getMerchantId(){return this.options.merchant_id}getMerchantNumber(){return this.options.merchant_number}getPrivateKey(){return this.options.private_key}getPublicKey(){return this.options.public_key}getTimeStamp(){return(0,A.default)().tz("Asia/Dhaka").format("YYYYMMDDHHmmss")}getCallbackUrl(){return this.options.callbackURL}getApiHeaders(){return{Accept:"application/json","Content-Type":"application/json","X-KM-Api-Version":this.options.apiVersion}}createHash(e){return g.default.createHash("sha1").update(e).digest("hex").toUpperCase()}encrypt(e){let r=`-----BEGIN PUBLIC KEY-----
2
+ ${this.getPublicKey()}
3
+ -----END PUBLIC KEY-----`;return g.default.publicEncrypt({key:r,padding:g.default.constants.RSA_PKCS1_PADDING},Buffer.from(JSON.stringify(e),"utf8")).toString("base64")}decrypt(e){let r=`-----BEGIN PRIVATE KEY-----
4
+ ${this.getPrivateKey()}
5
+ -----END PRIVATE KEY-----`,a=new N.default(r,"pkcs8",{encryptionScheme:"pkcs1"});a.setOptions({environment:"browser"});let n=a.decrypt(e).toString("utf8");return JSON.parse(n)}sign(e){let r=`-----BEGIN PRIVATE KEY-----
6
+ ${this.getPrivateKey()}
7
+ -----END PRIVATE KEY-----`,a=g.default.createSign("SHA256");return a.update(JSON.stringify(e)),a.end(),a.sign(r,"base64")}confirmPayment(e){return i(this,null,function*(){let r={currencyCode:"050",amount:e.amount,orderId:e.orderId,challenge:e.challenge,merchantId:this.getMerchantId()},a={signature:this.sign(r),paymentRefId:e.paymentReferenceId,sensitiveData:this.encrypt(r),merchantCallbackURL:this.getCallbackUrl(),additionalMerchantInfo:y({},e.productDetails)},[n]=yield this.axios(`${this.getApiBaseUrl()}/check-out/complete/${e.paymentReferenceId}`,{method:"POST",headers:T(y({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(a)});return n})}getCheckoutUrl(e){return i(this,null,function*(){let r=this.getTimeStamp(),a=`${this.getApiBaseUrl()}/check-out/initialize/${this.getMerchantId()}/${e.orderId}`,n={datetime:r,orderId:e.orderId,merchantId:this.getMerchantId(),challenge:this.createHash(e.orderId)},h={dateTime:r,signature:this.sign(n),sensitiveData:this.encrypt(n),accountNumber:this.getMerchantNumber()},[c]=yield this.axios(a,{method:"POST",headers:T(y({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(h)}),p=this.decrypt(c.sensitiveData);return(yield this.confirmPayment({ip:e.ip,challenge:p.challenge,amount:e.amount,orderId:e.orderId,clientType:e.clientType,paymentReferenceId:p.paymentReferenceId,productDetails:e.productDetails})).callBackUrl})}};var f=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.sandbox?"https://api-m.sandbox.paypal.com":"https://api.paypal.com"}getClientId(){return this.options.clientId}getClientSecret(){return this.options.clientSecret}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/v2/checkout/orders`}getAccessToken(){return i(this,null,function*(){let e=`${this.getApiBaseUrl()}/v1/oauth2/token`,r=btoa(`${this.getClientId()}:${this.getClientSecret()}`),[a]=yield this.jsonFetch(e,{method:"POST",headers:{Authorization:`Basic ${r}`,"Content-Type":"application/x-www-form-urlencoded"},body:"grant_type=client_credentials"});return a.access_token})}getCheckoutUrl(e){return i(this,null,function*(){var h;let r=yield this.getAccessToken(),[a]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}}),n=(h=a.links.find(c=>c.rel==="approve"))==null?void 0:h.href;if(!n)throw new Error("Failed to get checkout url");return n})}};var S=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.apiUrl}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/gwprocess/v4/api.php`}getApiValidationUrl(){return`${this.getApiBaseUrl()}/validator/api/validationserverAPI.php`}getApiRefundUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiRefundQueryUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryBySessionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryByTransactionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiHeaders(){return{"Content-Type":"application/x-www-form-urlencoded"}}urlFormEncode(e){return Object.entries(e).map(([r,a])=>`${encodeURIComponent(r)}=${encodeURIComponent(a)}`).join("&")}getCheckoutUrl(e){return i(this,null,function*(){let[r]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:this.urlFormEncode(e),headers:this.getApiHeaders()});if(r.status==="FAILED")throw new Error(r.failedreason);return r.redirectGatewayURL})}};var O=require("stripe");var C=class{constructor(t,e){this.apiKey=t;this.stripe=new O.Stripe(t,e)}getCheckoutUrl(t){return i(this,null,function*(){let e=yield this.stripe.checkout.sessions.create(t);if(!e.url)throw new Error("Failed to get checkout url");return e.url})}verifySignature(t){return i(this,null,function*(){try{return{event:yield this.stripe.webhooks.constructEventAsync(t.body,t.signature,t.secret)}}catch(e){return{error:e}}})}};var _={LemonSqueezy:v,Bkash:I,Paypal:f,SSLCommerz:S,Stripe:C,Nagad:k};0&&(module.exports={UnifyPayment});
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ var U=Object.defineProperty,R=Object.defineProperties;var w=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var P=(i,r,e)=>r in i?U(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,g=(i,r)=>{for(var e in r||(r={}))b.call(r,e)&&P(i,e,r[e]);if(T)for(var e of T(r))B.call(r,e)&&P(i,e,r[e]);return i},S=(i,r)=>R(i,w(r));var a=(i,r,e)=>new Promise((t,s)=>{var n=p=>{try{c(e.next(p))}catch(m){s(m)}},h=p=>{try{c(e.throw(p))}catch(m){s(m)}},c=p=>p.done?t(p.value):Promise.resolve(p.value).then(n,h);c((e=e.apply(i,r)).next())});import E from"axios";var o=class{jsonFetch(r,e){return a(this,null,function*(){let t=yield fetch(r,e);return[yield t.json(),t]})}axios(r,e){return a(this,null,function*(){let t=yield E({url:r,method:e==null?void 0:e.method,headers:e==null?void 0:e.headers,data:e==null?void 0:e.body});return[t.data,t.request]})}};var l=class extends o{constructor(e){super();this.options=e}getAppKey(){return this.options.app_key}getApiBaseUrl(){return this.options.apiUrl}getApiRequestHeaders(){return{"Content-Type":"application/json",Accept:"application/json",username:this.options.username,password:this.options.password}}getAccessToken(){return a(this,null,function*(){let[e]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/token/grant`,{method:"POST",headers:this.getApiRequestHeaders(),body:JSON.stringify({app_key:this.options.app_key,app_secret:this.options.app_secret})});if("errorMessage"in e)throw new Error(e.errorMessage);return e.id_token})}getCheckoutUrl(e){return a(this,null,function*(){let t=yield this.getAccessToken(),[s]=yield this.jsonFetch(`${this.getApiBaseUrl()}/tokenized/checkout/create`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-App-Key":this.getAppKey(),Authorization:`Bearer ${t}`},body:JSON.stringify(e)});if("errorMessage"in s)throw new Error(s.errorMessage);return s.bkashURL})}};var y=class extends o{constructor(e){super();this.apiKey=e}getApiBaseUrl(){return"https://api.lemonsqueezy.com/v1"}getApiRequestHeaders(){return{Accept:"application/vnd.api+json","Content-Type":"application/vnd.api+json",Authorization:`Bearer ${this.apiKey}`}}getCheckoutUrl(e){return a(this,null,function*(){let[t]=yield this.jsonFetch(`${this.getApiBaseUrl()}/checkouts`,{method:"POST",body:JSON.stringify({data:e}),headers:this.getApiRequestHeaders()});if("errors"in t)throw new Error(t.errors[0].detail);return t.data.attributes.url})}verifySignature(e){return a(this,null,function*(){try{let t=new TextEncoder,s=yield crypto.subtle.importKey("raw",t.encode(e.secret),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),n=yield crypto.subtle.sign("HMAC",s,t.encode(e.body));if(Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("")!==e.signature)throw new Error("Invalid signature");return{event:JSON.parse(e.body),type:e.x_event}}catch(t){return{error:t}}})}};import C from"dayjs";import N from"dayjs/plugin/timezone";import O from"dayjs/plugin/utc";import I from"node:crypto";import K from"node-rsa";var v=class extends o{constructor(e){super();this.options=e;C.extend(N),C.extend(O)}getApiBaseUrl(){return this.options.is_live?"https://api.mynagad.com/api/dfs":"http://sandbox.mynagad.com:10080/remote-payment-gateway-1.0/api/dfs"}getMerchantId(){return this.options.merchant_id}getMerchantNumber(){return this.options.merchant_number}getPrivateKey(){return this.options.private_key}getPublicKey(){return this.options.public_key}getTimeStamp(){return C().tz("Asia/Dhaka").format("YYYYMMDDHHmmss")}getCallbackUrl(){return this.options.callbackURL}getApiHeaders(){return{Accept:"application/json","Content-Type":"application/json","X-KM-Api-Version":this.options.apiVersion}}createHash(e){return I.createHash("sha1").update(e).digest("hex").toUpperCase()}encrypt(e){let t=`-----BEGIN PUBLIC KEY-----
2
+ ${this.getPublicKey()}
3
+ -----END PUBLIC KEY-----`;return I.publicEncrypt({key:t,padding:I.constants.RSA_PKCS1_PADDING},Buffer.from(JSON.stringify(e),"utf8")).toString("base64")}decrypt(e){let t=`-----BEGIN PRIVATE KEY-----
4
+ ${this.getPrivateKey()}
5
+ -----END PRIVATE KEY-----`,s=new K(t,"pkcs8",{encryptionScheme:"pkcs1"});s.setOptions({environment:"browser"});let n=s.decrypt(e).toString("utf8");return JSON.parse(n)}sign(e){let t=`-----BEGIN PRIVATE KEY-----
6
+ ${this.getPrivateKey()}
7
+ -----END PRIVATE KEY-----`,s=I.createSign("SHA256");return s.update(JSON.stringify(e)),s.end(),s.sign(t,"base64")}confirmPayment(e){return a(this,null,function*(){let t={currencyCode:"050",amount:e.amount,orderId:e.orderId,challenge:e.challenge,merchantId:this.getMerchantId()},s={signature:this.sign(t),paymentRefId:e.paymentReferenceId,sensitiveData:this.encrypt(t),merchantCallbackURL:this.getCallbackUrl(),additionalMerchantInfo:g({},e.productDetails)},[n]=yield this.axios(`${this.getApiBaseUrl()}/check-out/complete/${e.paymentReferenceId}`,{method:"POST",headers:S(g({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(s)});return n})}getCheckoutUrl(e){return a(this,null,function*(){let t=this.getTimeStamp(),s=`${this.getApiBaseUrl()}/check-out/initialize/${this.getMerchantId()}/${e.orderId}`,n={datetime:t,orderId:e.orderId,merchantId:this.getMerchantId(),challenge:this.createHash(e.orderId)},h={dateTime:t,signature:this.sign(n),sensitiveData:this.encrypt(n),accountNumber:this.getMerchantNumber()},[c]=yield this.axios(s,{method:"POST",headers:S(g({},this.getApiHeaders()),{"X-KM-IP-V4":e.ip,"X-KM-Client-Type":e.clientType}),body:JSON.stringify(h)}),p=this.decrypt(c.sensitiveData);return(yield this.confirmPayment({ip:e.ip,challenge:p.challenge,amount:e.amount,orderId:e.orderId,clientType:e.clientType,paymentReferenceId:p.paymentReferenceId,productDetails:e.productDetails})).callBackUrl})}};var A=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.sandbox?"https://api-m.sandbox.paypal.com":"https://api.paypal.com"}getClientId(){return this.options.clientId}getClientSecret(){return this.options.clientSecret}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/v2/checkout/orders`}getAccessToken(){return a(this,null,function*(){let e=`${this.getApiBaseUrl()}/v1/oauth2/token`,t=btoa(`${this.getClientId()}:${this.getClientSecret()}`),[s]=yield this.jsonFetch(e,{method:"POST",headers:{Authorization:`Basic ${t}`,"Content-Type":"application/x-www-form-urlencoded"},body:"grant_type=client_credentials"});return s.access_token})}getCheckoutUrl(e){return a(this,null,function*(){var h;let t=yield this.getAccessToken(),[s]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}}),n=(h=s.links.find(c=>c.rel==="approve"))==null?void 0:h.href;if(!n)throw new Error("Failed to get checkout url");return n})}};var k=class extends o{constructor(e){super();this.options=e}getApiBaseUrl(){return this.options.apiUrl}getApiCheckoutUrl(){return`${this.getApiBaseUrl()}/gwprocess/v4/api.php`}getApiValidationUrl(){return`${this.getApiBaseUrl()}/validator/api/validationserverAPI.php`}getApiRefundUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiRefundQueryUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryBySessionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiTransactionQueryByTransactionIdUrl(){return`${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`}getApiHeaders(){return{"Content-Type":"application/x-www-form-urlencoded"}}urlFormEncode(e){return Object.entries(e).map(([t,s])=>`${encodeURIComponent(t)}=${encodeURIComponent(s)}`).join("&")}getCheckoutUrl(e){return a(this,null,function*(){let[t]=yield this.jsonFetch(this.getApiCheckoutUrl(),{method:"POST",body:this.urlFormEncode(e),headers:this.getApiHeaders()});if(t.status==="FAILED")throw new Error(t.failedreason);return t.redirectGatewayURL})}};import{Stripe as x}from"stripe";var f=class{constructor(r,e){this.apiKey=r;this.stripe=new x(r,e)}getCheckoutUrl(r){return a(this,null,function*(){let e=yield this.stripe.checkout.sessions.create(r);if(!e.url)throw new Error("Failed to get checkout url");return e.url})}verifySignature(r){return a(this,null,function*(){try{return{event:yield this.stripe.webhooks.constructEventAsync(r.body,r.signature,r.secret)}}catch(e){return{error:e}}})}};var Se={LemonSqueezy:y,Bkash:l,Paypal:A,SSLCommerz:k,Stripe:f,Nagad:v};export{Se as UnifyPayment};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unify-payment/node",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.mjs",
@@ -29,6 +29,9 @@
29
29
  "repository": {
30
30
  "url": "https://github.com/shakibhasan09/unify-payment"
31
31
  },
32
+ "files": [
33
+ "dist"
34
+ ],
32
35
  "license": "ISC",
33
36
  "scripts": {
34
37
  "build": "tsup",
@@ -36,11 +39,15 @@
36
39
  },
37
40
  "devDependencies": {
38
41
  "@tsconfig/recommended": "^1.0.7",
42
+ "@types/node-rsa": "^1.1.4",
39
43
  "tsup": "^8.2.4",
40
44
  "typescript": "^5.4.5"
41
45
  },
42
46
  "dependencies": {
43
47
  "@paddle/paddle-node-sdk": "^1.5.0",
48
+ "axios": "^1.7.6",
49
+ "dayjs": "^1.11.13",
50
+ "node-rsa": "^1.1.1",
44
51
  "stripe": "^16.8.0"
45
52
  }
46
53
  }