Last active
August 8, 2017 18:05
-
-
Save bluepnume/259e3fa3120a63903934882991c58ce3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script> | |
(function() { | |
var PAYPAL_SCRIPT = 'https://www.paypalobjects.com/api/checkout.js'; | |
var ATTEMPTS = 3; | |
function loadPayPalCheckout(callback) { | |
ATTEMPTS -= 1; | |
var container = document.body || document.head; | |
callback = callback || function() {}; | |
var script = document.createElement('script'); | |
script.setAttribute('src', PAYPAL_SCRIPT); | |
script.onload = function() { | |
callback() | |
}; | |
script.onerror = function(err) { | |
if (ATTEMPTS) { | |
loadPayPalCheckout(callback); | |
} else { | |
callback(err) | |
} | |
}; | |
container.appendChild(script); | |
} | |
loadPayPalCheckout(function(err) { | |
if (err) { | |
// fallback to static button | |
} else { | |
// paypal.Button is ready | |
} | |
}); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment