Skip to content

Latest commit

 

History

History
117 lines (82 loc) · 4.99 KB

README.md

File metadata and controls

117 lines (82 loc) · 4.99 KB

parse-iap-verify

TLDR: Payment verification should be easy; now it is.

If you are trying to earn a living or build a product on mobile, you need to monetize it. Many applications utilize 'In App Purchases' as the primary method of monetization. The best way of verifying purchases is via a server to server communication with the store that the purchase was made from.

If you use Parse.com as your backend server, you can use Cloud Code to make those calls. While some stores offer fairly straight forward verification steps, others are more convoluted and poorly documented.

This module makes it quick and easy so you don't have to reinvent the wheel for every new project (or spend days digging through documentation and trying various things), just like Parse does for standard backend db access, user login, etc.

Setup

Parse Project

  • parse-iap-verify cloned into ParseCloud/cloud/iapVerify of your project repo (submodules are nice)
  • ParseCloud running Parse JavaScript SDK 1.3.0+ (to utilize Parse.Config)
  • Parse.Config object named googlePlayAuth w/ key values for clientID, clientSecret and refreshToken

Apple App Store

  • No special setup required

Google Play Store

  1. Open a beer... this is going to take a while.
  2. Create a Google API service account Sign Up
  3. Create a new Project
  4. Enable Google Play Developer API
  5. Create Credentials for this project (skip the automatic setup)
  • Choose New Credentials button)
  • Select OAuth Client ID
  • Select Web Application
  • Fill in: (NOTE: The redirect URI doesn't really matter, but a working site is nice)
    • Name
    • Authorized redirect URIs
  • Record the Client ID and Client Secrect
  1. Visit the following URL in a browser: https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=WEB_REDIRECT_URI&client_id=WEB_CLIENT_ID
  2. Click Allow & authenticate yourself
  3. Once you arrive at the redirect site, copy the URI out of the addres bar
  4. Copy down the 'code' parameter value at the end of the URI ?code="1/......."
  5. Retrieve a refresh token to use when verifying receipts (curl example follows)
  1. Create Parse.Config object named googlePlayAuth with above clientID, clientSecret and refreshToken
  2. Celebrate

##Usage

Only a single method is exposed to verify purchase receipts:

var iap = require('cloud/iapVerify');

var platform = 'apple';
var payment = {
    receipt: 'receipt data',        // must be base64 for Apple
    productId: '0001',
    packageName: 'com.company.app'
};

iap.verifyPayment(platform, payment);

// Returns a Promise w/ JSON result
// SUCCESS - status = 0, receipt information passed verification
// {    'status':0,
//   'productId':'0001',
//     'receipt':{store_specific_receipt_data} 
// }
// FAILURES
// {    'status':123,
//    extraError:'informational string'
// }

References

Apple References

API Reference

Google Play References

API Reference

Receipt Generation

##Thank You Kudos to:

Kalina for outlining the steps required for Android IAP verification. Many people tried, but yours were the only ones that actually worked!

Stackoverflow Post

Wizcorp for highlighting so many great IAP references and a nice API interface in their Node-IAP module

Nick Lockwood for all of the amazing contributions he has shared with the community

Parse for building such a great BaaS and making it so easy to create great mobile products with a strong server component quickly

##Contributing Use Github issues to track bugs and feature requests.

Licence

MIT