Skip to content

Instantly share code, notes, and snippets.

@BubuMVX
Last active July 20, 2020 22:09
Show Gist options
  • Save BubuMVX/49be010e12d0813a94d32d4cb6d7bd28 to your computer and use it in GitHub Desktop.
Save BubuMVX/49be010e12d0813a94d32d4cb6d7bd28 to your computer and use it in GitHub Desktop.
A small and dirty snippet to get your PledgeBox ID on a project.
/*
* PledgeBox pledge manager
* Display some datas about your order on a project
* Run it on "thank you" page.
* URL scheme: https://survey.pledgebox.com/project/[PROJECT_ID]/[PROJECT_SLUG]/[TOKEN]/success
* Dates timezone: GMT-7
*/
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'https://survey.pledgebox.com/api/survey/order/info', true);
httpRequest.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
var json = JSON.parse(httpRequest.responseText);
var pledged_at = new Date(json.data.pledged_at * 1000).toLocaleString("en-US", {timeZone: "America/Los_Angeles"});
pledged_at = new Date(pledged_at);
var nl = '\n';
alert(
'PBID: ' + json.data.id + nl +
'Backer: ' + json.data.sequence + nl +
'Pledged: ' + pledged_at.getFullYear() + '-' +
leadingZero(pledged_at.getMonth()) + '-' +
leadingZero(pledged_at.getDate()) + ' ' +
leadingZero(pledged_at.getHours()) + ':' +
leadingZero(pledged_at.getMinutes()) + ':' +
leadingZero(pledged_at.getSeconds()) + nl +
'Opened: ' + json.data.opened_at + nl +
'Paid: ' + json.data.paid_at + nl +
'Completed: ' + json.data.completed_at
);
}
};
var token = location.href.split('/')[6];
httpRequest.send(JSON.stringify({token: token}));
function leadingZero(value) {
if(value < 10) {
value = '0' + value;
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment