npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ddpay

v0.0.2

Published

Nodejs API for DotDashPay

Downloads

2

Readme

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 Dot Mini connects your machine to payments.

The goal of DotDashPay is to abstract away all of the low-level protocols and connectivity aspects of interacting with payment-related hardware and payment processors. You simply write a few API calls, connect your machine to the DotDashPay chip, and you're finished! Oh, and don't worry about payments-related compliance and regulations for your hardware and software. We take care of that too! Here is a visual overview of the scope of the API library:

Installation

npm install ddpay

Guide

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(function () { console.log("waitForPaymentData onUpdate"); })
    .onCompletion(function (err, hwData) {
        if (err) {
            return console.log("Error getting payment data", err);
        }

        // specify the amount to charge
        var payData = {
            payid: hwData.payid,
            dollars: 1,
            cents: 28
        };

        console.log("settling payment", payData);

        // settle the payment
        ddpay.payment.settlePayment(payData)
            .onUpdate(function (err, data) { console.log("settlePayment onUpdate"); })
            .onCompletion(function (err, data) { console.log("settlePayment onCompletion"); });
    });

You can find this example in the examples directory.

API

Overview

The DotDashPay API has three namespaces:

  • ddpay.payment: all payment-processing related functions, e.g. processing, voiding, authorizing, refunding, etc transactions
  • ddpay.hardware: all payment-hardware related functions, e.g. reading card data, testing NFC connectivity, etc
  • ddpay.network: all network related functions, e.g. sending data chunks, checking network connectivity, etc

All API functions in each namespace send a request to The DotDashPay chip and return a Request object. The Request object has two functions for setting callbacks:

  • onUpdate
  • onCompletion

where the callback function passed into onUpdate is called for non-terminating update events from The Dot and the function passed into onCompletion is called when the request is finished, i.e. there will be no more onUpdate callbacks. From the simple example above:

var ddpay = require("ddapy")
ddpay.init();
ddpay.hardware.listenForPaymentData()
    .onUpdate(function (err, data) { console.log("listenForPaymentData Updated") });
    .onCompletion(function (err, data) { console.log("listenForPaymentData Complete") });)

Notice that the callback functions accepts two arguments:

  • err: Will be null if there was not an error. In the event of an error,err will be an object with the format
{
    "description": "a string description of the error",
    "code": 1  // an integer code for the particular error
}
  • data: A request-related data object with a format dependent on the exact response: check the relevant API function documentation for the expected format. All data objects have at least the following two fileds:
{
    "name": "name-of-the-response",
    "id": "id-of-the-corresponding-request"
    // response-specific data fields
    // ...
}


hardware API

#listenForPaymentData(onlyNewData)

Listen for payment data from the payments-related peripheral hardware

Arguments

  • onlyNewData {Boolean}: specify whether we should only listen for new payments data from the payments hardware, e.g. ignore card swipes that occured before this method was called

Update Responses MSRStartRead: response when the magnetic-stripe reader starts reading data from a magnetic stripe card

// Callback data
{
    "name": "MSRStartRead",
    "id": "id-of-the-corresponding-request"
}

Completion Responses MSREndRead : response when the magnetic-stripe reader finishes reading data from a magnetic stripe card.

// Callback data
{
    "name": "MSREndRead",
    "id": "id-of-the-corresponding-request",
    // e.g. pass `payid` into the object argument of `ddpay.payment.settlePayment`
    "payid": "id-for-referencing-the-given-magstripe-card" 
}


payment API

#settlePayment(paymentData)

Settles a payment: you may call this function either after receiving data from hardware.listenForPaymentData or after receiving data from payment.authorizePayment If called directly after receiving payment data from the hardware, then this immediently charges the payer. If called after authorizing the payment, then this request will finalize the transaction and the transaction cannot be voided later on.

Arguments

  • paymentData {Object}: an object that specifies the parameter of the payment and has the following format:
// `paymentData` format
{
    // e.g. this should come from `ddpay.hardware.listenForPaymentData`
    "payid": "id-for-referencing-the-given-payment-method", 

     // number of dollars to charge, the X in $X.Y
    "dollars": 1,
    
    // number of cents to charge, the Y in $X.Y
    "cents": 28
}

Update Responses

None

Completion Responses FinishedAuthorization : response when the payment

// Callback data
{
    "name": "MSREndRead",
    "id": "id-of-the-corresponding-request",
    "payid": "id-for-referencing-the-given-magstripe-card" // e.g. pass this id into `ddpay.payment.SettlePayment`,
    "status": 0, // 0 if success, 1 if fail
    "transaction_id": "istring id of the transaction",
    "info": "string with additional information about the transaction"
}

network API

We have not yet exposed the network API: this should be ready in October 2015.

NOTE

This API library is under active development. Contact Colorado Reed if you need specific functionality that is not yet implemented here.