@unify-payment/node 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +213 -62
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -11,15 +11,18 @@ UnifyPayment is a TypeScript package that provides a unified interface for integ
11
11
 
12
12
  ## Providers
13
13
 
14
- - **Stripe:** (Checkout, Webhook) will add more functionality later.
15
- - **LemonSqueezy:** (Checkout, Webhook) will add more functionality later.
16
- - **SSLCommerz:** (Checkout) will add more functionality later.
17
- - **PayPal:** (Checkout) will add more functionality later.
18
- - **Bkash:** (Checkout) will add more functionality later.
19
- - **Nagad:** (Checkout) will add more functionality later.
20
- - **RazorPay:** (upcoming).
21
- - **Shopify:** (upcoming).
22
- - **GooglePay:** (planing).
14
+ | Provider | Checkout | Verify Webhook | Tested Checkout | Tested Webhook |
15
+ | ------------ | -------- | -------------- | ------------------ | ------------------ |
16
+ | Stripe | Yes | Yes | :white_check_mark: | :white_check_mark: |
17
+ | LemonSqueezy | Yes | Yes | :white_check_mark: | :white_check_mark: |
18
+ | SSLCommerz | Yes | No | :x: | :x: |
19
+ | PayPal | Yes | No | :x: | :x: |
20
+ | Bkash | Yes | No | :x: | :x: |
21
+ | Nagad | Yes | No | :x: | :x: |
22
+ | Razorpay | Yes | Yes | :x: | :x: |
23
+ | Polar | Yes | Yes | :x: | :x: |
24
+ | Paddle | Yes | Yes | :x: | :x: |
25
+ | Coinbase | Yes | Yes | :x: | :x: |
23
26
 
24
27
  ## Installation
25
28
 
@@ -32,74 +35,228 @@ npm install @unify-payment/node
32
35
  ## Usage
33
36
 
34
37
  ```typescript
35
- // Stripe
36
- const stripe = new UnifyPayment.Stripe(process.env.STRIPE_SECRET_KEY!);
37
- const redirect = await stripe.getCheckoutUrl(stripePayload);
38
+ import { createPayment } from "@unify-payment/node";
39
+ ```
38
40
 
39
- // LemonSqueezy
40
- const lemon = new UnifyPayment.LemonSqueezy(process.env.LEMON_SECRET_KEY!);
41
- const redirect = await lemon.getCheckoutUrl(lemonsqueezyPayload);
41
+ ### Stripe
42
42
 
43
- // Paypal
44
- const paypal = new UnifyPayment.Paypal(process.env.PAYPAL_SECRET_KEY!);
45
- const redirect = await paypal.getCheckoutUrl(lemonsqueezyPayload);
43
+ ```typescript
44
+ const payment = createPayment({
45
+ provider: "stripe",
46
+ apiKey: process.env.STRIPE_SECRET_KEY!,
47
+ });
46
48
 
47
- // SSLCommerz
48
- const ssl = new UnifyPayment.SSLCommerz({
49
- apiUrl: process.env.SSLCOMMERZ_API_URL!,
50
- store_id: process.env.SSLCOMMERZ_STORE_ID!,
51
- store_passwd: process.env.SSLCOMMERZ_SECRET_KEY!,
49
+ const { url } = await payment.createCheckoutSession({
50
+ amount: 2999,
51
+ currency: "usd",
52
+ successUrl: "https://example.com/success",
53
+ cancelUrl: "https://example.com/cancel",
54
+ productName: "Pro Plan",
52
55
  });
53
- const redirect = await ssl.getCheckoutUrl(sslCommerzPayload);
54
56
  ```
55
57
 
56
- ## Webhook
58
+ ### LemonSqueezy
57
59
 
58
60
  ```typescript
59
- // Stripe
60
- const stripe = new UnifyPayment.Stripe(process.env.STRIPE_SECRET_KEY!);
61
+ const payment = createPayment({
62
+ provider: "lemonsqueezy",
63
+ apiKey: process.env.LEMON_SECRET_KEY!,
64
+ });
61
65
 
62
- const sign = c.req.header("Stripe-Signature");
63
- if (!sign) throw new Error("No Signature");
66
+ const { url } = await payment.createCheckoutSession({
67
+ amount: 2999,
68
+ currency: "usd",
69
+ successUrl: "https://example.com/success",
70
+ cancelUrl: "https://example.com/cancel",
71
+ storeId: "your-store-id",
72
+ variantId: "your-variant-id",
73
+ });
74
+ ```
64
75
 
65
- const webhookEvent = await stripe.verifySignature({
66
- signature: sign,
67
- secret: "PUT YOUR WEBHOOK SECRET HERE",
68
- body: await c.req.text(),
76
+ ### PayPal
77
+
78
+ ```typescript
79
+ const payment = createPayment({
80
+ provider: "paypal",
81
+ clientId: process.env.PAYPAL_CLIENT_ID!,
82
+ clientSecret: process.env.PAYPAL_CLIENT_SECRET!,
83
+ sandbox: true,
69
84
  });
70
85
 
71
- if ("error" in webhookEvent) throw new Error(webhookEvent.error.message);
86
+ const { url } = await payment.createCheckoutSession({
87
+ amount: 2999,
88
+ currency: "usd",
89
+ successUrl: "https://example.com/success",
90
+ cancelUrl: "https://example.com/cancel",
91
+ description: "Pro Plan",
92
+ });
93
+ ```
72
94
 
73
- switch (webhookEvent.event.type) {
74
- case "checkout.session.async_payment_succeeded":
75
- break;
95
+ ### Paddle
76
96
 
77
- default:
78
- break;
79
- }
97
+ ```typescript
98
+ const payment = createPayment({
99
+ provider: "paddle",
100
+ apiKey: process.env.PADDLE_API_KEY!,
101
+ sandbox: true,
102
+ });
80
103
 
81
- // LemonSqueezy
82
- const lemon = new UnifyPayment.LemonSqueezy(process.env.LEMON_SECRET_KEY!);
104
+ const { url } = await payment.createCheckoutSession({
105
+ priceId: "pri_xxxxx",
106
+ amount: 2999,
107
+ currency: "usd",
108
+ successUrl: "https://example.com/success",
109
+ cancelUrl: "https://example.com/cancel",
110
+ });
111
+ ```
83
112
 
84
- const sign = c.req.header("X-Signature");
85
- if (!sign) throw new Error("No Signature");
113
+ ### Polar
86
114
 
87
- const webhookEvent = await lemon.verifySignature({
88
- signature: sign,
89
- secret: "PUT YOUR WEBHOOK SECRET HERE",
90
- body: await c.req.text(),
91
- x_event: c.req.header("X-Event-Name")!,
115
+ ```typescript
116
+ const payment = createPayment({
117
+ provider: "polar",
118
+ accessToken: process.env.POLAR_ACCESS_TOKEN!,
119
+ sandbox: true,
120
+ });
121
+
122
+ const { url } = await payment.createCheckoutSession({
123
+ productId: "your-product-id",
124
+ amount: 2999,
125
+ currency: "usd",
126
+ successUrl: "https://example.com/success",
127
+ cancelUrl: "https://example.com/cancel",
128
+ });
129
+ ```
130
+
131
+ ### Coinbase
132
+
133
+ ```typescript
134
+ const payment = createPayment({
135
+ provider: "coinbase",
136
+ apiKey: process.env.COINBASE_API_KEY!,
137
+ });
138
+
139
+ const { url } = await payment.createCheckoutSession({
140
+ amount: 2999,
141
+ currency: "usd",
142
+ successUrl: "https://example.com/success",
143
+ cancelUrl: "https://example.com/cancel",
144
+ name: "Pro Plan",
145
+ description: "Monthly subscription",
146
+ });
147
+ ```
148
+
149
+ ### Razorpay
150
+
151
+ ```typescript
152
+ const payment = createPayment({
153
+ provider: "razorpay",
154
+ keyId: process.env.RAZORPAY_KEY_ID!,
155
+ keySecret: process.env.RAZORPAY_KEY_SECRET!,
156
+ });
157
+
158
+ const { url } = await payment.createCheckoutSession({
159
+ amount: 2999,
160
+ currency: "inr",
161
+ successUrl: "https://example.com/success",
162
+ cancelUrl: "https://example.com/cancel",
163
+ description: "Pro Plan",
92
164
  });
165
+ ```
93
166
 
94
- if ("error" in webhookEvent) throw new Error(webhookEvent.error.message);
167
+ ### SSLCommerz
95
168
 
96
- switch (webhookEvent.type) {
97
- case "order_refunded":
98
- break;
169
+ ```typescript
170
+ const payment = createPayment({
171
+ provider: "sslcommerz",
172
+ apiUrl: process.env.SSLCOMMERZ_API_URL!,
173
+ storeId: process.env.SSLCOMMERZ_STORE_ID!,
174
+ storePassword: process.env.SSLCOMMERZ_SECRET_KEY!,
175
+ });
99
176
 
100
- default:
101
- break;
102
- }
177
+ const { url } = await payment.createCheckoutSession({
178
+ amount: 2999,
179
+ currency: "usd",
180
+ successUrl: "https://example.com/success",
181
+ cancelUrl: "https://example.com/cancel",
182
+ transactionId: "txn_123",
183
+ customerName: "John Doe",
184
+ customerEmail: "john@example.com",
185
+ customerAddress: "123 Main St",
186
+ customerCity: "Dhaka",
187
+ customerState: "Dhaka",
188
+ customerPostcode: "1000",
189
+ customerCountry: "Bangladesh",
190
+ customerPhone: "01700000000",
191
+ productName: "Pro Plan",
192
+ productCategory: "SaaS",
193
+ });
194
+ ```
195
+
196
+ ### Bkash
197
+
198
+ ```typescript
199
+ const payment = createPayment({
200
+ provider: "bkash",
201
+ apiUrl: process.env.BKASH_API_URL!,
202
+ username: process.env.BKASH_USERNAME!,
203
+ password: process.env.BKASH_PASSWORD!,
204
+ appKey: process.env.BKASH_APP_KEY!,
205
+ appSecret: process.env.BKASH_APP_SECRET!,
206
+ });
207
+
208
+ const { url } = await payment.createCheckoutSession({
209
+ amount: 500,
210
+ currency: "BDT",
211
+ successUrl: "https://example.com/success",
212
+ cancelUrl: "https://example.com/cancel",
213
+ payerReference: "01700000000",
214
+ merchantInvoiceNumber: "INV-123",
215
+ });
216
+ ```
217
+
218
+ ### Nagad
219
+
220
+ ```typescript
221
+ const payment = createPayment({
222
+ provider: "nagad",
223
+ merchantId: process.env.NAGAD_MERCHANT_ID!,
224
+ merchantNumber: process.env.NAGAD_MERCHANT_NUMBER!,
225
+ privateKey: process.env.NAGAD_PRIVATE_KEY!,
226
+ publicKey: process.env.NAGAD_PUBLIC_KEY!,
227
+ callbackUrl: "https://example.com/callback",
228
+ apiVersion: "v1",
229
+ isLive: false,
230
+ });
231
+
232
+ const { url } = await payment.createCheckoutSession({
233
+ amount: 500,
234
+ currency: "BDT",
235
+ successUrl: "https://example.com/success",
236
+ cancelUrl: "https://example.com/cancel",
237
+ orderId: "order_123",
238
+ ip: "127.0.0.1",
239
+ });
240
+ ```
241
+
242
+ ## Webhook Verification
243
+
244
+ Providers that support webhook verification: **Stripe**, **LemonSqueezy**, **Razorpay**, **Polar**, **Paddle**, **Coinbase**.
245
+
246
+ ```typescript
247
+ const payment = createPayment({
248
+ provider: "stripe",
249
+ apiKey: process.env.STRIPE_SECRET_KEY!,
250
+ });
251
+
252
+ const webhookEvent = await payment.verifyWebhook!({
253
+ body: await c.req.text(),
254
+ signature: c.req.header("Stripe-Signature")!,
255
+ secret: process.env.STRIPE_WEBHOOK_SECRET!,
256
+ });
257
+
258
+ console.log(webhookEvent.type); // e.g. "checkout.session.completed"
259
+ console.log(webhookEvent.data); // event payload
103
260
  ```
104
261
 
105
262
  ## Contributing
@@ -143,9 +300,3 @@ We welcome contributions to UnifyPayment! If you'd like to help improve this pac
143
300
  - Add or update tests for new features or bug fixes.
144
301
  - Update documentation as needed.
145
302
  - Be respectful and constructive in discussions and code reviews.
146
-
147
- ## Special Thanks
148
-
149
- A special thanks to **Piyush Garg** ([@piyushgargdev](https://www.youtube.com/@piyushgargdev)) for suggesting the idea behind this package. Piyush is a talented developer and content creator who shares valuable insights and ideas in the world of software development. His suggestion was the spark that led to the creation of UnifyPayment, aiming to simplify payment integrations for developers.
150
-
151
- We appreciate Piyush's contribution to the developer community and encourage you to check out his YouTube channel for more inspiring content and innovative ideas in the tech space.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unify-payment/node",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.mjs",