S
S
Sarkis Arutiunian2016-01-09 03:28:08
JavaScript
Sarkis Arutiunian, 2016-01-09 03:28:08

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

2 answer(s)
S
Sarkis Arutiunian, 2016-01-15
@sarkis-tlt

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

the packages.json file will appear in the root of the project, add the following modules to it.
{
  "paypal-ipn" : "3.0.0",
  "body-parser": "1.14.1"
}

on the server side of the project, we create a file in which we configure the routing.
const bodyParser = Meteor.npmRequire('body-parser');
Picker.middleware(bodyParser.urlencoded({ extended: false }));
Picker.middleware(bodyParser.json());

it is possible in the same or in a new file on the server side, we define the paths and configure the listener itself.
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();
});

E
ElkinPP, 2016-01-13
@ElkinPP

Here you can find a PayPal IPN example: https://github.com/paypal/ipn-code-samples
I hope it helps you.
also: https://developer.paypal.com/docs/classic/ipn/inte...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question