Git Product home page Git Product logo

express-ipn's Introduction

express-ipn

Create a PayPal IPN listener in minutes with this easy-to-use Express middleware.

##Installation

$ npm install express-ipn

##Usage

Mount the middleware on a POST handler on the endpoint where you want you IPN listener to live:

var app = require('express')();
var ipn = require('express-ipn');
var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({extended: false})); // IPN data is sent in the body as x-www-form-urlencoded data
app.post('/', ipn.validator(validationHandler));

function validationHandler(err, ipnContent) {
    if (err) {
        console.error("IPN invalid"); // The IPN was invalid
    } else {
        console.log(ipnContent); // The IPN was valid.
        ... // Process the IPN data
    }
}

...

when you are ready to go put your server into production, make the following change:

...
app.post('/', ipn.validator(validationHandler), true);
...

##API

var ipn = require('express-ipn');
ipn.validator(callback, [productionMode]);

callback will be called when the IPN verification protocol is complete. It will be passed three parameters: err, ipnContent, and req. err will be an Error object if verification fails.

Verification will fail under two circumstances:

  1. PayPal returned an INVALID message in response to the verification request, meaning the ipn is not valid
  2. A test IPN (such as from a sandbox account or the IPN simulator) was received when productionMode was enabled. This is to prevent a live server from handling fake data. Conversely, if productionMode is disabled, a live IPN will be treated as invalid, as non-development servers should not be handling live data.

If verification succeeds, err will be null. The content of the originally received IPN will be parsed as a JavaScript object and passed in the ipnContent parameter. The original request will be passed in the additional req parameter. This is useful if, for example, the PayPal notify_url variable contains parametric correlation parameters.

productionMode is an optional which should be set to true when the listener is ready to go into production, and handle live payment data. It defaults to false. Note the in order to handle test IPNs, such as those sent from sandbox accounts, or from the IPN simulator, productionMode must be false. Conversely, to handle live IPNs, productionMode must be set to true.

express-ipn's People

Contributors

vicatcu avatar jhbertra avatar

Watchers

Auston LeRoy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.