Skip to content

Instantly share code, notes, and snippets.

@nickbrowne
Created May 7, 2019 08:25
Show Gist options
  • Save nickbrowne/bc352c40415e03dc0a7f62066b20eb18 to your computer and use it in GitHub Desktop.
Save nickbrowne/bc352c40415e03dc0a7f62066b20eb18 to your computer and use it in GitHub Desktop.
<!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&currency=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