ddpay

0.0.2 • Public • Published

DotDashPay API Node.js Library

Build Status codecov.io

The DotDashPay API Node.js library defines and implements a set of functions that can be used to interact with the Dot Mini IoT Payments Platform. The goal of this library is to abstract away all of the low-level protocols and connectivity aspects of this interaction from the user. Here is a visual overview of the scope of the API library:

TODO(cjrd) update this image

DotDashPay API Library Scope

Installation

npm install ddpay

Quick Start

After installing the DotDashPay API, we recommend running the simple usage example below, which you can find in the examples directory. This API includes a simulator for the Dot chip, so you don't need any hardware to dive in and get started!

Example: Performing a Transaction

var ddpay = require("ddpay");
var CONFIG = require("./configuration_example.json");
 
 
ddpay.init(CONFIG);
 
// wait for the payment data from the DDPay peripherals
ddpay.hardware.listenForPaymentData()
    .onUpdate(logDDPOutput("waitForPaymentData onUpdate"))
    .onCompletion(function (err, data) {
        if (err) {
            return console.log("Error getting payment data", err);
        }
 
        // specify the amount to charge
        data.charge = {
            dollars: 1,
            cents: 28
        };
 
        // authorize the payment
        ddpay.payment.authorizePayment(data)
            .onUpdate(logDDPOutput("authorizePayment onUpdate"))
            .onCompletion("authorizePayment onCompletion");
    });

where we use a simple helper function to log the output of the callbacks

/**
   A simple function that returns a functions that logs the result of a DDP request
 
   @param {String} prefix: a prefix used when logging the result of a DDP request
   @return {Function} function that logs the result of a DDP request
**/
function logDDPOutput(prefix) {
    return function (err, data) {
        if (err) {
            console.log(prefix, "ERROR", err)
        } else {
            console.log(prefix, data)
        }
    };
}

You can find this example in the examples directory.

Readme

Keywords

none

Package Sidebar

Install

npm i ddpay

Weekly Downloads

2

Version

0.0.2

License

Apache-2.0

Last publish

Collaborators

  • cjrd