@unify-payment/node 0.0.4 → 0.0.6

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
@@ -13,9 +13,8 @@ UnifyPayment is a TypeScript package that provides a unified interface for integ
13
13
 
14
14
  - **Stripe:** (Checkout, Webhook) will add more functionality later.
15
15
  - **LemonSqueezy:** (Checkout, Webhook) will add more functionality later.
16
- - **Paddle:** (Checkout, Webhook) will add more functionality later.
17
16
  - **SSLCommerz:** (Checkout) will add more functionality later.
18
- - **PayPal:** (upcoming).
17
+ - **PayPal:** (Checkout) will add more functionality later.
19
18
  - **RazorPay:** (upcoming).
20
19
  - **GooglePay:** (planing).
21
20
  - **Shopify:** (planing).
@@ -32,30 +31,36 @@ npm install @unify-payment/node
32
31
 
33
32
  ```typescript
34
33
  // Stripe
35
- const unify = new UnifyPayment({
36
- stripe: new Stripe(process.env.STRIPE_API_SECRET_KEY!),
37
- });
38
- const redirect = await unify.stripe.getCheckoutUrl(stripePayload);
34
+ const stripe = new UnifyPayment.Stripe(process.env.STRIPE_SECRET_KEY!);
35
+ const redirect = await stripe.getCheckoutUrl(stripePayload);
39
36
 
40
37
  // LemonSqueezy
41
- const unify = new UnifyPayment({
42
- lemonsqueezy: new LemonSqueezy(process.env.LEMON_SECRET_KEY!),
38
+ const lemon = new UnifyPayment.LemonSqueezy(process.env.LEMON_SECRET_KEY!);
39
+ const redirect = await lemon.getCheckoutUrl(lemonsqueezyPayload);
40
+
41
+ // Paypal
42
+ const paypal = new UnifyPayment.Paypal(process.env.PAYPAL_SECRET_KEY!);
43
+ const redirect = await paypal.getCheckoutUrl(lemonsqueezyPayload);
44
+
45
+ // SSLCommerz
46
+ const ssl = new UnifyPayment.SSLCommerz({
47
+ apiUrl: process.env.SSLCOMMERZ_API_URL!,
48
+ store_id: process.env.SSLCOMMERZ_STORE_ID!,
49
+ store_passwd: process.env.SSLCOMMERZ_SECRET_KEY!,
43
50
  });
44
- const redirect = await unify.lemonsqueezy.getCheckoutUrl(lemonsqueezyPayload);
51
+ const redirect = await ssl.getCheckoutUrl(sslCommerzPayload);
45
52
  ```
46
53
 
47
54
  ## Webhook
48
55
 
49
56
  ```typescript
50
57
  // Stripe
51
- const unify = new UnifyPayment({
52
- stripe: new Stripe(stripeKey),
53
- });
58
+ const stripe = new UnifyPayment.Stripe(process.env.STRIPE_SECRET_KEY!);
54
59
 
55
60
  const sign = c.req.header("Stripe-Signature");
56
61
  if (!sign) throw new Error("No Signature");
57
62
 
58
- const webhookEvent = await unify.stripe.webhook.verifySignature({
63
+ const webhookEvent = await stripe.verifySignature({
59
64
  signature: sign,
60
65
  secret: "PUT YOUR WEBHOOK SECRET HERE",
61
66
  body: await c.req.text(),
@@ -72,14 +77,12 @@ switch (webhookEvent.event.type) {
72
77
  }
73
78
 
74
79
  // LemonSqueezy
75
- const unify = new UnifyPayment({
76
- lemonsqueezy: new LemonSqueezy(lemonsqueezyKey),
77
- });
80
+ const lemon = new UnifyPayment.LemonSqueezy(process.env.LEMON_SECRET_KEY!);
78
81
 
79
82
  const sign = c.req.header("X-Signature");
80
83
  if (!sign) throw new Error("No Signature");
81
84
 
82
- const webhookEvent = await unify.lemonsqueezy.webhook.verifySignature({
85
+ const webhookEvent = await lemon.verifySignature({
83
86
  signature: sign,
84
87
  secret: "PUT YOUR WEBHOOK SECRET HERE",
85
88
  body: await c.req.text(),
@@ -0,0 +1,345 @@
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?: HeadersInit;
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<void>;
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 IPaypalOptions {
198
+ clientId: string;
199
+ clientSecret: string;
200
+ sandbox?: boolean;
201
+ }
202
+ interface IPaypalPayload {
203
+ intent: "CAPTURE";
204
+ purchase_units: {
205
+ items: {
206
+ name: string;
207
+ description: string;
208
+ quantity: number;
209
+ unit_amount: {
210
+ currency_code: "USD" | "EUR";
211
+ value: string;
212
+ };
213
+ }[];
214
+ amount: {
215
+ currency_code: "USD" | "EUR";
216
+ value: string;
217
+ breakdown: {
218
+ item_total: {
219
+ currency_code: "USD" | "EUR";
220
+ value: string;
221
+ };
222
+ };
223
+ };
224
+ }[];
225
+ application_context: {
226
+ return_url: string;
227
+ cancel_url: string;
228
+ shipping_preference?: "NO_SHIPPING";
229
+ user_action?: "PAY_NOW";
230
+ brand_name?: string;
231
+ };
232
+ }
233
+
234
+ declare class Paypal extends UnifyFetch {
235
+ private options;
236
+ constructor(options: IPaypalOptions);
237
+ private getApiBaseUrl;
238
+ private getClientId;
239
+ private getClientSecret;
240
+ private getApiCheckoutUrl;
241
+ getAccessToken(): Promise<string>;
242
+ getCheckoutUrl(payload: IPaypalPayload): Promise<string>;
243
+ }
244
+
245
+ type ISSLCommerzCreateCheckoutPayload = {
246
+ tran_id: string;
247
+ store_id: string;
248
+ store_passwd: string;
249
+ total_amount: number;
250
+ currency: "USD" | "EUR";
251
+ success_url?: string;
252
+ cancel_url?: string;
253
+ cus_name: string;
254
+ cus_email: string;
255
+ cus_add1: string;
256
+ cus_add2?: string;
257
+ cus_city: string;
258
+ cus_state: string;
259
+ cus_postcode: string;
260
+ cus_country: string;
261
+ cus_phone: string;
262
+ cus_fax?: string;
263
+ shipping_method: "NO";
264
+ product_name: string;
265
+ product_category: string;
266
+ product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
267
+ } | {
268
+ tran_id: string;
269
+ store_id: string;
270
+ store_passwd: string;
271
+ total_amount: number;
272
+ currency: "USD" | "EUR";
273
+ success_url?: string;
274
+ cancel_url?: string;
275
+ cus_name: string;
276
+ cus_email: string;
277
+ cus_add1: string;
278
+ cus_add2?: string;
279
+ cus_city: string;
280
+ cus_state: string;
281
+ cus_postcode: string;
282
+ cus_country: string;
283
+ cus_phone: string;
284
+ cus_fax?: string;
285
+ shipping_method: "YES";
286
+ ship_name: string;
287
+ ship_add1: string;
288
+ ship_add2?: string;
289
+ ship_city: string;
290
+ ship_state: string;
291
+ ship_postcode: string;
292
+ ship_country: string;
293
+ product_name: string;
294
+ product_category: string;
295
+ product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
296
+ };
297
+ type ISSLCommerzOptions = {
298
+ apiUrl: string;
299
+ store_id: string;
300
+ store_url?: string;
301
+ store_passwd: string;
302
+ };
303
+
304
+ declare class SSLCommerz extends UnifyFetch {
305
+ private options;
306
+ constructor(options: ISSLCommerzOptions);
307
+ private getApiBaseUrl;
308
+ private getApiCheckoutUrl;
309
+ private getApiValidationUrl;
310
+ private getApiRefundUrl;
311
+ private getApiRefundQueryUrl;
312
+ private getApiTransactionQueryBySessionIdUrl;
313
+ private getApiTransactionQueryByTransactionIdUrl;
314
+ private getApiHeaders;
315
+ private urlFormEncode;
316
+ getCheckoutUrl(payload: ISSLCommerzCreateCheckoutPayload): Promise<string>;
317
+ }
318
+
319
+ type TStripeWebhookEventResponse = {
320
+ error: Error;
321
+ } | {
322
+ event: Stripe$1.Event;
323
+ };
324
+
325
+ declare class Stripe {
326
+ private apiKey;
327
+ private stripe;
328
+ constructor(apiKey: string, config?: Stripe$2.StripeConfig);
329
+ getCheckoutUrl(params: Stripe$2.Checkout.SessionCreateParams): Promise<string>;
330
+ verifySignature(payload: {
331
+ signature: string;
332
+ secret: string;
333
+ body: string;
334
+ }): Promise<TStripeWebhookEventResponse>;
335
+ }
336
+
337
+ declare const UnifyPayment: {
338
+ LemonSqueezy: typeof LemonSqueezy;
339
+ Bkash: typeof Bkash;
340
+ Paypal: typeof Paypal;
341
+ SSLCommerz: typeof SSLCommerz;
342
+ Stripe: typeof Stripe;
343
+ };
344
+
345
+ export { UnifyPayment };