-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathorder.js
More file actions
89 lines (81 loc) · 2.07 KB
/
Copy pathorder.js
File metadata and controls
89 lines (81 loc) · 2.07 KB
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
'use strict';
module.exports = {
getRequest: getRequest,
decodeResponse: decodeResponse
};
const rc4 = require('./encrypt.js');
const fs = require('fs');
const dotenv = require("dotenv");
dotenv.config();
const privateKey = fs.readFileSync( privateKeyPath ).toString();
const publicKey = fs.readFileSync( publicKeypath ).toString();
const xml2js = require('xml2js');
var builder = new xml2js.Builder({
cdata: true
});
var parser = new xml2js.Parser({
explicitArray: false
});
const getPayment = (orderId, amount, currency) => {
let date = new Date();
const data = {
order: {
$: {
id: orderId,
timestamp: date.getTime(),
type: 'card'
},
signature: '<your_netopia_seller_account_signature>',
url: {
return: '<your_return_URL>',
confirm: '<your_confirm_URL>'
},
invoice: {
$: {
currency: currency,
amount: amount,
},
details: 'test plata',
contact_info: {
billing: {
$: {
type: 'person'
},
first_name: 'Test',
last_name: 'Test',
address: 'strada',
email: 'test@mobilpay.ro',
mobile_phone: 'mobilePhone'
},
shipping: {
$: {
type: 'person'
},
first_name: 'Test',
last_name: 'Test',
address: 'strada',
email: 'test@mobilpay.ro',
mobile_phone: 'mobilePhone'
}
}
},
ipn_cipher: 'aes-256-cbc',
}
}
return { data, algorithm: 'aes-256-cbc' };
}
function getRequest(orderId) {
const result = getPayment(orderId, 1, 'RON')
let xml = builder.buildObject(result.data);
return rc4.encrypt(publicKey, xml, result.algorithm);
}
function decodeResponse(data) {
return new Promise(function (resolve, reject) {
parser.parseString(rc4.decrypt(privateKey, data.iv, data.env_key, data.data, data.cipher), function (err, result) {
if (err) {
reject(err);
}
resolve(result);
});
});
}