In-App Purchase

In-App-Purchase is a way for the end uers to buy contents in applications such as iOS app, Android app etc.

This is a documentation on npm module called in-app-purchase.
This module helps node.js developers to deal with In-App Purchase without worrying about each individual platform specific details on the server-side validation.

Module's repository is here.

Detailed documentation is here.

Author: voltrue2

Try Validate Purchase Online

We do NOT store the receipt and public key/shared secret given on the server.

NOTE: If you are trying to validate subscription receipt of Apple, you will need to input shared secret along with the receipt.

For Apple Subscription, Android, and Amazon, You need to store the Public Key/Secret on the server.

 Receipt
Public Key/Secret
Validate

Supported Platforms

Apple Android Amazon Windows Roku

How To Install

You may install the module using npm as shown below:

$ npm install in-app-purchase

How To Add Module as Dependency

In your package.json file, add the following:

"dependencies": {
	"in-app-purchase": "1.0.4"
}

Validate With Apple

Apple purchase receipt is a Base64 String. For the first argument of iap.validate(), use iap.APPLE constant.

var iap = require('in-app-purchase');
iap.config({
  // If your purchase item is subscription type, you need this
  applePassword: '[shared secrect from iTunes Connect]'
});
iap.setup(function (error) {
  if (error) {
    // Don't forget to catch error here
  }
  // As of v1.4.0+ .validate and .validateOnce detects service automatically from the receipt
  iap.validate(receipt, function (error, response) {
    if (error) {
      // Failed to validate
    }
    if (iap.isValidated(response)) {
      // Succuessful validation
    }
  });
});

Validate With Google

Google purchase receipt is a javascript object. It must contain both data and signature. The module can handle either in object or string format. For the first argument of iap.validate(), use iap.GOOGLE constant.
NOTE: For Google validation, module requires the public key provided by Google. for more details, please read the followings:
Public Key From Files
Public Key As Strings
Public Key From ENV
The example uses public key from file approach.

var iap = require('in-app-purchase');
iap.config({
  googlePublicKeyPath: '/path/to/your/public/key/'
});
iap.setup(function (error) {
  if (error) {
    // Don't forget to catch error here
  }
  // As of v1.4.0+ .validate and .validateOnce detects service automatically from the receipt
  iap.validate(receipt, function (error, response) {
    if (error) {
      // Failed to validate
    }
    if (iap.isValidated(response)) {
      // Succuessful validation
    }
  });
});

Validate With Amazon

Amazon purchase receipt is a javascript object. To validate Amazon purchase, the module requires a shared secret as a string passed to the configuration. For the first argument of iap.validate(), use iap.AMAZON constant.

var iap = require('in-app-purchase');
iap.config({
  secret: 'shared secrect from amazon'
});
iap.setup(function (error) {
  if (error) {
    // Don't forget to catch error here
  }
  // As of v1.4.0+ .validate and .validateOnce detects service automatically from the receipt
  iap.validate(receipt, function (error, response) {
    if (error) {
      // Failed to validate
    }
    if (iap.isValidated(response)) {
      // Successful validation
    }
  });
});

Validate With Roku

Roku purchase receipt is a string. To validate Roku purchase, the module requires an API key as a string passed to the configuration. For the first argument of iap.validate(), use iap.ROKU constant.

var iap = require('in-app-purchase');
iap.config({
  rokuApiKey: 'API key from ROKU'
});
iap.setup(function (error) {
  if (error) {
    // Don't forget to catch error here
  }
  // As of v1.4.0+ .validate and .validateOnce detects service automatically from the receipt
  iap.validate(receipt, function (error, response) {
    if (error) {
      // Failed to validate
    }
    if (iap.isValidated(response)) {
      // Successful validation
    }
  });
});

Validate With Windows

Amazon purchase receipt is a signed XML string. For the first argument of iap.validate(), use iap.WINDOWS constant.

var iap = require('in-app-purchase');
iap.setup(function (error) {
  if (error) {
    // Don't forget to catch error here
  }
  // As of v1.4.0+ .validate and .validateOnce detects service automatically from the receipt
  iap.validate(receipt, function (error, response) {
    if (error) {
      // Failed to validate
    }
    if (iap.isValidated(response)) {
      // Successful validation
    }
  });
});