Using npm:
$ npm install --save zibal
In Node.js:
// Load the full build.
const Zibal = require('zibal');
// Initialize with configurations
Zibal.init({
merchant: 'YOUR-MERCHANT-ID',
callbackUrl: 'https://some-callback-url.tld',
logLevel: 2
// 0: none (default in production)
// 1: error
// 2: error + info (default)
});
// Payment Request
Zibal.request(1500)
.then((result) => {
console.log(result);
// { trackId: 1533727744287, result: 100, message: 'success', statusMessage: 'با موفقیت تایید شد.' }
}).catch((err) => {
console.error(err);
// { result: 103, message: 'authentication error', statusMessage: '{merchant} غیرفعال' }
});
// Payment Start URL
const url = Zibal.startURL(1533727744287);
// >> then open url in browser
// Payment Verify
Zibal.verify(1533727744287)
.then((result) => {
console.log(result);
// { paidAt: '2018-03-25T23:43:01.053000', amount: 1600, result: 100, status: 1, message : 'success', statusMessage: 'با موفقیت تایید شد.' }
}).catch((err) => {
console.error(err);
// { result: 103, message: 'authentication error', statusMessage: '{merchant} غیرفعال' }
});
init(**config**)
- init usingconfig
objectupdate(**config**)
- update config usingconfig
objectrequest(**amount, extras**)
- request payment usingamount: Number
andextras
object - returns aPromise
ofrequest
objectstartURL(**trackId**)
- get payment url usingtrackId: Number
fromrequest
object - returns aString
of payment urlverify(**trackId**)
- verify payment usingtrackId: Number
fromrequest
object - returns aPromise
ofverify
object
-
config
:merchant: String
- your merchant idcallbackUrl: String
- your callback urllogLevel: Number
- desired log level:0
: none (default in production)1
: error2
: error + info (default)
-
extras
:mobile: String
description: String
multiplexingInfos
feeMode
percentMode
-
request
Response:trackId: Number
- payment idresult: Number
- result status codemessage: String
- status short messagestatusMessage: String
- user friendly status message
-
verify
Resopnse:paidAt: Date
- payment timeamount: Number
- payment amountresult: Number
- payment status codemessage: String
- status short messagestatusMessage: String
- user friendly status message