0.7.0 • Published 5 years ago

ipn-pal v0.7.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

IPN-Pal

Build

PayPal Instant Payment Notification SDK for Node.js and Express.

Install

Either use yarn or npm to add the package.

$ yarn add ipn-pal

About IPN-Pal

The IPN message authentication protocol consists of four steps: 1. PayPal HTTPS POSTs an IPN message to your listener that notifies it of an event. 2. Your listener returns an empty HTTP 200 response to PayPal immediately. 3. Your listener HTTPS POSTs the complete, unaltered message is sent back to PayPal 1. The message must contain the same fields (in the same order) as the original message 2. The message must be encoded in the same way as the original message. 4. PayPal sends a single word back 1. Either (a or b) 1. VERIFIED (if the message matches the original) 2. INVALID (if the message does not match the original).

Use

To use this validator, you must ensure that your path variable is the same in your options as on the PayPal website. You can test this by going to the PayPal developer website. The below configuration should have these settings on the IPN website:

IPN Simulator

var ipn_pal = require('ipn-pal');
var express = require('express');
var app = express();

var IPN_ERRORS = ipn_pal.IPN_ERRORS;

// Use the ipn validator on a specific route
app.use(ipn_pal.validator({ path: "/your-ipn-webhook", sandbox: true }, function (err, body) {
  console.log('err', err); // See example below
  console.log('body', body); // See example below
  
  if (!err) {
    var transactionType = body.txn_type;
    var paymentType = body.payment_type;
  } else {
    switch (err) {
      case IPN_ERRORS.BAD_STATUS:
        // Do something here
        break;
      case IPN_ERRORS.INVALID_IPN:
        // Do something here
        break;
      case IPN_ERRORS.UNKNOWN_RESPONSE:
        // Do something here
        break;
    }
  }
}));

A callback example with test data:

$ err: null
$ body: { payment_type: 'instant',
          payment_date: '12:49:23 Nov 20, 2018 PST',
          payment_status: 'Pending',
          address_status: 'confirmed',
          payer_status: 'verified',
          first_name: 'John',
          last_name: 'Smith',
          payer_email: 'buyer@paypalsandbox.com',
          payer_id: 'TESTBUYERID01',
          address_name: 'John Smith',
          address_country: 'United States',
          address_country_code: 'US',
          address_zip: '95131',
          address_state: 'CA',
          address_city: 'San Jose',
          address_street: '123 any street',
          business: 'seller@paypalsandbox.com',
          receiver_email: 'seller@paypalsandbox.com',
          receiver_id: 'seller@paypalsandbox.com',
          residence_country: 'US',
          item_name: 'something',
          item_number: 'AK-1234',
          quantity: '1',
          shipping: '3.04',
          tax: '2.02',
          mc_currency: 'USD',
          mc_fee: '0.44',
          mc_gross: '12.34',
          mc_gross_1: '9.34',
          txn_type: 'web_accept',
          txn_id: '657441024',
          notify_version: '2.1',
          custom: 'xyz123',
          invoice: 'abc1234',
          test_ipn: '1',
          verify_sign: 'AcZrR69yBSOpZEbp3xyJumBX9WTAJ05Dw-Dqbok8jXqjlzAh8l2yShK' }

API

Table of Contents

Options

The Options parameter

Type: Object

Properties

  • path string The path to your webhook. Must be the same on PayPal
  • sandbox boolean? Are you using the sandbox environment? Default: false

Callback

This callback will be passed the body of the request if successful

Type: Function

Parameters

validator

This method is the validator for an IPN webhook defined on your server

Parameters

  • options Options to pass the validator
  • cb Callback? A successful callback can be called

IPN_ERRORS

IPN_ERRORS

Type: {BAD_STATUS: string, INVALID_IPN: string, UNKNOWN_RESPONSE: string}

License

MIT © ProductOfAmerica