webpay-bahamta
Advanced tools
Comparing version 1.0.1 to 1.0.2
97
index.js
"use strict"; | ||
const axios = require('axios').default; | ||
const pjson = require('./package.json'); | ||
const BASE_URL = 'https://webpay.bahamta.com/api'; | ||
const DOCS_URL = 'https://webpay.bahamta.com/doc/api'; | ||
const USER_AGENT = `Webpay NodeJS Library - ${pjson.version}`; | ||
axios.interceptors.response.use( | ||
response => { | ||
return response; | ||
}, | ||
error => { | ||
if(!error.response) | ||
error.response = { | ||
data: { ok: false, error: 'NETWORK_ERROR', apidoc: DOCS_URL}, | ||
status: 500, | ||
}; | ||
return Promise.reject(error.response); | ||
} | ||
); | ||
const serverCall = config => { | ||
config.headers = { | ||
"user-agent": USER_AGENT, | ||
}; | ||
config.baseURL = BASE_URL; | ||
config.timeout = 60 * .5 * 1000; // Let's say you want to wait at least .5 mins | ||
return axios(config); | ||
}; | ||
/** | ||
* @param {string} api_key - The bahamta api-key: 'webpay:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz' | ||
* @param {string} reference - The order number (should be unique): 'order#1004' | ||
* @param {number} amount_irr - The amount of money in Rials: 100000 | ||
* @param {string} callback_url - Call back url for bahamta recall (should start with http or https) : 'https://mydomain.ir/checkout/order#1004' | ||
* @param {string} payer_mobile - The payer mobile number: '98912*******' | ||
* @param {string} trusted_pan - The trusted credit cards number list: '6219234531241234,623254******5645,5453612376879876' | ||
* @returns {Promise} Promise object represents server response success=({ok: true, result}), failure = ({ok: false, error}) | ||
*/ | ||
const payment = async ( | ||
api_key, | ||
reference, | ||
amount_irr, | ||
callback_url, | ||
payer_mobile = null, | ||
trusted_pan = null | ||
) => { | ||
try { | ||
let params = { | ||
api_key, | ||
reference, | ||
amount_irr, | ||
callback_url, | ||
payer_mobile, | ||
trusted_pan | ||
}; | ||
const response = await serverCall({method: 'GET', url:`/create_request`, params: params}); | ||
return response.data; | ||
} catch (error) { | ||
return {...response.data, apidoc: DOCS_URL}; | ||
} | ||
} | ||
/** | ||
* @param {string} api_key - The bahamta api-key: 'webpay:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz' | ||
* @param {string} reference - The order number (should be unique): 'order#1004' | ||
* @param {number} amount_irr - The amount of money in Rials: 100000 | ||
* @returns {Promise} Promise object represents server response success=({ok: true, result}), failure = ({ok: false, error}) | ||
*/ | ||
const verify = async ( | ||
api_key, | ||
reference, | ||
amount_irr | ||
) => { | ||
try { | ||
let params = { | ||
api_key, | ||
reference, | ||
amount_irr | ||
}; | ||
const response = await serverCall({method: 'GET', url:`/confirm_payment`, params}); | ||
return response.data; | ||
} catch (error) { | ||
return {...response.data, apidoc: DOCS_URL}; | ||
} | ||
} | ||
module.exports = { | ||
payment : payment, | ||
verify : verify | ||
}; | ||
module.exports = require('./lib/webpay'); |
{ | ||
"name": "webpay-bahamta", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "This a lib to handle payment from bahamta", | ||
@@ -8,2 +8,3 @@ "author": "Hossein Rashidi", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"repository": { | ||
@@ -25,3 +26,7 @@ "type": "git", | ||
"axios": "^0.21.1" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^8.2.0", | ||
"typescript": "^4.2.4" | ||
} | ||
} |
@@ -63,12 +63,12 @@ [![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/hrashidi/webpay-bahamta)](https://github.com/hrashidi/webpay-bahamta/releases/latest) | ||
{ | ||
"state": "paid", | ||
"total": 1000000, | ||
"wage": 5000, | ||
"gateway": "sep", | ||
"terminal": "11223344", | ||
"pay_ref": "GmshtyjwKSu5lKOLquYrzO9BqjUMb/TPUK0qak/iVs", | ||
"pay_trace": "935041", | ||
"pay_pan": "123456******1234", | ||
"pay_cid": "77CB1B455FB5F60415A7A02E4502134CFD72DBF6D1EC8FA2B48467DFB124AA75A", | ||
"pay_time": "2019-11-12T16:39:57.686436+03:30" | ||
"state": "paid", | ||
"total": 1000000, | ||
"wage": 5000, | ||
"gateway": "sep", | ||
"terminal": "11223344", | ||
"pay_ref": "GmshtyjwKSu5lKOLquYrzO9BqjUMb/TPUK0qak/iVs", | ||
"pay_trace": "935041", | ||
"pay_pan": "123456******1234", | ||
"pay_cid": "77CB1B455FB5F60415A7A02E4502134CFD72DBF6D1EC8FA2B48467DFB124AA75A", | ||
"pay_time": "2019-11-12T16:39:57.686436+03:30" | ||
} | ||
@@ -75,0 +75,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10102
7
190
2
1
1