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

coinpush-node

v1.0.4

Published

Integrate cryptocurrency payments into your application.

Downloads

19

Readme

Description

Enable cryptocurrency payments in your web applications or business.

This NODE SDK interacts with the Coinpush.io API handling the creation and monitoring of cryptocurrency payments.

Contents

Prerequisites

  • NODE >= 8.0.0
  • NPM

Installation

npm install coinpush-node

Usage

Currencies

Coinpush currently supports: btc, bch and ltc.

Be sure to check out Coinpush's supported cryptocurrencies for an up-to-date list, as well as fee information.

Initialisation

To get started, inject the Config class into the Client constructor:

const Config = require('coinpush-node')['config']
const Client = require('coinpush-node')['client']
const Coinpush = new Client(new Config())

Testnet

Want to request the Coinpush.io Testnet? Enable it like so:

const Coinpush = new Client(new Config().useTestnet())

IMPORTANT: Please do not send real payments to any addresses created on the Testnet, as our systems do not monitor them automatically.

Approach A

This approach enables payments on a per-cryptocurrency basis.

Payment Creation

To create a new payment address, use the following method:

let currency = 'btc' // The cryptocurrency to charge in.

Coinpush.create(currency, {
    amount: 20000, // Satoshis to charge (0.0002 * 100000000).
    output_address: 'YOUR_BTC_OUTPUT_ADDRESS',
    // callback_url: 'OPTIONAL_WEBHOOK_NOTIFICATION_URL'
}).then((json) => {
    let depositAddress = json.results.address.deposit_address
}).catch((err) => {
    err.res.json().then((json) => {
        console.error(err.statusCode, json)
    })
})

For more information on the create resource visit: Coinpush.io API Payment Creation.

Payment Monitoring

Webhooks

Webhook notifications are sent if a callback_url is supplied when creating a payment - read more about webhooks on the official docs: Coinpush.io API Payment Monitoring.

Manually

You can use a payment's address label, made when creating a payment, to inspect its statuses:

let label = 'ADDRESS_LABEL_FROM_PAYMENT_CREATION'

Coinpush.statuses(label).then((json) => {
    // Collect only the statuses from the object.
    let statuses = json.results.statuses.map((item) => {
        return item.status
    })

    // The payment status to check for.
    let status = 'balance_sufficient'

    // Create boolean stating whether the status was met.
    let paymentWasSuccessful = statuses.includes(status)
}).catch((err) => {
    err.res.json().then((json) => {
        console.error(err.statusCode, json)
    })
})

Statuses indicate changes in a payment's lifespan. To discover which statuses you can check for, see: Coinpush.io API Statuses.

Approach B

This approach enables payments via one, or more, cryptocurrencies based on a fiat currency and amount. It makes use of charge tokens, which are used in conjunction with the Javascript Charge UI plugin.

Charge Tokens

let fiat = 'usd' // The fiat currency to charge in.

Coinpush.charge(fiat, {
    amount: 12.45,
    'accept[btc]': 'YOUR_BTC_OUTPUT_ADDRESS',
    'accept[bch]': 'YOUR_BCH_OUTPUT_ADDRESS',
    'accept[ltc]': 'YOUR_LTC_OUTPUT_ADDRESS'
}).then((json) => {
    let token = json.results.charge.token

    // Use `token` on your template with the Charge UI plugin.
}).catch((err) => {
    err.res.json().then((json) => {
        console.error(err.statusCode, json)
    })
})

Read more about charge tokens here: Coinpush.io API Charge Tokens.

Charge Monitoring

To monitor a charge payment you must inspect its statuses:

let token = 'CHARGE_TOKEN_FROM_CHARGE_CREATION'

Coinpush.chargeView(token).then((json) => {
    // Collect only the statuses from the object.
    let statuses = json.results.statuses.map((item) => {
        return item.status
    })

    // The payment status to check for.
    let status = 'balance_sufficient'

    // Create boolean stating whether the status was met.
    let paymentWasSuccessful = statuses.includes(status)
}).catch((err) => {
    err.res.json().then((json) => {
        console.error(err.statusCode, json)
    })
})

Read more about charge monitoring here: Coinpush.io API Charge Monitoring.

Response Status Codes

Coinpush always responds with meaningful HTTP status codes, look out for these:

| Code | Description | | ---- |-------------| | 200 | The request was successful. | | 201 | The request was successful and a new resource was created. | | 400 | The request was not validated or formatted properly. | | 404 | The given input or resource was not found. | | 405 | The request method was not supported. | | 429 | You exceeded the given rate limit. | | 500 | The API experienced an internal server error. | | 503 | The API is down for maintenance. |

Links