-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
99 lines (86 loc) · 2.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
var express = require('express'),
ZarinpalCheckout = require('zarinpal-checkout'),
bodyParser = require('body-parser'),
app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
/**
* Initial ZarinPal module.
* @param {String} 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' [MerchantID]
* @param {bool} false [toggle `Sandbox` mode]
*/
var zarinpal = ZarinpalCheckout.create('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', true);
/**
* Route: PaymentRequest [module]
* @return {String} URL [Payement Authority]
*/
app.get('/PaymentRequest', function(req, res) {
zarinpal.PaymentRequest({
Amount: '1000',
CallbackURL: 'http://siamak.us',
Description: 'Hello NodeJS API.',
Email: '[email protected]',
Mobile: '09120000000'
}).then(function (response) {
if (response.status == 100) {
res.redirect(response.url);
}
}).catch(function (err) {
console.log(err);
});
});
/**
* Route: PaymentVerification [module]
* @return {number} RefID [Check Paymenet state]
*/
app.get('/PaymentVerification/:amount/:token', function(req, res) {
zarinpal.PaymentVerification({
Amount: req.params.amount,
Authority: req.params.token,
}).then(function (response) {
if (response.status == 101) {
console.log("Verified! Ref ID: " + response.RefID);
} else {
console.log(response);
}
}).catch(function (err) {
console.log(err);
});
});
/**
* Route: UnverifiedTransactions [module]
* @return {Object} authorities [List of Unverified transactions]
*/
app.get('/UnverifiedTransactions', function(req, res) {
zarinpal.UnverifiedTransactions().then(function (response) {
if (response.status == 100) {
console.log(response.authorities);
}
}).catch(function (err) {
console.log(err);
});
});
/**
* Route: Refresh Authority [module]
* @param {number} expire [(1800 / 60) = 30min]
* @return {String} status [Status of Authority]
*/
app.get('/RefreshAuthority/:expire/:token', function(req, res) {
zarinpal.RefreshAuthority({
Authority: req.params.token,
Expire: req.params.expire
}).then(function (response) {
if (response.status == 100) {
res.send('<h2>You can Use: <u>' + req.params.token + '</u> — Expire in: <u>' + req.params.expire + '</u></h2>');
}
}).catch(function (err) {
console.log(err);
});
});
/**
* Serve App on 9990
*/
app.listen(9990, function() {
console.log('App is Running on Port 9990.');
});