In-app purchase verification
Inspired by the iap_verifier CoffeeScript module
written by Paul Crawford, I wanted a pure JavaScript implementation of in-app purchase verification.
I also wanted to add support for other app stores, and not just limit this to Apple. The iap
module is exactly that. Pull requests to add support for other platforms are very welcome!
Installation
npm install iap
Usage
Only a single method is exposed to verify purchase receipts:
var iap = ; var platform = 'apple';var payment = receipt: 'receipt data' // always required productId: 'abc' packageName: 'my.app' subscription: true // optional, if google play subscription; iap;
The receipt you pass must conform to the requirements of the backend you are verifying with. Read the next chapter for more information on the format.
Supported platforms
Apple
The payment object
The receipt string passed may be either the base64 string that Apple really wants, or the decoded receipt as returned by the iOS SDK (in which case it will be automatically base64 serialized).
Both productId and packageName (bundle ID) are optional, but when provided will be tested against. If the receipt does not match the provided values, an error will be returned.
The response
The response passed back to your callback will also be Apple specific. The entire parsed receipt will be in the result object:
Google Play
The payment object
The receipt string is the purchase token that Google Play returns to the mobile application when a purchase is made.
Both packageName and productId are compulsory.
Lastly you must provide keyObject
which is the Google API Service Account JSON key file linked to your Google Play
account for authentication. This property can be either a string, file buffer or an object. If provided a string or file
buffer, the call will automatically parse it into an object for use.
The response
The response passed back to your callback will also be Google Play specific. The entire parsed response will be in the receipt sub-object.
All Platforms
Regardless of the platform used, besides the platform-specific receipt, the following properties will be included:
- transactionId, to uniquely identify this transaction.
- productId, which specifies what was purchased.
- platform, which is always the platform you passed.
License
MIT
References
Apple References
Code Inspiration
API Reference
Google Play References
Code Inspiration
- https://bitbucket.org/gooroo175/google-play-purchase-validator/src/d88278c30df0d0dc51b852b7bcab5f40e3a30923/index.js?at=master
- https://github.com/machadogj/node-google-bigquery
- https://github.com/extrabacon/google-oauth-jwt/blob/master/lib/request-jwt.js
API Reference
- https://developer.android.com/google/play/billing/gp-purchase-status-api.html
- https://developers.google.com/android-publisher/
- https://developers.google.com/android-publisher/getting_started
- https://developers.google.com/android-publisher/authorization
- https://developers.google.com/accounts/docs/OAuth2ServiceAccount
- https://developers.google.com/android-publisher/api-ref/purchases/products
- https://developers.google.com/android-publisher/api-ref/purchases/products/get
- http://developer.android.com/google/play/billing/billing_testing.html
- http://stackoverflow.com/questions/24323207/use-service-account-to-verify-google-inapppurchase
Receipt Generation