|  | 
| 1 |  | -# pay.ir node.js typescript library | 
|  | 1 | +# pay.ir node.js typescript module | 
|  | 2 | + | 
|  | 3 | +## what is | 
|  | 4 | + | 
|  | 5 | +By using this package, you'll be able to work with Pay.ir REST Api in Node.js (Back-End) without any problem! This package is usable for all Node.js Frameworks such as Express.js, Hapi.js, Sails.js, Adonis.js or others. | 
|  | 6 | + | 
|  | 7 | +This package is written in Typescript and targets ES6. the main difference between this package and [official](https://github.com/erfansahaf/payir) one is the typings and readability. I rewrote everything from scratch and added the much needed improvements to the original package. | 
|  | 8 | +so even if you don't use the typescript to write your app the improvements must be clear. | 
|  | 9 | + | 
|  | 10 | +## improvements | 
|  | 11 | + | 
|  | 12 | +- typings. get assist from IDEs when writing your code. | 
|  | 13 | +- better networking. this library uses [Axios](https://github.com/axios/axios) for networking and error handling is much more to my liking. | 
|  | 14 | +- smaller code due to better error handling | 
|  | 15 | + | 
|  | 16 | +## Installing | 
|  | 17 | + | 
|  | 18 | +first you need to pass your API key to the constructor. | 
|  | 19 | + | 
|  | 20 | +Using npm: | 
|  | 21 | + | 
|  | 22 | +```bash | 
|  | 23 | +npm install axios | 
|  | 24 | +``` | 
|  | 25 | + | 
|  | 26 | +## Example | 
|  | 27 | + | 
|  | 28 | +import library using | 
|  | 29 | + | 
|  | 30 | +```javascript | 
|  | 31 | +const Pay = require('payir-typescript'); | 
|  | 32 | +``` | 
|  | 33 | + | 
|  | 34 | +or: | 
|  | 35 | + | 
|  | 36 | +```javascript | 
|  | 37 | +import PayIrTypescript from 'payir-typescript'; | 
|  | 38 | +``` | 
|  | 39 | + | 
|  | 40 | +then pass the API key to the constructor | 
|  | 41 | + | 
|  | 42 | +```javascript | 
|  | 43 | +const pay = new PayIrTypescript(APIKEY); | 
|  | 44 | +``` | 
|  | 45 | + | 
|  | 46 | +now you can use the following methods on the pay instance | 
|  | 47 | + | 
|  | 48 | +### Send | 
|  | 49 | + | 
|  | 50 | +this method accepts payment parameters as an object and returns a promise. | 
|  | 51 | + | 
|  | 52 | +```javascript | 
|  | 53 | +pay | 
|  | 54 | +  .send({ | 
|  | 55 | +    amount: AMOUNT, | 
|  | 56 | +    redirect: REDIRECT_URL | 
|  | 57 | +  }) | 
|  | 58 | +  .then(item => { | 
|  | 59 | +    const val = <string>item; | 
|  | 60 | +    console.log(val); | 
|  | 61 | +  }) | 
|  | 62 | +  .catch(e => console.log(e)); | 
|  | 63 | +``` | 
|  | 64 | + | 
|  | 65 | +or using `async/await` we can have | 
|  | 66 | + | 
|  | 67 | +```javascript | 
|  | 68 | +const payment = await pay.send({ | 
|  | 69 | +  amount: AMOUNT, | 
|  | 70 | +  redirect: REDIRECT_URL | 
|  | 71 | +}); | 
|  | 72 | +``` | 
|  | 73 | + | 
|  | 74 | +full list of parameters accepted are listed in [pay.ir](https://pay.ir/docs/gateway/). | 
|  | 75 | + | 
|  | 76 | +### Verify | 
|  | 77 | + | 
|  | 78 | +this method accepts verify parameters as an object and returns a promise. | 
|  | 79 | + | 
|  | 80 | +```javascript | 
|  | 81 | +pay | 
|  | 82 | +  .verify({ | 
|  | 83 | +    token: 'token' | 
|  | 84 | +  }) | 
|  | 85 | +  .then(item => console.log(item)) | 
|  | 86 | +  .catch(e => console.log(e)); | 
|  | 87 | +``` | 
|  | 88 | + | 
|  | 89 | +or using `async/await` we can have | 
|  | 90 | + | 
|  | 91 | +```javascript | 
|  | 92 | +const payment = await pay.verify({ | 
|  | 93 | +  token: 'token' | 
|  | 94 | +}); | 
|  | 95 | +``` | 
|  | 96 | + | 
|  | 97 | +full list of parameters accepted are listed in [pay.ir](https://pay.ir/docs/gateway/). | 
0 commit comments