-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
90 lines (78 loc) · 2.42 KB
/
app.js
File metadata and controls
90 lines (78 loc) · 2.42 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
90
var express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const axios = require('axios');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cors());
app.options('*', cors());
app.get('/', (req, res) => res.status(200).send('Arkesel Rocks!!'));
app.post('/payments/initiate', ((req, res) => {
const uniqueRef = `${Date.now() + (Math.random() * 100)}`;
const paymentRequest = {
account_number: "0553995074",
merchant_reference: uniqueRef,
channel: "mobile-money",
provider: "mtn",
transaction_type: "debit",
amount: "1.00",
purpose: "credit top up",
service_name: "arkesel",
currency: "GHS",
};
const apiKey = 'XXXXXXXXXXXXXXXXXXXX=';
const url = 'https://payment.arkesel.com/api/v1/payment/charge/initiate';
axios({
method: 'post',
url,
data: { ...paymentRequest },
headers: {
'api-key': apiKey,
}
}).then(res => res.data).then(data => {
console.log({ data }, 'Initiate payment');
// Save into DB
});
res.setHeader('Content-Type', 'application/json');
return res.status(200).json({
status: 'success',
message: 'payment initiated'
});
}));
// Callback URL for payment
app.get('/payments/arkesel/callback', ((req, res) => {
console.log({ query: res.query }, 'Callback for Arkesel payment');
// Verify the payment...
res.setHeader('Content-Type', 'application/json');
return res.status(200).json({
status: 'success',
message: 'arkesel payment callback called'
});
}));
// Verify payment
app.get('/payments/verify', ((req, res) => {
const apiKey = 'XXXXXXXXXXXXXXXXXXXXXXX=';
const transRef = 'T634E3e8cac8175';
const url = `https://payment.arkesel.com/api/v1/verify/transaction/${transRef}`;
axios({
method: 'get',
url,
headers: {
'api-key': apiKey,
}
}).then(res => res.data).then(data => {
console.log({ data }, 'Verify payment');
// Update payment status in DB
});
res.setHeader('Content-Type', 'application/json');
return res.status(200).json({
status: 'success',
message: 'payment verification called'
});
}));
app.listen(8000, function () {
console.log('Arkesel Payment app listening on 8000!');
});