Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
95 lines (88 loc) · 2.39 KB
/
Copy pathserver.js
File metadata and controls
95 lines (88 loc) · 2.39 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
91
92
93
94
95
const express = require("express");
const fetch = require("node-fetch");
const app = express();
app.use(express.static("public"));
app.use(express.json());
// Insert your secret key here
const SECRET_KEY = "insert_your_secret_key_here";
app.post("/create-payment-sessions", async (_req, res) => {
// Create a PaymentSession with 3D Secure Enabled
const request = await fetch(
"https://api.sandbox.checkout.com/payment-sessions",
{
method: "POST",
headers: {
Authorization: `Bearer ${SECRET_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
amount: 6540,
currency: "GBP",
reference: "ORD-123A",
description: "Payment for Guitars and Amps",
billing_descriptor: {
name: "Jia Tsang",
city: "London",
},
customer: {
email: "jia.tsang@example.com",
name: "Jia Tsang",
},
shipping: {
address: {
address_line1: "123 High St.",
address_line2: "Flat 456",
city: "London",
zip: "SW1A 1AA",
country: "GB",
},
phone: {
number: "1234567890",
country_code: "+44",
},
},
billing: {
address: {
address_line1: "123 High St.",
address_line2: "Flat 456",
city: "London",
zip: "SW1A 1AA",
country: "GB",
},
phone: {
number: "1234567890",
country_code: "+44",
},
},
risk: {
enabled: true,
},
success_url: "http://localhost:3000/success.html",
failure_url: "http://localhost:3000/failure.html",
metadata: {},
items: [
{
name: "Guitar",
quantity: 1,
unit_price: 1635,
},
{
name: "Amp",
quantity: 3,
unit_price: 1635,
},
],
processing_channel_id: "insert_processing_channel_id_here",
// ✅ Enable 3D Secure Authentication
"3ds": {
"enabled": true
}
}),
}
);
const parsedPayload = await request.json();
res.status(request.status).send(parsedPayload);
});
app.listen(3000, () =>
console.log("Node server listening on port 3000: http://localhost:3000/")
);