1.1.1 • Published 3 years ago

@notchpay/payment v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Notch Pay

Nodejs API wrapper for Notch Pay.

Installation and Authentication

npm install @notchpay/payment

Authenticate

// Require the library
var notchpay = require("@notchpay/payment")("business_key");

Transaction

Allows you to perform transactions on your nodejs and JavaScript applications.

Initiate

// Initiate transaction
await notchpay
  .transaction()
  .init(500, "usd", {
    name: "Chapdel KAMGA",
    email: "hello@chapdel.me",
  })
  .then((r) => {
    console.log("success", r.data);
  })
  .catch((e) => {
    console.log("error", e);
  });

Check

// Check transaction
await notchpay
  .transaction()
  .check("transaction_reference")
  .then((r) => {
    console.log("success", r.data);
  })
  .catch((e) => {
    console.log("error", e);
  });

Complete

// Complete transaction
await notchpay
  .transaction()
  .complete("transaction_reference", "notchpay", {
    number: 123456789,
    code: 12345,
  })
  .then((r) => {
    console.log("success", r.data);
  })
  .catch((e) => {
    console.log("error", e);
  });

Complete With Window

This method offers you the possibility to complete the transaction in a new window. It is necessary to follow our instructions.

// Complete transaction
await notchpay
  .transaction()
  .complete("transaction_reference", "notchpay", {
    number: 123456789,
    code: 12345,
  })
  .then((r) => {
    var _transaction = notchpay
      .transaction()
      .completeWithWindow(r.data.authorization_url, r.data.transaction);

    var watcher = setInterval(() => {
      console.log(_transaction);
      if (_transaction.status != null && _transaction.status != "pending") {
        clearInterval(watcher);

        // your code here
        /*switch (transaction.status) {

        }*/
      }
    }, 2000);
  })
  .catch((e) => {
    console.log("error", e);
  });