Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Created July 19, 2017 20:20
Show Gist options
  • Save bluepnume/872ec204f80fe73398a96b077834778b to your computer and use it in GitHub Desktop.
Save bluepnume/872ec204f80fe73398a96b077834778b to your computer and use it in GitHub Desktop.
<!-- Detect checkout.js eligibility -->
<script>
if (paypal.isEligible()) {
paypal.Button.render({ ... }, '#container');
}
</script>
<!-- Otherwise render static button with redirect -->
<script src="https://www.paypalobjects.com/api/button.js"></script>
<div id="paypal-static-button"></div>
<script>
var el = window.paypal.button.create('walmart', {
lc: 'en_US',
color: 'gold',
shape: 'rect',
size: 'small'
}, {
type: "button",
label: 'checkout'
}).el;
document.querySelector('#paypal-static-button').appendChild(el);
el.addEventListener('click', function(event) {
event.preventDefault();
// Generate EC token and redirect to paypal
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment