Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions js/Paywall.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,68 @@ function startGame(){
}

function createInvoice() {


const Http = new XMLHttpRequest();
const url = 'https://api.zebedee.io/v0/charges';

Http.open("POST", url);

Http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
Http.setRequestHeader("apikey", config.API_KEY);

const payload = JSON.stringify({
"expiresIn": 300,
"amount": config.FEE * 1000,
"description": "EasySats - Bomberman Paywall",
"internalId": "11af01d092444a317cb33faa6b8304b8",
"callbackUrl": "https://your-website.com/callback"
})
Http.send(payload);

Http.onreadystatechange = (e) => {

if (Http.readyState === XMLHttpRequest.DONE) {
console.log(Http.responseText)
const data = JSON.parse(Http.responseText);
currentChargeID = data.data.id;
createInvoiceQRCode(data);
}

}
}

function checkPayment() {

const Http = new XMLHttpRequest();
const url = 'https://api.zebedee.io/v0/charges/' + currentChargeID;

Http.open("GET", url);

Http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
Http.setRequestHeader("apikey", config.API_KEY);

Http.send();

Http.onreadystatechange = (e) => {

if (Http.readyState === XMLHttpRequest.DONE) {
console.log(Http.responseText);
const data = JSON.parse(Http.responseText);
const status = data.data.status;

if (status === "pending") {

setTimeout(function() {
checkPayment();
}, 2000);

} else if (status === "completed") {

startGame();

}
}
}

}

createInvoice();
58 changes: 56 additions & 2 deletions js/Withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,65 @@ function updateWithdrawUI(){
}

function createWithdrawLNURL(){

const Http = new XMLHttpRequest();
const url = 'https://api.zebedee.io/v0/withdrawal-requests';

Http.open("POST", url);

Http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
Http.setRequestHeader("apikey", config.API_KEY);

const payload = JSON.stringify({
"expiresIn": 300,
"amount": gGameEngine.totalSats * 1000,
"description": "Bomberman withdraw",
"internalId": "11af01d092444a317cb33faa6b8304b8",
"callbackUrl": "https://your-website.com/callback"
});

Http.send(payload);

Http.onreadystatechange = (e) => {

if (Http.readyState === XMLHttpRequest.DONE) {

const data = JSON.parse(Http.responseText);

currentWithdrawlID = data.data.id;

makeWithdrawQRCode(data)
}

}
}

function checkWithdraw() {

const Http = new XMLHttpRequest();
const url = 'https://api.zebedee.io/v0/withdrawal-requests/' + currentWithdrawlID;

Http.open("GET", url);

Http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
Http.setRequestHeader("apikey", config.API_KEY);

Http.send();

Http.onreadystatechange = (e) => {

if (Http.readyState === XMLHttpRequest.DONE) {

const data = JSON.parse(Http.responseText);

const status = data.data.status;
if (status === "pending") {
setTimeout(function() {
checkWithdraw();
}, 2000);
} else if (status === "completed") {
updateWithdrawUI();
}
}
}
}

document.getElementById('withdrawButton').onclick = withdraw;