Answer the question
In order to leave comments, you need to log in
IPN listener for PayPal in Meteor app, how to implement?
The second day I suffer with the attachment of paypal to the meteor application. About the REST API has already scored completely, just tons of documentation without convenient navigation. I found a more or less simple solution, it's just to put a PayPal button and set up IPN natification, in which after each operation, PayPal will send a post request that needs to be processed on the server and return PayPal back. Actually, this is the only safe way to somehow automatically control payments and do something about it.
Actually, with this "simple" solution, I hung for the second day. Can't set up IPN listener! Can anyone share experience?
Answer the question
In order to leave comments, you need to log in
solution for meteor:
install the following packages (support for node packages and routing on the server side).
meteor add meteorhacks:npm
meteor add meteorhacks:picker
{
"paypal-ipn" : "3.0.0",
"body-parser": "1.14.1"
}
const bodyParser = Meteor.npmRequire('body-parser');
Picker.middleware(bodyParser.urlencoded({ extended: false }));
Picker.middleware(bodyParser.json());
Picker.route('/ipn', function(params, req, res, next) {
res.writeHead(200);
const ipn = Meteor.npmRequire("paypal-ipn");
// создаем обертку функции верификации
// можно так же верифицировать синхронно
const wrappedVerify = Async.wrap(ipn,"verify");
let verified = false;
//обрабатывать только пост запросы
if (req.method === "POST") {
// PayPal ждет от нас пересылки IPN сообщения
// делаем это первым:
try {
//второй аргумент в продакшене не нужен и по умалчанию false
verified = wrappedVerify(req.body, {"allow_sandbox" : true});
} catch (err) {
// код при ошибке
}
if (verified === 'VERIFIED') {
let payment = req.body;
// код если все успешно
}
}
res.end();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question