@unify-payment/node 0.0.3 → 0.0.4
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 +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/common.d.ts +5 -2
- package/dist/lib/common.js +7 -1
- package/dist/lib/sslcommerz.d.ts +28 -0
- package/dist/lib/sslcommerz.js +79 -0
- package/dist/types/sslcommerz.d.ts +85 -0
- package/dist/types/sslcommerz.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,11 +14,11 @@ UnifyPayment is a TypeScript package that provides a unified interface for integ
|
|
|
14
14
|
- **Stripe:** (Checkout, Webhook) will add more functionality later.
|
|
15
15
|
- **LemonSqueezy:** (Checkout, Webhook) will add more functionality later.
|
|
16
16
|
- **Paddle:** (Checkout, Webhook) will add more functionality later.
|
|
17
|
+
- **SSLCommerz:** (Checkout) will add more functionality later.
|
|
17
18
|
- **PayPal:** (upcoming).
|
|
18
19
|
- **RazorPay:** (upcoming).
|
|
19
20
|
- **GooglePay:** (planing).
|
|
20
21
|
- **Shopify:** (planing).
|
|
21
|
-
- **SSLCommerz:** (planing).
|
|
22
22
|
|
|
23
23
|
## Installation
|
|
24
24
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./lib/common"), exports);
|
|
18
18
|
__exportStar(require("./lib/lemonsqueezy"), exports);
|
|
19
19
|
__exportStar(require("./lib/stripe"), exports);
|
|
20
|
+
__exportStar(require("./lib/sslcommerz"), exports);
|
|
20
21
|
__exportStar(require("./types/lemonsqueezy"), exports);
|
|
22
|
+
__exportStar(require("./types/sslcommerz"), exports);
|
package/dist/lib/common.d.ts
CHANGED
|
@@ -260,18 +260,21 @@
|
|
|
260
260
|
/// <reference types="stripe/types/WebhookEndpoints" />
|
|
261
261
|
/// <reference types="stripe/types/lib" />
|
|
262
262
|
/// <reference types="stripe/types/net/net" />
|
|
263
|
+
import { Paddle } from "@paddle/paddle-node-sdk";
|
|
263
264
|
import Stripe from "stripe";
|
|
264
265
|
import { LemonSqueezy, UnifyLemonSqueezy } from "./lemonsqueezy";
|
|
265
|
-
import { UnifyStripe } from "./stripe";
|
|
266
|
-
import { Paddle } from "@paddle/paddle-node-sdk";
|
|
267
266
|
import { UnifyPaddle } from "./paddle";
|
|
267
|
+
import { SSLCommerz, UnifySSLCommerz } from "./sslcommerz";
|
|
268
|
+
import { UnifyStripe } from "./stripe";
|
|
268
269
|
export type UnifyPaymentOptions = {
|
|
269
270
|
stripe?: Stripe;
|
|
270
271
|
lemonsqueezy?: LemonSqueezy;
|
|
272
|
+
sslcommerz?: SSLCommerz;
|
|
271
273
|
paddle?: Paddle;
|
|
272
274
|
};
|
|
273
275
|
export declare class UnifyPayment<T extends UnifyPaymentOptions = UnifyPaymentOptions> {
|
|
274
276
|
stripe: T["stripe"] extends Stripe ? UnifyStripe : undefined;
|
|
277
|
+
sslcommerz: T["sslcommerz"] extends SSLCommerz ? UnifySSLCommerz : undefined;
|
|
275
278
|
lemonsqueezy: T["lemonsqueezy"] extends LemonSqueezy ? UnifyLemonSqueezy : undefined;
|
|
276
279
|
paddle: T["paddle"] extends Paddle ? UnifyPaddle : undefined;
|
|
277
280
|
constructor(options: T);
|
package/dist/lib/common.js
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnifyPayment = void 0;
|
|
4
4
|
const lemonsqueezy_1 = require("./lemonsqueezy");
|
|
5
|
-
const stripe_1 = require("./stripe");
|
|
6
5
|
const paddle_1 = require("./paddle");
|
|
6
|
+
const sslcommerz_1 = require("./sslcommerz");
|
|
7
|
+
const stripe_1 = require("./stripe");
|
|
7
8
|
class UnifyPayment {
|
|
8
9
|
constructor(options) {
|
|
10
|
+
// stripe
|
|
9
11
|
this.stripe = new stripe_1.UnifyStripe(options.stripe);
|
|
12
|
+
// sslcommerz
|
|
13
|
+
this.sslcommerz = new sslcommerz_1.UnifySSLCommerz(options.sslcommerz);
|
|
14
|
+
// lemonsqueezy
|
|
10
15
|
this.lemonsqueezy = new lemonsqueezy_1.UnifyLemonSqueezy(options.lemonsqueezy);
|
|
16
|
+
// paddle
|
|
11
17
|
this.paddle = new paddle_1.UnifyPaddle(options.paddle);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SSLCommerzCreateCheckoutPayload } from "../types/sslcommerz";
|
|
2
|
+
export type SSLCommerzOptions = {
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
store_id: string;
|
|
5
|
+
store_url?: string;
|
|
6
|
+
store_passwd: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class SSLCommerz {
|
|
9
|
+
private options;
|
|
10
|
+
constructor(options: SSLCommerzOptions);
|
|
11
|
+
getApiBaseUrl(): string;
|
|
12
|
+
getApiCheckoutUrl(): string;
|
|
13
|
+
getApiValidationUrl(): string;
|
|
14
|
+
getApiRefundUrl(): string;
|
|
15
|
+
getApiRefundQueryUrl(): string;
|
|
16
|
+
getApiTransactionQueryBySessionIdUrl(): string;
|
|
17
|
+
getApiTransactionQueryByTransactionIdUrl(): string;
|
|
18
|
+
getApiHeaders(): {
|
|
19
|
+
"Content-Type": string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare class UnifySSLCommerz {
|
|
23
|
+
private sslcommerz;
|
|
24
|
+
constructor(sslcommerz: SSLCommerz);
|
|
25
|
+
private fetch;
|
|
26
|
+
private urlFormEncode;
|
|
27
|
+
getCheckoutUrl(payload: SSLCommerzCreateCheckoutPayload): Promise<string>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UnifySSLCommerz = exports.SSLCommerz = void 0;
|
|
13
|
+
class SSLCommerz {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
getApiBaseUrl() {
|
|
18
|
+
return this.options.apiUrl;
|
|
19
|
+
}
|
|
20
|
+
getApiCheckoutUrl() {
|
|
21
|
+
return `${this.getApiBaseUrl()}/gwprocess/v4/api.php`;
|
|
22
|
+
}
|
|
23
|
+
getApiValidationUrl() {
|
|
24
|
+
return `${this.getApiBaseUrl()}/validator/api/validationserverAPI.php`;
|
|
25
|
+
}
|
|
26
|
+
getApiRefundUrl() {
|
|
27
|
+
return `${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`;
|
|
28
|
+
}
|
|
29
|
+
getApiRefundQueryUrl() {
|
|
30
|
+
return `${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`;
|
|
31
|
+
}
|
|
32
|
+
getApiTransactionQueryBySessionIdUrl() {
|
|
33
|
+
return `${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`;
|
|
34
|
+
}
|
|
35
|
+
getApiTransactionQueryByTransactionIdUrl() {
|
|
36
|
+
return `${this.getApiBaseUrl()}/validator/api/merchantTransIDvalidationAPI.php`;
|
|
37
|
+
}
|
|
38
|
+
getApiHeaders() {
|
|
39
|
+
return {
|
|
40
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.SSLCommerz = SSLCommerz;
|
|
45
|
+
class UnifySSLCommerz {
|
|
46
|
+
constructor(sslcommerz) {
|
|
47
|
+
this.sslcommerz = sslcommerz;
|
|
48
|
+
}
|
|
49
|
+
fetch(url, params) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return yield fetch(url, {
|
|
52
|
+
method: (params === null || params === void 0 ? void 0 : params.method) || "GET",
|
|
53
|
+
headers: this.sslcommerz.getApiHeaders(),
|
|
54
|
+
body: params === null || params === void 0 ? void 0 : params.body,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
urlFormEncode(payload) {
|
|
59
|
+
return Object.entries(payload)
|
|
60
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
61
|
+
.join("&");
|
|
62
|
+
}
|
|
63
|
+
getCheckoutUrl(payload) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const req = yield this.fetch(this.sslcommerz.getApiCheckoutUrl(), {
|
|
66
|
+
method: "POST",
|
|
67
|
+
body: this.urlFormEncode(payload),
|
|
68
|
+
headers: this.sslcommerz.getApiHeaders(),
|
|
69
|
+
});
|
|
70
|
+
// TODO: handle parsing error
|
|
71
|
+
const res = (yield req.json());
|
|
72
|
+
if (res.status === "FAILED") {
|
|
73
|
+
throw new Error(res.failedreason);
|
|
74
|
+
}
|
|
75
|
+
return res.redirectGatewayURL;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.UnifySSLCommerz = UnifySSLCommerz;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export type SSLCommerzCreateCheckoutPayload = {
|
|
2
|
+
tran_id: string;
|
|
3
|
+
store_id: string;
|
|
4
|
+
store_passwd: string;
|
|
5
|
+
total_amount: number;
|
|
6
|
+
currency: "USD" | "EUR";
|
|
7
|
+
success_url?: string;
|
|
8
|
+
cancel_url?: string;
|
|
9
|
+
cus_name: string;
|
|
10
|
+
cus_email: string;
|
|
11
|
+
cus_add1: string;
|
|
12
|
+
cus_add2?: string;
|
|
13
|
+
cus_city: string;
|
|
14
|
+
cus_state: string;
|
|
15
|
+
cus_postcode: string;
|
|
16
|
+
cus_country: string;
|
|
17
|
+
cus_phone: string;
|
|
18
|
+
cus_fax?: string;
|
|
19
|
+
shipping_method: "NO";
|
|
20
|
+
product_name: string;
|
|
21
|
+
product_category: string;
|
|
22
|
+
product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
|
|
23
|
+
} | {
|
|
24
|
+
tran_id: string;
|
|
25
|
+
store_id: string;
|
|
26
|
+
store_passwd: string;
|
|
27
|
+
total_amount: number;
|
|
28
|
+
currency: "USD" | "EUR";
|
|
29
|
+
success_url?: string;
|
|
30
|
+
cancel_url?: string;
|
|
31
|
+
cus_name: string;
|
|
32
|
+
cus_email: string;
|
|
33
|
+
cus_add1: string;
|
|
34
|
+
cus_add2?: string;
|
|
35
|
+
cus_city: string;
|
|
36
|
+
cus_state: string;
|
|
37
|
+
cus_postcode: string;
|
|
38
|
+
cus_country: string;
|
|
39
|
+
cus_phone: string;
|
|
40
|
+
cus_fax?: string;
|
|
41
|
+
shipping_method: "YES";
|
|
42
|
+
ship_name: string;
|
|
43
|
+
ship_add1: string;
|
|
44
|
+
ship_add2?: string;
|
|
45
|
+
ship_city: string;
|
|
46
|
+
ship_state: string;
|
|
47
|
+
ship_postcode: string;
|
|
48
|
+
ship_country: string;
|
|
49
|
+
product_name: string;
|
|
50
|
+
product_category: string;
|
|
51
|
+
product_profile: "general" | "physical-goods" | "non-physical-goods" | "airline-tickets" | "travel-vertical" | "telecom-vertical";
|
|
52
|
+
};
|
|
53
|
+
export interface SSLCommerzCheckoutResponse {
|
|
54
|
+
status: "SUCCESS" | "FAILED";
|
|
55
|
+
failedreason: string;
|
|
56
|
+
sessionkey: string;
|
|
57
|
+
gw: Gw;
|
|
58
|
+
redirectGatewayURL: string;
|
|
59
|
+
directPaymentURLBank: string;
|
|
60
|
+
directPaymentURLCard: string;
|
|
61
|
+
directPaymentURL: string;
|
|
62
|
+
redirectGatewayURLFailed: string;
|
|
63
|
+
GatewayPageURL: string;
|
|
64
|
+
storeBanner: string;
|
|
65
|
+
storeLogo: string;
|
|
66
|
+
store_name: string;
|
|
67
|
+
desc: Desc[];
|
|
68
|
+
is_direct_pay_enable: string;
|
|
69
|
+
}
|
|
70
|
+
export interface Gw {
|
|
71
|
+
visa: string;
|
|
72
|
+
master: string;
|
|
73
|
+
amex: string;
|
|
74
|
+
othercards: string;
|
|
75
|
+
internetbanking: string;
|
|
76
|
+
mobilebanking: string;
|
|
77
|
+
}
|
|
78
|
+
export interface Desc {
|
|
79
|
+
name: string;
|
|
80
|
+
type: string;
|
|
81
|
+
logo: string;
|
|
82
|
+
gw: string;
|
|
83
|
+
r_flag?: string;
|
|
84
|
+
redirectGatewayURL?: string;
|
|
85
|
+
}
|