Created
December 18, 2015 22:09
-
-
Save Siphion/4bd9ccff22b7f22a065d to your computer and use it in GitHub Desktop.
meteor iron-router validate ipn paypal
This file contains 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
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