Skip to content

Instantly share code, notes, and snippets.

@sirateek
Last active May 28, 2020 16:47
Show Gist options
  • Save sirateek/31fbedb5a41097c73496f87b765b90e1 to your computer and use it in GitHub Desktop.
Save sirateek/31fbedb5a41097c73496f87b765b90e1 to your computer and use it in GitHub Desktop.
const request = require("request-promise");
const crypto = require("crypto");
const UUID = require("uuid-v4");
var baseUrl = "https://api-pay.line.me";
var extension = `/v3/payments/request`;
var channelSecret = "";
var nonce = UUID();
console.log(nonce);
const doRequest = (body) => {
const sigprepare = channelSecret + extension + JSON.stringify(body) + nonce;
const signature = crypto
.createHmac("sha256", channelSecret)
.update(sigprepare)
.digest("base64")
.toString();
console.log(signature);
var header = {
"Content-Type": "application/json",
"X-LINE-ChannelId": "",
"X-LINE-Authorization-Nonce": nonce,
"X-LINE-Authorization": signature,
};
return request({
method: `POST`,
uri: `${baseUrl}${extension}`,
headers: header,
body: JSON.stringify(body),
});
};
doRequest({
amount: 2,
currency: "THB",
orderId: "00BB1A",
packages: [
{
id: "01A",
amount: 2,
name: "Toy Package",
products: [
{
name: "ตุ๊กตา Cony",
quantity: 1,
price: 1,
},
{
name: "ตุ๊กตา Sally",
quantity: 1,
price: 1,
},
],
},
],
redirectUrls: {
confirmUrlType: "CLIENT",
confirmUrl:
"https://google.com/?success=true",
cancelUrl:
"https://google.com/?success=false",
},
})
.then((data) => {
console.log(data);
})
.catch((e) => {
console.log("Error");
console.log(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment