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

vigour-pay

v1.0.6

Published

Native store purchasing and web payment

Downloads

14

Readme

pay

Native store purchasing and web payment

Install

npm install vigour-pay

Updates via upstream remote

Usage

See tests

Building native apps

See wrapper

Specs

Config

configuration for pay should go in the app's package.json

{
  "vigour": {
    "pay": {
      "android": {
        "billingKey": "SUPASECRETwhatevs",
        "products": {
          "single": {
            "id": "mtv-play_single_episode_purchase",
            "type": "single-purchase"
          },
          "monthly": {
          	"id": "mtvplay_subscription_monthly",
            "type": "monthly-recurring-subscription"
          },
          "yearly": {
          	"id": "mtvplay_single_purchase",
            "type": "yearly-recurring-subscription"
          }
        }
      },
      "iOS": {
        "products": {
          "single": "{region}_single_purchase",
          "monthly": "{region}_subscription_monthly",
          "yearly": "{region}_subscription_annual"
        }
      },
      "fire": {
        "products": {
          "single": "fire_single_id",
          "monthly": "fire_montly_id",
          "yearly": "fire_yearly_id"
        }
      }
    }
  }
}

Use of the Module

new Pay(settings)

var Pay = require('vigour-pay')

var pay = new Pay()
when using templating for region specific product id's: set region
config.region.on((region) => {
  pay.set({region: region})
})

pay.buy(label, callback(err, response))

pay.buy(label, callback) Will attempt to buy whatever product is configured as label for the current platform. label being single, monthly or yearly when using the above config.

button.onClick(() => {
  pay.buy('monthly', (err, response) => {
    if (err) { // something broke down
      throw err
    }
    var receipt = response.receipt
    if (receipt) { // purchased dat "monthly"!
    	user.set({owns: {monthly: receipt}}) // update the user
      if (myBackEndUpdater) { // lets tell some other back end
        myBackEndUpdater(user.id.val, receipt)
      }
    } else {
      // everything worked, but the user cancelled the purchase at some point
      // console.log('dude why dont u buy? (gif monne)')
    }
  })
})

pay.products (Observable property)

pay.products is a list of available products,

  • based on the config + platform
  • validated and completed by the native Plugin

e.g.

pay.products.val = {
  single: {
    val: 'NL_single_purchase',
    owned: {
      val: true,
      receipt: {
        hash: 'garblegarble'
      }
    },
    price: 0.99
  },
  monthly: {
    val: 'NL_monthly_subscription',
    owned: true,
    price: 4.99
  },
  yearly: {
    val: 'NL_yearly_subscription',
    price: 19.99
  }
}

pay.products[label].owned

owned is

  • if owned
    • true
    • could have receipt property when available
  • if not owned
    • false
    • undefined (property doesn't exist).

pay.products[label].price

Price is the number of pay.currency one has to pay in order to buy product.

pay.currency

The type of moneys the store wants to use.

pay.currency.val = {
  val: '€',
  name: 'Euro'
}

Native Plugins

Methods

buy(productId, callback(error, response))

  • buy the product with productId
  • when done, call callback passing
    • error
    • response

getProducts(callback(err, response))

Used to

  • get products available for this app on this platform

In order to

  • ensure products in package.json are actually available in the store
  • get product.price
  • get product.owned
response

response should look like:

var response = {
  productId1: {
    price: 999.01,
    owned: { // check if the device's store account owns the product
      val: true,
      receipt: 'RECEIPTFORPRODUCT'
    }
    // platform specific info may go here
  },
  productId2: {
    price: 0.99
  }
}