Last active
January 23, 2017 22:30
-
-
Save bluepnume/eab72a3897fa03d16d261c51fe92b541 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
| // Before ------------------------------------------- | |
| <script> | |
| window.paypalCheckoutReady = function () { | |
| paypal.checkout.setup("8J7EEJME4CLSA", { | |
| environment: 'sandbox', | |
| buttons: [{ container: 'paypalContainer', color: 'blue', size: 'medium', shape: 'rect' }], | |
| click: function (event) { | |
| event.preventDefault(); | |
| var postData = 'SiteId=1&f=GetPayPalRedirect&OrderId=206156'; | |
| $.post(globalSiteReferer + '/ajax.aspx', postData, function (data) { | |
| var o = JSON.parse(data); | |
| if (!o.Success || o.PayPalURL == '') { | |
| try {paypal.checkout.closeFlow();} catch(err) {} | |
| return; | |
| } | |
| if (isTestSite) { | |
| console.log(o.PayPalToken + ' --- ' + o.PayPalURL) | |
| } | |
| paypal.checkout.initXO(); | |
| if (o.PayPalToken != '') | |
| paypal.checkout.startFlow(o.PayPalToken); | |
| else | |
| paypal.checkout.startFlow(o.PayPalURL); | |
| }); | |
| } | |
| }); | |
| }; | |
| </script> | |
| <script src="https://www.paypalobjects.com/api/checkout.js" async=""></script> | |
| // After ------------------------------------------- | |
| <script src="https://www.paypalobjects.com/api/checkout.js"></script> | |
| <script> | |
| paypal.Button.render({ | |
| env: 'sandbox', | |
| style: { | |
| color: 'blue', | |
| size: 'medium', | |
| shape: 'rect' | |
| }, | |
| payment: function(resolve, reject) { | |
| var postData = 'SiteId=1&f=GetPayPalRedirect&OrderId=206156'; | |
| $.post(globalSiteReferer + '/ajax.aspx', postData, function (data) { | |
| var o = JSON.parse(data); | |
| if (!o.Success || o.PayPalURL == '') { | |
| return reject(new Error('Could not create payment')); | |
| } | |
| if (isTestSite) { | |
| console.log(o.PayPalToken + ' --- ' + o.PayPalURL) | |
| } | |
| return resolve(o.PayPalToken || o.PayPalURL.match(/token=(EC-\w+)/)[1]); | |
| }); | |
| }, | |
| onAuthorize: function(data, actions) { | |
| return actions.redirect(); | |
| } | |
| }, '#paypalContainer'); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment