-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormal.js
More file actions
34 lines (32 loc) · 1.28 KB
/
Copy pathnormal.js
File metadata and controls
34 lines (32 loc) · 1.28 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
// Script made by Anapah Pongvijarn
// Updated 21 Feb 2022
// Freeuse and modify right
/*
Redeem a truewallet voucher to a phone number
check for valid phone number and valid url
raise error for invalid input
Phone number ex. 061XXXXXXX
Voucher link ex. https://gift.truemoney.com/campaign/?v=XXXXXXXXXXXXXXXXXX
(V= {18 char})
*/
module.exports = async (phone , url) => {
if ((phone.trim().length == 10) && phone.trim()[0] == "0") {
PHONE_NUMBER = phone
} else {
throw Error("Invalid Phone number")
}
if (url.includes("https://gift.truemoney.com/campaign/?v=") && url.split("https://gift.truemoney.com/campaign/?v=")[1].length == 18){
VOUCHER_CODE = url.split("https://gift.truemoney.com/campaign/?v=")[1];
} else {
throw Error("Invalid voucher")
}
let request = await require("petitio")(`https://gift.truemoney.com/campaign/vouchers/${VOUCHER_CODE}/redeem`,"POST").body({"mobile":PHONE_NUMBER,"voucher_hash":VOUCHER_CODE}).json()
console.log(request.status.code)
if (request.status.code == "SUCCESS") {
return {
"AMOUNT":request.voucher.redeemed_amount_baht,
"SENDER":request.owner_profile.full_name
};
}
throw Error(request.status.code)
};