Last active
June 4, 2020 03:25
-
-
Save ThiagoBarradas/34d7fd2aeb9f25abe6404c1bd64946a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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