Skip to content

Instantly share code, notes, and snippets.

@Siphion
Created December 18, 2015 22:09
Show Gist options
  • Save Siphion/4bd9ccff22b7f22a065d to your computer and use it in GitHub Desktop.
Save Siphion/4bd9ccff22b7f22a065d to your computer and use it in GitHub Desktop.
meteor iron-router validate ipn paypal
let paypalProd = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
let paypalSandbox = 'https://www.paypal.com/cgi-bin/webscr';
function validateIPN(data) {
try {
let url = (Meteor.settings.paypal.sandbox ? paypalSandbox : paypalProd) +
'?cmd=_notify-validate';
return HTTP.post(url, {params: data}) === 'VERIFIED';
} catch (err) {
log.error(err);
}
return false;
}
Router.route('/paypal/payipn', function payipn() {
try {
let data = this.request.body;
this.response.end('');
if (validateIPN(data)) {
log.debug('valid ipn');
// then do stuffs
}
} catch (err) {
log.error(err);
}
}, { where: 'server' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment