oem-inapppurchases
v1.0.9
Published
TypeScript/Node.js package to verify in-app purchases for: - Google Play subscriptions - Apple App Store receipts
Downloads
235
Readme
oem-inapppurchases
TypeScript/Node.js package to verify in-app purchases for:
- Google Play subscriptions
- Apple App Store receipts
It exposes a factory (PaymentGatewayFactory) and a wrapper (InAppPurchases) so you can use one verification flow for both stores.
Installation
npm install oem-inapppurchasesExports
import { InAppPurchases, PaymentGatewayFactory } from "oem-inapppurchases";Gateway Names
Use these values with getPaymentGatewayObject(...):
playstoreappstore
Payload Requirements
Play Store payload
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| email | string | Yes | Google service account email |
| privateKey | string | Yes | Google service account private key |
| packageName | string | Yes | Android package name |
| productId | string | Yes | Subscription product ID |
| purchaseToken | string | Yes | Purchase token from client app |
App Store payload
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| secretKey | string | Yes | App-specific shared secret |
| dumpData | string | Yes | Base64 receipt data |
| sandbox | number | Yes | 0 for production, 1 for sandbox |
| sandBox | number | Recommended | Currently used internally for API selection (0 or 1) |
sandbox is validated, while sandBox is read during verification in the current implementation. Set both to the same value for compatibility.
Usage
Verify Google Play subscription
import { InAppPurchases, PaymentGatewayFactory } from "oem-inapppurchases";
const payload = {
email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL!,
privateKey: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY!.replace(/\\n/g, "\n"),
packageName: "com.example.app",
productId: "premium_monthly",
purchaseToken: "purchase-token-from-device"
};
const factory = new PaymentGatewayFactory();
const gateway = factory.getPaymentGatewayObject("playstore");
const iap = new InAppPurchases(payload);
const result = await iap.verifyPayment(gateway);
console.log(result);Verify App Store receipt
import { InAppPurchases, PaymentGatewayFactory } from "oem-inapppurchases";
const payload = {
secretKey: process.env.APPLE_SHARED_SECRET!,
dumpData: "base64-receipt-data",
sandbox: 0,
sandBox: 0
};
const factory = new PaymentGatewayFactory();
const gateway = factory.getPaymentGatewayObject("appstore");
const iap = new InAppPurchases(payload);
const result = await iap.verifyPayment(gateway);
console.log(result);Get normalized response data
Use verifyPaymentWithData(...) when you want a normalized wrapper:
const result = await iap.verifyPaymentWithData(gateway);
// { status: boolean, data: any }Typical Response Shape
{
status: true,
data: { ...storeResponse }
}Error Cases
You should handle thrown errors in your service layer. Common messages include:
Payment Gateway Not Found- validation errors for missing required fields
Unable to verify payment(App Store failures)Failed to verify purchase:<statusText>(Play Store failures)
Development
npm run build
npm run devCurrent scripts:
build: compiles TypeScript and copies.envtodist/.envdev: runsindex.tswith nodemon
License
ISC
