wwx-iap0.5.0 • Public • Published
In-app purchase verification
Inspired by the iap_verifier CoffeeScript module
I also wanted to add support for other app stores, and not just limit this to Apple. The
module is exactly that. Pull requests to add support for other platforms are very welcome!
npm install iap
Only a single method is exposed to verify purchase receipts:
var iap = ;var platform = 'apple';var payment =receipt: 'receipt data' // always requiredproductId: '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.
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 passed back to your callback will also be Apple specific. The entire parsed receipt will be in the result object:
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 passed back to your callback will also be Google Play specific. The entire parsed response will be in the receipt sub-object.
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.
Google Play References