Last active
July 20, 2018 18:00
-
-
Save bluepnume/a8a0e1687ec4835c3ad8bed03b46d6e8 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
paypal.Button.render({ | |
payment: function() { | |
return jQuery.ajax({ | |
method: 'POST', | |
url: '/generate-paypal-token' | |
}).then(function(data, status, res) { | |
// Reject the promise if token not returned | |
if (!data.token) { | |
throw new Error('Response did not contain a PayPal token'); | |
} | |
// Reject the promise if non-200 response code | |
if (res.status !== 200) { | |
throw new Error('Response non-200 code: ' + res.status); | |
} | |
// Otherwise resolve the promise with the token | |
return data.token; | |
}); | |
}, | |
onAuthorize: function(data, actions) { | |
// Redirect to the return URL | |
return actions.redirect(); | |
}, | |
onCancel: function(data, actions) { | |
// Redirect to the cancel URL | |
return actions.redirect(); | |
}, | |
onError: function(err) { | |
// Handle errors here; show an error message or redirect to an error page | |
// Note: any rejected promise from the `payment()` function will call this error handler | |
} | |
}, '#container'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment