Skip to content

YunlongJiao-B/ziap_verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZIAP Verifier

Provide a consistent interface for iap verification on iOS/google play/amazon, etc.

Installation

First of all, you need to login to npm as 'zentertain', please set the email as 'dev@zentertain.net'

npm login

Once you get logged in, do:

npm install @zentertain/ziap_verifier

Usage

To verify a receipt

iOS

  var ziap_verifier = require('@zentertain/ziap_verifier');

  var verifier = ziap_verifier.createVerifier('ios');
  var payment = { receipt: 'receipt string' };
  verifier.verify(payment, function(error, valid) {
    if (error) {
      // Some error happened, check the error list in lib/errors.coffee
    }

    if (valid) {
      // the receipt is verified as valid
    }
  });

Google Play

  var ziap_verifier = require('@zentertain/ziap_verifier');

  var verifier = ziap_verifier.createVerifier('googleplay', { publicKey: 'The public key' });
  var payment = { receipt: 'receipt string', receiptSignature: 'receipt signature string' };
  verifier.verify(payment, function(error, valid) {
    if (error) {
      // Some error happened, check the error list in lib/errors.coffee
    }

    if (valid) {
      // the receipt is verified as valid
    }
  });

Amazon

  var ziap_verifier = require('@zentertain/ziap_verifier');

  var verifier = ziap_verifier.createVerifier('amazon', { secret: 'The secret string', version: '2' });
  var payment = { userId: 'user_id', receipt: 'receipt' };
  verifier.verify(payment, function(error, valid) {
    if (error) {
      // Some error happened, check the error list in lib/errors.coffee
    }

    if (valid) {
      // the receipt is verified as valid
    }
  });

Facebook

  var ziap_verifier = require('@zentertain/ziap_verifier');

  var verifier = ziap_verifier.createVerifier('facebook', { secret: 'The secret string' });
  var payment = { receipt: 'receipt string', receiptSignature: 'receipt signature string' };
  verifier.verify(payment, function(error, valid) {
    if (error) {
      // Some error happened, check the error list in lib/errors.coffee
    }

    if (valid) {
      // the receipt is verified as valid
    }
  });

If you want a promise

Just add 'P' as suffix to your calls, take amazon's as an example:

  var ziap_verifier = require('@zentertain/ziap_verifier');

  var verifier = ziap_verifier.createVerifierP('amazon', { secret: 'The secret string', version: '2' });
  var payment = { userId: 'user_id', receipt: 'receipt' };
  verifier.verifyP(payment).then(function(valid) {
    if (valid) {
      // the receipt is verified as valid
    }
  }).catch(function(e) {
    // Some error happened.
  }).done();

About

for @zentertain/ziap_verifier

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published