Skip to content

Commit 79f6a7c

Browse files
committed
main functionality added
1 parent 864a78c commit 79f6a7c

4 files changed

Lines changed: 227 additions & 16 deletions

File tree

CHANGELIST.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Change Log
2+
All notable changes to this project is documented in this file.
3+
4+
# v0.2.2 - 2021 14 Aug (main functionality)
5+
### Added
6+
- checkTransaction() method
7+
- verifyPayment() method
8+
- refundPayment() method
9+
### Changes
10+
- `URL_REFUND` address changed to correct value.
11+
112
# v0.1.0 (dev/main)
213
- initializing main structure
314
- initializing requestBuilder

README.md

Lines changed: 139 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,144 @@
1-
# NodeJS SDK for Pasargad
1+
# NodeJS SDK for Pasargad IPG
2+
NodeJS package to connect your application to Pasargad Internet Payment Gateway through RESTful API
23

3-
## Redirect To payment
4+
# Installation
5+
For installation, use `npm` package:
6+
7+
```bash
8+
$ npm install @pepco/nodejs-rest-sdk
9+
```
10+
11+
# Usage
12+
- To Read API Documentation, [Click Here! (دانلود مستندات کامل درگاه پرداخت)](https://www.pep.co.ir/wp-content/uploads/2019/06/1-__PEP_IPG_REST-13971020.Ver3_.00.pdf)
13+
- Save your private key into an `.xml` file inside your project directory.
14+
15+
## Redirect User to Payment Gateway
416
```js
17+
// Tip! Initialize this property in your payment service constructor method!
518
const PasargadApi = require('@pepco/nodejs-rest-sdk');
19+
const pasargad = new PasargadApi(
20+
"YOUR_MERCHANT_CODE",
21+
"YOUR_TERMINAL_ID",
22+
"http://yoursite.com/redirect-url-here/",
23+
"certificate_file_location.xml");
24+
//e.q:
25+
// const pasargad = new PasargadApi(xxxxxx,xxxxx,"https://pep.co.ir/ipgtest","cert.xml");
626

7-
const pasargad = new PasargadApi(xxxxxx,xxxxx,"https://pep.co.ir/ipgtest","cert.xml");
8-
try {
9-
pasargad.amount = 10000;
10-
pasargad.invoiceNumber = "5002";
11-
pasargad.invoiceDate = "2021/08/12 17:31:00";
12-
pasargad.redirect().then(redirectUrl => {
13-
// redirect Here
14-
console.log(redirectUrl);
15-
});
16-
} catch(e) {
17-
throw e;
27+
// Set Amount
28+
pasargad.amount = 15000;
29+
30+
// Set Invoice Number (it MUST BE UNIQUE)
31+
pasargad.invoiceNumber = "4029";
32+
33+
// set Invoice Date with below format (Y/m/d H:i:s)
34+
pasargad.invoiceDate = "2021/08/08 11:54:03";
35+
36+
// get the Generated RedirectUrl from Pasargad API (async request):
37+
// output example: https://pep.shaparak.ir/payment.aspx?n=bPo+Z8GLB4oh5W0KVNohihxCu1qBB3kziabGvO1xqg8Y=
38+
pasargad.redirect().then(redirectURL => {
39+
// redirect user to `redirectURL`
40+
console.log(redirectURL);
41+
});
42+
```
43+
44+
## Checking and Verifying Transaction
45+
After Payment Process, User is going to be returned to your redirect_url.
46+
47+
payment gateway is going to answer the payment result with sending below parameters to your redirectURL (as `QueryString` parameters):
48+
- InvoiceNumber (IN field)
49+
- InvoiceDate (ID field)
50+
- TransactionReferenceID (tref field)
51+
52+
Store this information in a proper data storage and let's check transaction result by sending a check api request to the Bank:
53+
54+
```js
55+
// Set Transaction refrence id received in
56+
pasargad.transactionReferenceID = "636843820118990203";
57+
58+
// Set Unique Invoice Number that you want to check the result
59+
pasargad.invoiceNumber = 4029;
60+
61+
// set Invoice Date of your Invoice
62+
pasargad.invoiceDate = "2021/08/08 11:54:03";
63+
64+
// check Transaction result
65+
pasargad.checkTransaction().then(response => {
66+
// you can handle the response here:
67+
console.log(response);
68+
});
69+
```
70+
71+
Successful result:
72+
```json
73+
{
74+
"TraceNumber": 13,
75+
"ReferenceNumber": 100200300400500,
76+
"TransactionDate": "2021/08/08 11:58:23",
77+
"Action": "1003",
78+
"TransactionReferenceID": "636843820118990203",
79+
"InvoiceNumber": "4029",
80+
"InvoiceDate": "2021/08/08 11:54:03",
81+
"MerchantCode": 100123,
82+
"TerminalCode": 200123,
83+
"Amount": 15000,
84+
"IsSuccess": true,
85+
"Message": " "
1886
}
19-
```
87+
```
88+
If you got `IsSuccess` with `true` value, so everything is O.K!
89+
90+
Now, for your successful transaction, you should call `verifyPayment()` method to keep the money and Bank makes sure the checking process was done properly:
91+
92+
93+
```js
94+
// Set Amount
95+
pasargad.amount = 15000;
96+
97+
// Set Invoice Number (it MUST BE UNIQUE)
98+
pasargad.invoiceNumber = "4029";
99+
100+
// set Invoice Date with below format (Y/m/d H:i:s)
101+
pasargad.invoiceDate = "2021/08/08 11:54:03";
102+
103+
// verify payment:
104+
pasargad.verifyPayment().then(response => {
105+
// response
106+
console.log(response);
107+
});
108+
```
109+
110+
...and the successful response looks like this response:
111+
```json
112+
{
113+
"IsSuccess": true,
114+
"Message": " ",
115+
"MaskedCardNumber": "5022-29**-****-2328",
116+
"HashedCardNumber": "2DDB1E270C598677AE328AA37C2970E3075E1DB6665C5AAFD131C59F7FAD99F23680536B07C140D24AAD8355EA9725A5493AC48E0F48E39D50B54DB906958182",
117+
"ShaparakRefNumber": "100200300400500"
118+
}
119+
120+
```
121+
122+
## Payment Refund
123+
If for any reason, you decided to cancel an order in early hours after taking the order (maximum 2 hours later), you can refund the client payment to his/her bank card.
124+
125+
for this, use `refundPayment()` method:
126+
127+
```js
128+
// Set Unique Invoice Number that you want to check the result
129+
pasargad.invoiceNumber = "4029";
130+
131+
// set Invoice Date of your Invoice
132+
pasargad.invoiceDate = "2021/08/08 11:54:03";
133+
134+
// check Transaction result
135+
pasargad.refundPayment().then(response => {
136+
// handle response here:
137+
console.log(response);
138+
});
139+
```
140+
141+
# Support
142+
Please use your credentials to login into [Support Panel](https://my.pep.co.ir)
143+
144+
Contact Author/Maintainer: [Reza Seyf](https://twitter.com/seyfcode)

lib/Pasargad.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const URL_GET_TOKEN = "https://pep.shaparak.ir/Api/v1/Payment/GetToken";
1515

1616
const URL_CHECK_TRANSACTION = 'https://pep.shaparak.ir/Api/v1/Payment/CheckTransactionResult';
1717
const URL_VERIFY_PAYMENT = 'https://pep.shaparak.ir/Api/v1/Payment/VerifyPayment';
18-
const URL_REFUND = 'https://pep.shaparak.ir/Api/v1/Payment/VerifyPayment';
18+
const URL_REFUND = 'https://pep.shaparak.ir/Api/v1/Payment/RefundPayment';
1919

2020

2121

@@ -89,6 +89,17 @@ module.exports = class Pasargad
8989
}
9090

9191

92+
93+
/**
94+
* payment reference id setter
95+
*
96+
* @param {string} transactionReferenceID Payment reference id
97+
*/
98+
set transactionReferenceID (transactionReferenceID) {
99+
this._transactionReferenceID = transactionReferenceID;
100+
}
101+
102+
92103
/**
93104
* invoiceDate setter
94105
*
@@ -225,4 +236,68 @@ module.exports = class Pasargad
225236
};
226237
return this.getToken(params);
227238
}
239+
240+
241+
async checkTransaction() {
242+
const params = {
243+
transactionReferenceID: this._transactionReferenceID,
244+
invoiceNumber: this._invoiceNumber,
245+
invoiceDate: this._invoiceDate,
246+
merchantCode: `${this._merchantcode}`,
247+
terminalCode: `${this._terminalId}`
248+
};
249+
this.signData(params);
250+
let response;
251+
await this._requestBuilder({
252+
url: URL_CHECK_TRANSACTION,
253+
method: "POST",
254+
body: (JSON.stringify(params))
255+
}).then(data => {
256+
response = data;
257+
});
258+
return response;
259+
}
260+
261+
async verifyPayment()
262+
{
263+
const params = {
264+
amount: this._amount,
265+
invoiceNumber: this._invoiceNumber,
266+
invoiceDate: this._invoiceDate,
267+
merchantCode: `${this._merchantcode}`,
268+
terminalCode: `${this._terminalId}`,
269+
timeStamp: this.getTimestamp()
270+
};
271+
this.signData(params);
272+
let response;
273+
await this._requestBuilder({
274+
url: URL_VERIFY_PAYMENT,
275+
method: "POST",
276+
body: (JSON.stringify(params))
277+
}).then(data => {
278+
response = data;
279+
});
280+
return response;
281+
}
282+
283+
async refundPayment()
284+
{
285+
const params = {
286+
invoiceNumber: this._invoiceNumber,
287+
invoiceDate: this._invoiceDate,
288+
merchantCode: `${this._merchantcode}`,
289+
terminalCode: `${this._terminalId}`,
290+
timeStamp: this.getTimestamp()
291+
};
292+
this.signData(params);
293+
let response;
294+
await this._requestBuilder({
295+
url: URL_REFUND,
296+
method: "POST",
297+
body: (JSON.stringify(params))
298+
}).then(data => {
299+
response = data;
300+
});
301+
return response;
302+
}
228303
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pepco/nodejs-rest-sdk",
3-
"version": "0.1.0",
3+
"version": "0.2.2",
44
"description": "NodeJS package to connect your application to Pasargad Bank Internet Payment Gateway through RESTful API",
55
"homepage": "https://github.com/pepco-api/nodejs-rest-sdk-sdk",
66
"repository": {

0 commit comments

Comments
 (0)