Created
May 7, 2019 08:25
-
-
Save nickbrowne/bc352c40415e03dc0a7f62066b20eb18 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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
</head> | |
<body> | |
<div id="error"></div> | |
<!-- Set up a container element for the button --> | |
<div id="paypal-button-container"></div> | |
<!-- Include the PayPal JavaScript SDK --> | |
<script src="https://www.paypal.com/sdk/js?client-id=sb¤cy=USD"></script> | |
<script> | |
// Render the PayPal button into #paypal-button-container | |
paypal.Buttons({ | |
env: "sandbox", | |
style: { | |
layout: 'horizontal' | |
}, | |
onError: function(error) { | |
// attempt to handle error "nicely" | |
document.getElementById("error").innerHTML = error; | |
}, | |
createOrder: function() { | |
return new Promise(function(resolve, reject) { | |
// pseudocode: fetch("server_endpoint").then(something_goes_wrong) | |
// | |
// so we want to reject with an error: | |
reject(new Error("Server isn't happy for some reason")); | |
}); | |
}, | |
}).render('#paypal-button-container'); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment