Node.js library for Apple and Google IAP.
yarn add @jeremybarbet/node-iap
Getting a service account up and running is surprisingly really hard. Mostly, because of a mix of permissions, scopes, and order in which you are doing all these operations has a huge impact.
- I recommend following this official documentation to create a new service account. This library use service account's clientEmail and privateKey, so you can ignore the "OAuth client" paragraphs.
- Generate an Apple password through the App Store Connect. I recommend creating an "app-specific shared secret".
import { verifyAppleReceipt, verifyGoogleReceipt } from '@jeremybarbet/node-iap';
const { data } = verifyAppleReceipt(
{
transactionReceipt: 'BASE_64_RECEIPT',
},
{
password: 'APPLE_PASSWORD',
},
);
const { data } = verifyGoogleReceipt(
{
packageName: 'PACKAGE_NAME',
token: 'TOKEN',
productId: 'PRODUCT_ID',
},
{
clientEmail: 'GOOGLE_CLIENT_EMAIL',
privateKey: 'GOOGLE_PRIVATE_KEY',
},
);
You can find an example in the example directory.
You will first, need to duplicate the data.example.json
file, rename it data.json
and provide your own Apple and Google credentials and receipt data. Then you can run the example:
yarn ts-node ./packages/node-iap/example/index.ts
- Apple
- Part of the code and features are inspired by in-app-purchase's library.
This library is licensed under the MIT License.