OrahKokos / coinpayments-ipn

Module for verifing Coinpaymets Instant Payment notifications.
MIT License
7 stars 4 forks source link

Coinpayments-IPN

build status code coverage

alt text

Module for verifing Coinpaymets Instant Payment notifications.

Installation

npm install coinpayments-ipn

Usage

/**
 *
 * @param {String} hmac
 * @param {String} ipnSecret
 * @param {Object} payload
 * @returns {Boolean}
 * @throws {CoinpaymentsIPNError}
 */
const { verify } = require('coinpayments-ipn');
const CoinpaymentsIPNError = require('coinpayments-ipn/lib/error');

let isValid, error;

try {
  isValid = verify(hmac, ipnSecret, payload);
} catch (e) {
  error = e;
}
if (error) {
  if (error instanceof CoinpaymentsIPNError) {
    // handle invalid payload
  }
  // make bug report
}

if (isValid) {
  // valid
} else {
  // invalid
}

Example

A simple docker image can be found here.