Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ThiagoBarradas/34d7fd2aeb9f25abe6404c1bd64946a0 to your computer and use it in GitHub Desktop.
Save ThiagoBarradas/34d7fd2aeb9f25abe6404c1bd64946a0 to your computer and use it in GitHub Desktop.
// create checkouts
function doGet(request) {
var sk = "sk_xxxxxxxxxxxxxxxxxxx";
var acceptedAmounts = [ "10", "50" ];
var amount = request.parameter.amount;
if (!acceptedAmounts.includes(amount)) {
throw "invalid amount";
}
var amountInCents = amount * 100;
var payload =
{
"items":[
{
"amount": amountInCents,
"description":"Doação :)",
"quantity":1
}
],
"customer": {
"name":"." // required, only to bypass
},
"payments":[
{
"amount" : amountInCents,
"payment_method":"checkout",
"checkout": {
"expires_in":120,
"billing_address_editable" : true,
"customer_editable" : true,
"accepted_payment_methods": ["credit_card" ],
"credit_card": {
"installments": [
{
"number": 1,
"total": amountInCents
}
]
}
}
}
]
};
var user = sk;
var pass = "";
var options = {
"method": 'POST',
"payload": JSON.stringify(payload),
"headers" : {
"Content-Type": "application/json",
"Authorization": "Basic " + Utilities.base64Encode(user + ":" + pass)
}
};
var response = UrlFetchApp.fetch("https://api.mundipagg.com/core/v1/orders", options);
var responseObj = JSON.parse(response.getContentText());
var checkout_url = responseObj.checkouts[0].payment_url;
return HtmlService.createHtmlOutput(
"<script>window.top.location.href=\"" + checkout_url + "\";</script>"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment