Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #58

Closed
wants to merge 60 commits into from
Closed

V2 #58

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0cac080
chore: Upgrade deps
alitnk Sep 10, 2022
a7ac151
feat: Start using zod
alitnk Sep 10, 2022
2bb1268
fix: Remove remaining io-ts usage
alitnk Sep 10, 2022
e861a53
refactor: Removing tests dir, changing imports
alitnk Sep 10, 2022
2ab88ee
Change private key format in Pasargad API
Keivan-sf Sep 11, 2022
49cedae
Accept and convert `xml` key for Pasargad
Keivan-sf Sep 11, 2022
1012584
Merge pull request #32 from Keivan-sf/v2
alitnk Sep 11, 2022
66494b5
fix: Issue with imports
alitnk Sep 13, 2022
37ef308
feat: Move from classes to factory functions
alitnk Sep 13, 2022
72a81e8
fix: Add back requestPayment and verifyPayment
alitnk Sep 13, 2022
56a9c65
Add `buildRedirectScript` utility
Keivan-sf Sep 13, 2022
24f7b64
refactor: Move tests' driver creation to beforeAll
alitnk Sep 13, 2022
38d5f9e
Merge branch '25-remove-classes' of https://github.com/alitnk/monopay…
alitnk Sep 13, 2022
80db71c
refactor: Rename BaseReceipt to just Receipt
alitnk Sep 13, 2022
bf6a5b8
Merge pull request #33 from alitnk/25-remove-classes
alitnk Sep 13, 2022
308bce5
refactor: Update examples structure
alitnk Sep 13, 2022
d26ab0d
feat: NestJS support, moving from yarn to npm
alitnk Sep 13, 2022
301b245
fix: Remove yarn.lock
alitnk Sep 13, 2022
7ed90c4
fix: Type issue with MonopayOptions
alitnk Sep 13, 2022
06ba7f6
test: Add test for NestJS integration
alitnk Sep 13, 2022
f76ef73
Fix broken links
Keivan-sf Sep 14, 2022
29b08f4
Merge pull request #38 from alitnk/fix-example-links
alitnk Sep 14, 2022
c89ee05
fix: Type-safety issue with getDriver on NestJS
alitnk Sep 14, 2022
ed75d9d
Create `MonopayError` abstract class
Keivan-sf Sep 15, 2022
b768706
fix: Export driver and api types
alitnk Sep 15, 2022
0a2bafb
Throw `BadConfigError` on wrong schemas
Keivan-sf Sep 15, 2022
3346419
resolves #41: Fix Behpardakht error codes bug
Keivan-sf Sep 15, 2022
1253dfa
Throw `BadConfigError` for Behpardakht IPG
Keivan-sf Sep 15, 2022
d58cafa
Throw `BadConfigError` for IdPay IPG
Keivan-sf Sep 15, 2022
f32c622
Add `callBackErrors` to idPay IPG config errors
Keivan-sf Sep 15, 2022
8f2d4be
Throw `BadConfigError` for Nextpay IPG
Keivan-sf Sep 15, 2022
f4ca9f9
feat: NestJS example + improve on nestjs integ
alitnk Sep 15, 2022
3730ced
Merge pull request #39 from alitnk/26-nestjs-support
alitnk Sep 15, 2022
781ce14
Add bad IP error code to `IPGConfigErrors`
Keivan-sf Sep 16, 2022
265b579
Throw `BadConfigError` for Payir IPG
Keivan-sf Sep 16, 2022
67fbc68
Throw `BadConfigError` for Sadad IPG
Keivan-sf Sep 16, 2022
e94332b
Throw `BadConfigError` for Saman IPG
Keivan-sf Sep 16, 2022
df12b22
Throw `BadConfigError` for Zarinpal IPG
Keivan-sf Sep 16, 2022
e4b180a
Throw `BadConfigError` for Zibal IPG
Keivan-sf Sep 16, 2022
a71201e
Fix `BadConfigError` for Zibal IPG
Keivan-sf Sep 16, 2022
a16bc8f
Add `UserError` to exceptions
Keivan-sf Sep 17, 2022
b13ca2a
Throw `UserError` for Behpardakht IPG
Keivan-sf Sep 17, 2022
f2d0d30
Throw `UserError` for Idpay IPG
Keivan-sf Sep 17, 2022
a3b308d
Throw `UserError` for Nextpay IPG
Keivan-sf Sep 17, 2022
6300f44
Remove unrelated codes from payir `IPGConfigErros`
Keivan-sf Sep 17, 2022
91ec21c
Throw `UserError` for Payir IPG
Keivan-sf Sep 17, 2022
f3c7016
Throw `UserError` for Saman IPG
Keivan-sf Sep 17, 2022
6d2e8df
Throw `UserError` for Zarinpal IPG
Keivan-sf Sep 17, 2022
17054fe
Throw `UserError` for Zibal IPG
Keivan-sf Sep 17, 2022
a155fcc
Throw `BadConfigError` for signing failure
Keivan-sf Sep 17, 2022
abc6658
Add `GatewayFailureError` to exceptions
Keivan-sf Sep 17, 2022
6e87197
Make `GatewayFailureError` message optional
Keivan-sf Sep 17, 2022
747a8a5
Throw `GatewayFailureError` in all drivers
Keivan-sf Sep 17, 2022
cf31a95
typo: fix `RequestPaymentRes_Successful`
Keivan-sf Sep 17, 2022
55d8fbe
refactor: Avoid long constructor calls in `throwError`
Keivan-sf Sep 17, 2022
bda6c7c
Remove old error handling classes
Keivan-sf Sep 17, 2022
3f4264d
Include error code in `MonopayError`
Keivan-sf Sep 18, 2022
4931574
Merge pull request #42 from alitnk/error-handling
alitnk Sep 18, 2022
d0f8d51
Disable eslint ts comment rule for test files
Keivan-sf Sep 18, 2022
181bdc2
Merge pull request #43 from alitnk/disable-test-eslint
Keivan-sf Sep 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ yarn add monopay
### Getting a payment driver

```javascript
const driver = getPaymentDriver('zibal', {
const driver = getPaymentDriver('zibal')({
merchantId: 'merchant-id',
sandbox: true,
});
Expand All @@ -56,7 +56,7 @@ const driver = getPaymentDriver('zibal', {
### Requesting for payment

```javascript
const paymentInfo = await driver.requestPayment({
const paymentInfo = await driver.request({
amount: 200000, // IRR
callbackUrl: 'mysite.com/callback',
});
Expand All @@ -66,12 +66,12 @@ const paymentInfo = await driver.requestPayment({

```javascript
app.all('/callback', async (req, res) => {
const receipt = await driver.verifyPayment(
const receipt = await driver.verify(
{
amount: 200000, // IRR
referenceId: 1234,
},
{ ...req.query, ...req.body }
{ ...req.query, ...req.body },
);

res.json({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# مثال استفاده از Express

دیدن این داکیومنت به [انگلیسی(English)](/examples/express-example/README.md)
دیدن این داکیومنت به [انگلیسی (English)](/examples/express-javascript/README.md)

دو مسیر زیر در این مثال تعریف شده اند:

1. `/purchase`: ارسال درخواست پرداخت به بانک پذیرنده و انتقال کاربر به درگاه پرداخت
2. `/callback`: دریافت اطلاعات و نتیجه پرداخت از بانک پذیرنده و ارزیابی آن

> نکته: برای تست کردن این مثال همراه SSL میتوانید از وبسایت [ngrok.com](https://ngrok.com) استفاده کنید و سپس ادرس ngrok خود را در فایل `.env` جایگذاری کنید.
> نکته: برای تست کردن این مثال همراه SSL میتوانید از وبسایت [ngrok.com](https://ngrok.com) استفاده کنید و سپس ادرس ngrok خود را در فایل `.env` جایگذاری کنید.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Example using Express

Switch to [persian (فارسی)](/examples/express-example/READMEfa.md)
Switch to [Persian (فارسی)](/examples/express-javascript/README-fa.md)

There are two routes in this example:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const chosenDriver = 'nextpay';
*/
app.get('/purchase', async (req, res) => {
try {
const driver = getPaymentDriver(chosenDriver, monopayConfiguration[chosenDriver]);
const driver = getPaymentDriver(chosenDriver)(monopayConfiguration[chosenDriver]);

const paymentInfo = await driver.requestPayment({
const paymentInfo = await driver.request({
amount: 20000,
callbackUrl: process.env.APP_URL + '/callback',
});
Expand All @@ -69,13 +69,13 @@ app.get('/purchase', async (req, res) => {
});

/**
* The callback URL that was given to `requestPayment`
* The callback URL that was given to `request`
*/
app.all('/callback', async (req, res) => {
try {
const driver = getPaymentDriver(chosenDriver, monopayConfiguration[chosenDriver]);
const driver = getPaymentDriver(chosenDriver)(monopayConfiguration[chosenDriver]);

const receipt = await driver.verifyPayment(
const receipt = await driver.verify(
{
amount: db.amount, // from database
referenceId: db.paymentID, // from database
Expand Down
10 changes: 10 additions & 0 deletions examples/express-typescript/README-fa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# مثال استفاده از Express

دیدن این داکیومنت به [انگلیسی (English)](/examples/express-typescript/README.md)

دو مسیر زیر در این مثال تعریف شده اند:

1. `/purchase`: ارسال درخواست پرداخت به بانک پذیرنده و انتقال کاربر به درگاه پرداخت
2. `/callback`: دریافت اطلاعات و نتیجه پرداخت از بانک پذیرنده و ارزیابی آن

> نکته: برای تست کردن این مثال همراه SSL میتوانید از وبسایت [ngrok.com](https://ngrok.com) استفاده کنید و سپس ادرس ngrok خود را در فایل `.env` جایگذاری کنید.
10 changes: 10 additions & 0 deletions examples/express-typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Example using Express

Switch to [Persian (فارسی)](/examples/express-typescript/README-fa.md)

There are two routes in this example:

1. `/purchase`: requests the payment and then sends the user to the payment gateway
2. `/callback`: receives the data from the gateway and verifies it

> Note: in order to test this example with SSL, you can use [ngrok.com](https://ngrok.com) and add your ngrok url to the `.env` file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPaymentDriver, ConfigObject, DriverName } from 'monopay';
import { config } from 'dotenv';
import express from 'express';
import { ConfigObject, DriverName, getPaymentDriver } from 'monopay';
config();
const app = express();
const port = 3000;
Expand Down Expand Up @@ -42,9 +42,9 @@ const chosenDriver: DriverName = 'nextpay';
*/
app.get('/purchase', async (req, res) => {
try {
const driver = getPaymentDriver(chosenDriver, monopayConfiguration[chosenDriver]);
const driver = getPaymentDriver(chosenDriver)(monopayConfiguration[chosenDriver]);

const paymentInfo = await driver.requestPayment({
const paymentInfo = await driver.request({
amount: 20000,
callbackUrl: process.env.APP_URL + '/callback',
});
Expand All @@ -65,13 +65,13 @@ app.get('/purchase', async (req, res) => {
});

/**
* The callback URL that was given to `requestPayment`
* The callback URL that was given to `request`
*/
app.all('/callback', async (req, res) => {
try {
const driver = getPaymentDriver(chosenDriver, monopayConfiguration[chosenDriver]);
const driver = getPaymentDriver(chosenDriver)(monopayConfiguration[chosenDriver]);

const receipt = await driver.verifyPayment(
const receipt = await driver.verify(
{
amount: db.amount, // from database
referenceId: db.paymentID, // from database
Expand Down
25 changes: 25 additions & 0 deletions examples/nestjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
Loading