zibalts 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Zibal: () => Zibal
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/urls.ts
38
+ var rootAPIUrl = "https://gateway.zibal.ir/";
39
+ var urls = {
40
+ requestURL: `${rootAPIUrl}v1/request`,
41
+ startURL: `${rootAPIUrl}start/`,
42
+ verifyURL: `${rootAPIUrl}v1/verify`
43
+ };
44
+ var urls_default = {
45
+ ...urls,
46
+ getStartUrl: (trackId) => {
47
+ return `${urls.startURL}${trackId}`;
48
+ }
49
+ };
50
+
51
+ // src/index.ts
52
+ var import_axios = __toESM(require("axios"), 1);
53
+
54
+ // src/errors.ts
55
+ var results = {
56
+ 100: "\u0645\u0648\u0641\u0642",
57
+ 102: "merchant \u06CC\u0627\u0641\u062A \u0646\u0634\u062F.",
58
+ 103: "merchant \u063A\u06CC\u0631\u0641\u0639\u0627\u0644 \u0627\u0633\u062A. \u0628\u0627 \u067E\u0634\u062A\u06CC\u0628\u0627\u0646\u06CC \u062A\u0645\u0627\u0633 \u062D\u0627\u0635\u0644 \u06A9\u0646\u06CC\u062F.",
59
+ 104: "merchantId \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A.",
60
+ 105: "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u0627\u0632 1,000 \u0631\u06CC\u0627\u0644 \u0628\u0632\u0631\u06AF\u062A\u0631 \u0628\u0627\u0634\u062F",
61
+ 106: "callbackUrl \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A.",
62
+ 113: "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u0627\u0632 500,000,000 \u0631\u06CC\u0627\u0644 \u06A9\u0645\u062A\u0631 \u0628\u0627\u0634\u062F.",
63
+ 140: "callbackUrl \u0627\u0631\u0633\u0627\u0644 \u0646\u0634\u062F\u0647.",
64
+ 201: "\u0642\u0628\u0644\u0627 \u062A\u0627\u06CC\u06CC\u062F \u0634\u062F\u0647.",
65
+ 202: "\u0633\u0641\u0627\u0631\u0634 \u067E\u0631\u062F\u0627\u062E\u062A \u0646\u0634\u062F\u0647 \u06CC\u0627 \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0648\u062F\u0647 \u0627\u0633\u062A.",
66
+ 203: "trackId \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A.",
67
+ "-1": "\u062E\u0637\u0627"
68
+ };
69
+ var statuses = {
70
+ "-100": "\u062E\u0637\u0627",
71
+ "-1": "\u062F\u0631 \u0627\u0646\u062A\u0638\u0627\u0631 \u067E\u0631\u062F\u0627\u062E\u062A",
72
+ "-2": "\u062E\u0637\u0627\u06CC \u062F\u0627\u062E\u0644\u06CC",
73
+ 1: "\u067E\u0631\u062F\u0627\u062E\u062A \u0634\u062F\u0647 - \u062A\u0627\u06CC\u06CC\u062F\u0634\u062F\u0647",
74
+ 2: "\u067E\u0631\u062F\u0627\u062E\u062A \u0634\u062F\u0647 - \u062A\u0627\u06CC\u06CC\u062F\u0646\u0634\u062F\u0647",
75
+ 3: "\u0644\u063A\u0648\u0634\u062F\u0647 \u062A\u0648\u0633\u0637 \u06A9\u0627\u0631\u0628\u0631",
76
+ 4: "\u0634\u0645\u0627\u0631\u0647 \u06A9\u0627\u0631\u062A \u0646\u0627\u0645\u0639\u062A\u0628\u0631",
77
+ 5: "\u0645\u0648\u062C\u0648\u062F\u06CC \u062D\u0633\u0627\u0628 \u0646\u0627\u06A9\u0627\u0641\u06CC",
78
+ 6: "\u0631\u0645\u0632 \u0627\u0634\u062A\u0628\u0627\u0647",
79
+ 7: "\u062A\u0639\u062F\u0627\u062F \u062F\u0631\u062E\u0648\u0627\u0633\u062A\u200C\u0647\u0627 \u0628\u06CC\u0634 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632",
80
+ 8: "\u062A\u0639\u062F\u0627\u062F \u067E\u0631\u062F\u0627\u062E\u062A \u0627\u06CC\u0646\u062A\u0631\u0646\u062A\u06CC \u0631\u0648\u0632\u0627\u0646\u0647 \u0628\u06CC\u0634 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632",
81
+ 9: "\u0645\u0628\u0644\u063A \u067E\u0631\u062F\u0627\u062E\u062A \u0627\u06CC\u0646\u062A\u0631\u0646\u062A\u06CC \u0631\u0648\u0632\u0627\u0646\u0647 \u0628\u06CC\u0634 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0631",
82
+ 10: "\u0635\u0627\u062F\u0631\u06A9\u0646\u0646\u062F\u0647 \u06A9\u0627\u0631\u062A \u0646\u0627\u0645\u0639\u062A\u0628\u0631",
83
+ 11: "\u062E\u0637\u0627\u06CC \u0633\u0648\u06CC\u06CC\u0686",
84
+ 12: "\u06A9\u0627\u0631\u062A \u063A\u06CC\u0631\u0642\u0627\u0628\u0644 \u062F\u0633\u062A\u0631\u0633\u06CC"
85
+ };
86
+ var errors_default = {
87
+ getPersianMessage: (result = "-1") => {
88
+ return results[result];
89
+ },
90
+ getPersianStatus: (status = "-100") => {
91
+ return statuses[status];
92
+ }
93
+ };
94
+
95
+ // src/index.ts
96
+ var Zibal = class {
97
+ merchant = "zibal";
98
+ callbackUrl = "";
99
+ /*
100
+ * Initialize Zibal with Your Gateway Merchant Id
101
+ * @param {object} config Your Config Object
102
+ * @param {string} config.merchant Your Zibal Merchant Id
103
+ * @param {string} config.callbackUrl Your Callback Url
104
+ * */
105
+ constructor(config) {
106
+ this.init({ merchant: config.merchant, callbackUrl: config.callbackUrl });
107
+ }
108
+ /**
109
+ * Set Merchant Id
110
+ * @param {string} merchant Your Merchant Id
111
+ * */
112
+ setMerchant(merchant) {
113
+ this.merchant = merchant;
114
+ }
115
+ /**
116
+ * Initialize Zibal with Your Gateway Merchant Id
117
+ * @param {object} config Your Config Object
118
+ * @param {string} config.merchant Your Zibal Merchant Id
119
+ * @param {string} config.callbackUrl Your Callback Url
120
+ * */
121
+ init({ merchant, callbackUrl }) {
122
+ this.setMerchant(merchant);
123
+ this.callbackUrl = callbackUrl;
124
+ }
125
+ /**
126
+ * Create a Payment Session
127
+ * @param {object} payload Request Payload
128
+ * @param {number} payload.amount Transaction Amount (Required)
129
+ * @param {string} [payload.merchant] Specify Merchant if you Haven't Specify in Class Config
130
+ * @param {string} [payload.callbackUrl] Url which User will be Redirected to After Payment
131
+ * @param {string} [payload.description] Transaction's Description
132
+ * @param {string} [payload.orderId] Transaction Order Id
133
+ * @param {string} [payload.mobile] User's Mobile (09123456789)
134
+ * @param {number} [payload.feeMode=0] Transaction Fee Mode
135
+ * @param {boolean} [payload.linkToPay=false] If you want us to Generate a Short Link, send this: true
136
+ * @param {boolean} [payload.sms=false] If you want us to Send the Short Link to User's Mobile, send this: true
137
+ * @param {number} [payload.percentMode=0] Whether to Calculate Each Submerchant Share with Percent
138
+ * @param {Array} [payload.multiplexingInfos=[]] Multiplexing for this Transaction
139
+ * @param {Array} [payload.allowedCards=[]] Array of Allowed Full Card Numbers for this Transaction
140
+ * @return {Promise<{}>} Promise will Resolve After HTTP Call is Successful
141
+ * @example
142
+ * request({amount: 20000})
143
+ *
144
+ * */
145
+ async request(configs) {
146
+ configs.merchant = configs.merchant ?? this.merchant;
147
+ configs.callbackUrl = configs.callbackUrl ?? this.callbackUrl;
148
+ console.log("configs: ", configs);
149
+ const result = await import_axios.default.default.post(urls_default.requestURL, configs);
150
+ const data = result.data || {};
151
+ data.persianMessage = errors_default.getPersianMessage(data.result);
152
+ if (result.data.result !== 100) {
153
+ data.success = false;
154
+ return data;
155
+ } else {
156
+ data.success = true;
157
+ data.paymentUrl = urls_default.getStartUrl(data.trackId);
158
+ return data;
159
+ }
160
+ }
161
+ /**
162
+ * Create a Payment Session
163
+ * @param {object} payload Verify Payload
164
+ * @param {string} payload.merchant IPG Merchant Id
165
+ * @param {number} [payload.trackId] IPG Transaction Track Id to be Verified
166
+ * */
167
+ async verify(configs) {
168
+ const result = await import_axios.default.default.post(urls_default.verifyURL, {
169
+ trackId: configs.trackId,
170
+ merchant: configs.merchant ?? this.merchant
171
+ });
172
+ const data = result.data || {};
173
+ data.persianMessage = errors_default.getPersianMessage(data.result);
174
+ if (result.data.result !== 100) {
175
+ data.success = false;
176
+ return data;
177
+ } else {
178
+ data.success = true;
179
+ return data;
180
+ }
181
+ }
182
+ };
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ Zibal
186
+ });
@@ -0,0 +1,94 @@
1
+ type resultId = 100 | 102 | 103 | 104 | 105 | 106 | 113 | 140 | 201 | 202 | 203 | "-1";
2
+ type statusId = "-100" | "-1" | "-2" | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
3
+
4
+ interface ZibalRequest {
5
+ amount: number;
6
+ callbackUrl?: string;
7
+ orderId?: number;
8
+ merchant?: string;
9
+ mobile?: string;
10
+ multiplexingInfos?: any;
11
+ description?: string;
12
+ linkToPay?: boolean;
13
+ sms?: boolean;
14
+ percentMode?: number;
15
+ feeMode?: number;
16
+ allowedCards?: any;
17
+ }
18
+ interface ZibalRequestResponse {
19
+ trackId: number;
20
+ result: resultId;
21
+ message: string;
22
+ persianMessage: string;
23
+ success: boolean;
24
+ paymentUrl: string;
25
+ }
26
+ interface ZibalVerify {
27
+ trackId: number;
28
+ merchant?: string;
29
+ }
30
+ interface ZibalVerifyResponse {
31
+ message: string;
32
+ result: resultId;
33
+ refNumber: any;
34
+ paidAt: Date;
35
+ status: statusId;
36
+ amount: number;
37
+ orderId: string;
38
+ description: string;
39
+ multiplexingInfos: any[];
40
+ cardNumber: any;
41
+ persianMessage: string;
42
+ success: boolean;
43
+ }
44
+
45
+ declare class Zibal {
46
+ private merchant;
47
+ private callbackUrl;
48
+ constructor(config: {
49
+ merchant: string;
50
+ callbackUrl: string;
51
+ });
52
+ /**
53
+ * Set Merchant Id
54
+ * @param {string} merchant Your Merchant Id
55
+ * */
56
+ private setMerchant;
57
+ /**
58
+ * Initialize Zibal with Your Gateway Merchant Id
59
+ * @param {object} config Your Config Object
60
+ * @param {string} config.merchant Your Zibal Merchant Id
61
+ * @param {string} config.callbackUrl Your Callback Url
62
+ * */
63
+ private init;
64
+ /**
65
+ * Create a Payment Session
66
+ * @param {object} payload Request Payload
67
+ * @param {number} payload.amount Transaction Amount (Required)
68
+ * @param {string} [payload.merchant] Specify Merchant if you Haven't Specify in Class Config
69
+ * @param {string} [payload.callbackUrl] Url which User will be Redirected to After Payment
70
+ * @param {string} [payload.description] Transaction's Description
71
+ * @param {string} [payload.orderId] Transaction Order Id
72
+ * @param {string} [payload.mobile] User's Mobile (09123456789)
73
+ * @param {number} [payload.feeMode=0] Transaction Fee Mode
74
+ * @param {boolean} [payload.linkToPay=false] If you want us to Generate a Short Link, send this: true
75
+ * @param {boolean} [payload.sms=false] If you want us to Send the Short Link to User's Mobile, send this: true
76
+ * @param {number} [payload.percentMode=0] Whether to Calculate Each Submerchant Share with Percent
77
+ * @param {Array} [payload.multiplexingInfos=[]] Multiplexing for this Transaction
78
+ * @param {Array} [payload.allowedCards=[]] Array of Allowed Full Card Numbers for this Transaction
79
+ * @return {Promise<{}>} Promise will Resolve After HTTP Call is Successful
80
+ * @example
81
+ * request({amount: 20000})
82
+ *
83
+ * */
84
+ request(configs: ZibalRequest): Promise<ZibalRequestResponse>;
85
+ /**
86
+ * Create a Payment Session
87
+ * @param {object} payload Verify Payload
88
+ * @param {string} payload.merchant IPG Merchant Id
89
+ * @param {number} [payload.trackId] IPG Transaction Track Id to be Verified
90
+ * */
91
+ verify(configs: ZibalVerify): Promise<ZibalVerifyResponse>;
92
+ }
93
+
94
+ export { Zibal };
@@ -0,0 +1,94 @@
1
+ type resultId = 100 | 102 | 103 | 104 | 105 | 106 | 113 | 140 | 201 | 202 | 203 | "-1";
2
+ type statusId = "-100" | "-1" | "-2" | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
3
+
4
+ interface ZibalRequest {
5
+ amount: number;
6
+ callbackUrl?: string;
7
+ orderId?: number;
8
+ merchant?: string;
9
+ mobile?: string;
10
+ multiplexingInfos?: any;
11
+ description?: string;
12
+ linkToPay?: boolean;
13
+ sms?: boolean;
14
+ percentMode?: number;
15
+ feeMode?: number;
16
+ allowedCards?: any;
17
+ }
18
+ interface ZibalRequestResponse {
19
+ trackId: number;
20
+ result: resultId;
21
+ message: string;
22
+ persianMessage: string;
23
+ success: boolean;
24
+ paymentUrl: string;
25
+ }
26
+ interface ZibalVerify {
27
+ trackId: number;
28
+ merchant?: string;
29
+ }
30
+ interface ZibalVerifyResponse {
31
+ message: string;
32
+ result: resultId;
33
+ refNumber: any;
34
+ paidAt: Date;
35
+ status: statusId;
36
+ amount: number;
37
+ orderId: string;
38
+ description: string;
39
+ multiplexingInfos: any[];
40
+ cardNumber: any;
41
+ persianMessage: string;
42
+ success: boolean;
43
+ }
44
+
45
+ declare class Zibal {
46
+ private merchant;
47
+ private callbackUrl;
48
+ constructor(config: {
49
+ merchant: string;
50
+ callbackUrl: string;
51
+ });
52
+ /**
53
+ * Set Merchant Id
54
+ * @param {string} merchant Your Merchant Id
55
+ * */
56
+ private setMerchant;
57
+ /**
58
+ * Initialize Zibal with Your Gateway Merchant Id
59
+ * @param {object} config Your Config Object
60
+ * @param {string} config.merchant Your Zibal Merchant Id
61
+ * @param {string} config.callbackUrl Your Callback Url
62
+ * */
63
+ private init;
64
+ /**
65
+ * Create a Payment Session
66
+ * @param {object} payload Request Payload
67
+ * @param {number} payload.amount Transaction Amount (Required)
68
+ * @param {string} [payload.merchant] Specify Merchant if you Haven't Specify in Class Config
69
+ * @param {string} [payload.callbackUrl] Url which User will be Redirected to After Payment
70
+ * @param {string} [payload.description] Transaction's Description
71
+ * @param {string} [payload.orderId] Transaction Order Id
72
+ * @param {string} [payload.mobile] User's Mobile (09123456789)
73
+ * @param {number} [payload.feeMode=0] Transaction Fee Mode
74
+ * @param {boolean} [payload.linkToPay=false] If you want us to Generate a Short Link, send this: true
75
+ * @param {boolean} [payload.sms=false] If you want us to Send the Short Link to User's Mobile, send this: true
76
+ * @param {number} [payload.percentMode=0] Whether to Calculate Each Submerchant Share with Percent
77
+ * @param {Array} [payload.multiplexingInfos=[]] Multiplexing for this Transaction
78
+ * @param {Array} [payload.allowedCards=[]] Array of Allowed Full Card Numbers for this Transaction
79
+ * @return {Promise<{}>} Promise will Resolve After HTTP Call is Successful
80
+ * @example
81
+ * request({amount: 20000})
82
+ *
83
+ * */
84
+ request(configs: ZibalRequest): Promise<ZibalRequestResponse>;
85
+ /**
86
+ * Create a Payment Session
87
+ * @param {object} payload Verify Payload
88
+ * @param {string} payload.merchant IPG Merchant Id
89
+ * @param {number} [payload.trackId] IPG Transaction Track Id to be Verified
90
+ * */
91
+ verify(configs: ZibalVerify): Promise<ZibalVerifyResponse>;
92
+ }
93
+
94
+ export { Zibal };
package/dist/index.js ADDED
@@ -0,0 +1,149 @@
1
+ // src/urls.ts
2
+ var rootAPIUrl = "https://gateway.zibal.ir/";
3
+ var urls = {
4
+ requestURL: `${rootAPIUrl}v1/request`,
5
+ startURL: `${rootAPIUrl}start/`,
6
+ verifyURL: `${rootAPIUrl}v1/verify`
7
+ };
8
+ var urls_default = {
9
+ ...urls,
10
+ getStartUrl: (trackId) => {
11
+ return `${urls.startURL}${trackId}`;
12
+ }
13
+ };
14
+
15
+ // src/index.ts
16
+ import axios from "axios";
17
+
18
+ // src/errors.ts
19
+ var results = {
20
+ 100: "\u0645\u0648\u0641\u0642",
21
+ 102: "merchant \u06CC\u0627\u0641\u062A \u0646\u0634\u062F.",
22
+ 103: "merchant \u063A\u06CC\u0631\u0641\u0639\u0627\u0644 \u0627\u0633\u062A. \u0628\u0627 \u067E\u0634\u062A\u06CC\u0628\u0627\u0646\u06CC \u062A\u0645\u0627\u0633 \u062D\u0627\u0635\u0644 \u06A9\u0646\u06CC\u062F.",
23
+ 104: "merchantId \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A.",
24
+ 105: "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u0627\u0632 1,000 \u0631\u06CC\u0627\u0644 \u0628\u0632\u0631\u06AF\u062A\u0631 \u0628\u0627\u0634\u062F",
25
+ 106: "callbackUrl \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A.",
26
+ 113: "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u0627\u0632 500,000,000 \u0631\u06CC\u0627\u0644 \u06A9\u0645\u062A\u0631 \u0628\u0627\u0634\u062F.",
27
+ 140: "callbackUrl \u0627\u0631\u0633\u0627\u0644 \u0646\u0634\u062F\u0647.",
28
+ 201: "\u0642\u0628\u0644\u0627 \u062A\u0627\u06CC\u06CC\u062F \u0634\u062F\u0647.",
29
+ 202: "\u0633\u0641\u0627\u0631\u0634 \u067E\u0631\u062F\u0627\u062E\u062A \u0646\u0634\u062F\u0647 \u06CC\u0627 \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0648\u062F\u0647 \u0627\u0633\u062A.",
30
+ 203: "trackId \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A.",
31
+ "-1": "\u062E\u0637\u0627"
32
+ };
33
+ var statuses = {
34
+ "-100": "\u062E\u0637\u0627",
35
+ "-1": "\u062F\u0631 \u0627\u0646\u062A\u0638\u0627\u0631 \u067E\u0631\u062F\u0627\u062E\u062A",
36
+ "-2": "\u062E\u0637\u0627\u06CC \u062F\u0627\u062E\u0644\u06CC",
37
+ 1: "\u067E\u0631\u062F\u0627\u062E\u062A \u0634\u062F\u0647 - \u062A\u0627\u06CC\u06CC\u062F\u0634\u062F\u0647",
38
+ 2: "\u067E\u0631\u062F\u0627\u062E\u062A \u0634\u062F\u0647 - \u062A\u0627\u06CC\u06CC\u062F\u0646\u0634\u062F\u0647",
39
+ 3: "\u0644\u063A\u0648\u0634\u062F\u0647 \u062A\u0648\u0633\u0637 \u06A9\u0627\u0631\u0628\u0631",
40
+ 4: "\u0634\u0645\u0627\u0631\u0647 \u06A9\u0627\u0631\u062A \u0646\u0627\u0645\u0639\u062A\u0628\u0631",
41
+ 5: "\u0645\u0648\u062C\u0648\u062F\u06CC \u062D\u0633\u0627\u0628 \u0646\u0627\u06A9\u0627\u0641\u06CC",
42
+ 6: "\u0631\u0645\u0632 \u0627\u0634\u062A\u0628\u0627\u0647",
43
+ 7: "\u062A\u0639\u062F\u0627\u062F \u062F\u0631\u062E\u0648\u0627\u0633\u062A\u200C\u0647\u0627 \u0628\u06CC\u0634 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632",
44
+ 8: "\u062A\u0639\u062F\u0627\u062F \u067E\u0631\u062F\u0627\u062E\u062A \u0627\u06CC\u0646\u062A\u0631\u0646\u062A\u06CC \u0631\u0648\u0632\u0627\u0646\u0647 \u0628\u06CC\u0634 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632",
45
+ 9: "\u0645\u0628\u0644\u063A \u067E\u0631\u062F\u0627\u062E\u062A \u0627\u06CC\u0646\u062A\u0631\u0646\u062A\u06CC \u0631\u0648\u0632\u0627\u0646\u0647 \u0628\u06CC\u0634 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0631",
46
+ 10: "\u0635\u0627\u062F\u0631\u06A9\u0646\u0646\u062F\u0647 \u06A9\u0627\u0631\u062A \u0646\u0627\u0645\u0639\u062A\u0628\u0631",
47
+ 11: "\u062E\u0637\u0627\u06CC \u0633\u0648\u06CC\u06CC\u0686",
48
+ 12: "\u06A9\u0627\u0631\u062A \u063A\u06CC\u0631\u0642\u0627\u0628\u0644 \u062F\u0633\u062A\u0631\u0633\u06CC"
49
+ };
50
+ var errors_default = {
51
+ getPersianMessage: (result = "-1") => {
52
+ return results[result];
53
+ },
54
+ getPersianStatus: (status = "-100") => {
55
+ return statuses[status];
56
+ }
57
+ };
58
+
59
+ // src/index.ts
60
+ var Zibal = class {
61
+ merchant = "zibal";
62
+ callbackUrl = "";
63
+ /*
64
+ * Initialize Zibal with Your Gateway Merchant Id
65
+ * @param {object} config Your Config Object
66
+ * @param {string} config.merchant Your Zibal Merchant Id
67
+ * @param {string} config.callbackUrl Your Callback Url
68
+ * */
69
+ constructor(config) {
70
+ this.init({ merchant: config.merchant, callbackUrl: config.callbackUrl });
71
+ }
72
+ /**
73
+ * Set Merchant Id
74
+ * @param {string} merchant Your Merchant Id
75
+ * */
76
+ setMerchant(merchant) {
77
+ this.merchant = merchant;
78
+ }
79
+ /**
80
+ * Initialize Zibal with Your Gateway Merchant Id
81
+ * @param {object} config Your Config Object
82
+ * @param {string} config.merchant Your Zibal Merchant Id
83
+ * @param {string} config.callbackUrl Your Callback Url
84
+ * */
85
+ init({ merchant, callbackUrl }) {
86
+ this.setMerchant(merchant);
87
+ this.callbackUrl = callbackUrl;
88
+ }
89
+ /**
90
+ * Create a Payment Session
91
+ * @param {object} payload Request Payload
92
+ * @param {number} payload.amount Transaction Amount (Required)
93
+ * @param {string} [payload.merchant] Specify Merchant if you Haven't Specify in Class Config
94
+ * @param {string} [payload.callbackUrl] Url which User will be Redirected to After Payment
95
+ * @param {string} [payload.description] Transaction's Description
96
+ * @param {string} [payload.orderId] Transaction Order Id
97
+ * @param {string} [payload.mobile] User's Mobile (09123456789)
98
+ * @param {number} [payload.feeMode=0] Transaction Fee Mode
99
+ * @param {boolean} [payload.linkToPay=false] If you want us to Generate a Short Link, send this: true
100
+ * @param {boolean} [payload.sms=false] If you want us to Send the Short Link to User's Mobile, send this: true
101
+ * @param {number} [payload.percentMode=0] Whether to Calculate Each Submerchant Share with Percent
102
+ * @param {Array} [payload.multiplexingInfos=[]] Multiplexing for this Transaction
103
+ * @param {Array} [payload.allowedCards=[]] Array of Allowed Full Card Numbers for this Transaction
104
+ * @return {Promise<{}>} Promise will Resolve After HTTP Call is Successful
105
+ * @example
106
+ * request({amount: 20000})
107
+ *
108
+ * */
109
+ async request(configs) {
110
+ configs.merchant = configs.merchant ?? this.merchant;
111
+ configs.callbackUrl = configs.callbackUrl ?? this.callbackUrl;
112
+ console.log("configs: ", configs);
113
+ const result = await axios.default.post(urls_default.requestURL, configs);
114
+ const data = result.data || {};
115
+ data.persianMessage = errors_default.getPersianMessage(data.result);
116
+ if (result.data.result !== 100) {
117
+ data.success = false;
118
+ return data;
119
+ } else {
120
+ data.success = true;
121
+ data.paymentUrl = urls_default.getStartUrl(data.trackId);
122
+ return data;
123
+ }
124
+ }
125
+ /**
126
+ * Create a Payment Session
127
+ * @param {object} payload Verify Payload
128
+ * @param {string} payload.merchant IPG Merchant Id
129
+ * @param {number} [payload.trackId] IPG Transaction Track Id to be Verified
130
+ * */
131
+ async verify(configs) {
132
+ const result = await axios.default.post(urls_default.verifyURL, {
133
+ trackId: configs.trackId,
134
+ merchant: configs.merchant ?? this.merchant
135
+ });
136
+ const data = result.data || {};
137
+ data.persianMessage = errors_default.getPersianMessage(data.result);
138
+ if (result.data.result !== 100) {
139
+ data.success = false;
140
+ return data;
141
+ } else {
142
+ data.success = true;
143
+ return data;
144
+ }
145
+ }
146
+ };
147
+ export {
148
+ Zibal
149
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "zibalts",
3
+ "version": "0.1.0",
4
+ "description": "Zibal IPG Module changed for typescript",
5
+ "main": "./dist/index.cjs",
6
+ "types": "./dist/index.d.ts",
7
+ "module": "./dist/index.js",
8
+ "type": "module",
9
+ "keywords": [
10
+ "IPG",
11
+ "Zibal",
12
+ "Payment Facilitator"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup src/index.ts --format esm,cjs --dts"
16
+ },
17
+ "exports":{
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs",
21
+ "types": "./dist/index.d.ts"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "author": "Sajjad Shahi, Shakib Mohammadi",
28
+ "license": "ISC",
29
+ "dependencies": {
30
+ "axios": "^0.21.0"
31
+ },
32
+ "devDependencies": {
33
+ "tsup": "^8.5.1",
34
+ "typescript": "5.9"
35
+ }
36
+ }
package/readme.md ADDED
@@ -0,0 +1,79 @@
1
+ # [Zibal](https://zibal.ir) IPG NPM Module
2
+
3
+ Here is Zibal's NPM Module to Easily Create and Process IPG Transactions.
4
+
5
+ ## Get Started
6
+ 1. Install Module using `npm` or `yarn`
7
+ ```
8
+ npm install zibalts --save-dev
9
+ ```
10
+ 2. Configure Module
11
+
12
+ ```typescript
13
+ import { Zibal } from "zibalts"
14
+
15
+ const zibal = new Zibal({
16
+ merchant: "YOUR_MERCHANT", // Your IPG's Merchant Id (You Can Get it From Zibal's Dashboard)
17
+ callbackUrl: "https://yourwebsite.com/ipg/cb" // The URL Where User will be Redirected to After Payment
18
+ })
19
+ ```
20
+
21
+ You can Configure These Two Parameters for Each Transaction Too.
22
+
23
+ You can Specify `merchant: zibal` to Perform Sandbox Transactions.
24
+
25
+ 3. Create IPG Transaction
26
+ ```typescript
27
+ try{
28
+ const result = await zibal.request({
29
+ amount: 200000, // Required - In Rials
30
+ orderId: "ZBL-aaaa", // Optional
31
+ merchant: "YOUR_MERCHANT", // As Said Above, You can Specify merchant for Each Transaction too.
32
+ callbackUrl: "https://yourwebsite.com/ipg/cb", // As Said Above, You can Specify merchant for Each Transaction too.
33
+ mobile: "09123456789", // Optional - User's Card Numbers will Show inf Dropdown in Shaparak Page if you Send User's Mobile
34
+ description: "THIS IS MY DESCRIPTION", // Optional
35
+ allowedCards: ["5022291092719457"], // Optional - Any Transaction with a Card Number which is not Present in this Array will be Unsuccessful
36
+ linkToPay: true, // Optional - If true, we will generate a Short Link for this transaction.
37
+ sms: true, // Optional - If true, we will Send the Short Link to User's Mobile
38
+ })
39
+
40
+
41
+ // Redirect User to Payment URL after Creating Transaction
42
+ // res.redirect is for Express Framework
43
+ // Store response.trackId Somewhere too
44
+ res.redirect(result.paymentUrl)
45
+ }catch(e:any){
46
+ // show some error
47
+ }
48
+
49
+ ```
50
+
51
+ See [Documentation](https://docs.zibal.ir/IPG/API) For More Features.
52
+
53
+ 4. Catch Data in Callback
54
+
55
+ User will be Redirected to `callbackUrl` you Have Sent in Request. We Will Specify Transaction Information in Query Strings Link:
56
+
57
+ `https://yourwebsite.com/ipg/cb?trackId=10000&success=1&status=2&orderId=1`
58
+
59
+ You Shall Catch it in Your Application (ExpressJS, Koa, Hapi, Loopback, Sails, Meteor etc.) and Verify the Transactions if `success === true && status === 2` and Process Your Order for your Customer.
60
+
61
+ 5. Verify Transaction
62
+
63
+ Here you Should Tell Us that You Got the Transaction Information & Verify it.
64
+
65
+ ```typescript
66
+ try{
67
+ const result = await zibal.verify({
68
+ trackId: 100000, // Required - Transaction's trackId Which we Specify in callback.
69
+ merchant: "YOUR_MERCHANT", // As Said Above, You can Specify merchant for Each Transaction too.
70
+ })
71
+ // ALL SET AND DONE
72
+ }catch(e:any){
73
+ // SHOW SOME ERROR
74
+ }
75
+ ```
76
+
77
+ 6. Done
78
+
79
+ Your Website is now Connected to Zibal IPG! Enjoy and Have Fun.