|
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 |
2 | 3 |
|
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 |
4 | 16 | ```js |
| 17 | +// Tip! Initialize this property in your payment service constructor method! |
5 | 18 | 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"); |
6 | 26 |
|
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": " " |
18 | 86 | } |
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) |
0 commit comments