Skip to content

Repository files navigation

Apple Receipt Parser

Latest Version on NPM Scrutinizer build Scrutinizer quality Scrutinizer coverage Software License Monthly Downloads Total Downloads

A lightweight TypeScript library for extracting selected fields from Apple's ASN.1 encoded Unified Receipts.

Important

This library is not a full-fledged receipt parser. It extracts supported fields from Apple's ASN.1 encoded Unified Receipts, including in-app purchase receipts. It does not work with the old-style transaction receipts.

Caution

This library does not verify the receipt's PKCS#7 signature — it only checks that the ASN.1 structure has the expected shape. The extracted data is not cryptographically trustworthy on its own. Do not grant entitlements based on it without verifying the receipt signature (or using Apple's App Store Server API) separately.

Note

Documentation for the version 1.x of the library can be found here.

Installation

Using npm:

npm install @tamtamchik/app-store-receipt-parser

Using yarn:

yarn add @tamtamchik/app-store-receipt-parser

Usage

The result includes selected top-level receipt fields, aggregate in-app transaction IDs, and structured in-app receipt data in IN_APP_RECEIPTS.

import { parseReceipt } from '@tamtamchik/app-store-receipt-parser';

// Unified Receipt string 
const receiptString = "MII...";
const data = parseReceipt(receiptString);

console.log(data);
// {
//   ENVIRONMENT: 'ProductionSandbox',
//   APP_VERSION: '1',
//   ORIGINAL_APP_VERSION: '1.0',
//   OPAQUE_VALUE: 'c4dd4054b0b61a07beb585f6a842e048',
//   SHA1_HASH: '2e0a115beac1c57023a5bd37349955a9ad99db4d',
//   BUNDLE_ID: 'com.mbaasy.ios.demo',
//   RECEIPT_CREATION_DATE: '2015-08-13T07:50:46Z',
//   ORIGINAL_PURCHASE_DATE: '2013-08-01T07:00:00Z',
//   IN_APP_EXPIRES_DATE: '2015-08-10T07:19:32Z',
//   IN_APP_CANCELLATION_DATE: '',
//   IN_APP_QUANTITY: '1',
//   IN_APP_WEB_ORDER_LINE_ITEM_ID: '1000000030274249',
//   IN_APP_PRODUCT_ID: 'monthly',
//   IN_APP_TRANSACTION_ID: '1000000166967782',
//   IN_APP_TRANSACTION_IDS: [
//     '1000000166865231',
//     '1000000166965150',
//     '1000000166965327',
//     '1000000166965895',
//     '1000000166967152',
//     '1000000166967484',
//     '1000000166967782'
//   ],
//   IN_APP_RECEIPTS: [
//     // ...
//     {
//       IN_APP_EXPIRES_DATE: '2015-08-10T07:19:32Z',
//       IN_APP_CANCELLATION_DATE: '',
//       IN_APP_QUANTITY: '1',
//       IN_APP_WEB_ORDER_LINE_ITEM_ID: '1000000030274249',
//       IN_APP_PRODUCT_ID: 'monthly',
//       IN_APP_TRANSACTION_ID: '1000000166967782',
//       IN_APP_ORIGINAL_TRANSACTION_ID: '1000000166965150',
//       IN_APP_PURCHASE_DATE: '2015-08-10T07:14:32Z',
//       IN_APP_ORIGINAL_PURCHASE_DATE: '2015-08-10T07:12:34Z'
//     }
//   ],
//   IN_APP_ORIGINAL_TRANSACTION_ID: '1000000166965150',
//   IN_APP_ORIGINAL_TRANSACTION_IDS: [
//     '1000000166865231',
//     '1000000166965150'
//   ],
//   IN_APP_PURCHASE_DATE: '2015-08-10T07:14:32Z',
//   IN_APP_ORIGINAL_PURCHASE_DATE: '2015-08-10T07:12:34Z'
// }

Warning

Top-level scalar IN_APP_* fields (e.g. IN_APP_PRODUCT_ID, IN_APP_TRANSACTION_ID) hold the value from the last in-app purchase block encountered in the receipt, and Apple does not guarantee the order of those blocks. They are kept for backward compatibility — for reliable per-purchase data use IN_APP_RECEIPTS.

Special Thanks

  • @Jurajzovinec for his superb contribution to the project.
  • @fechy for bringing environment variable support to the lib.

Contributing

Pull requests are always welcome. If you have bigger changes, please open an issue first to discuss your ideas.

License

Apple Receipt Parser is MIT licensed.

Third-Party Licenses

This project uses ASN1.js, licensed under the BSD-3-Clause License. The license text can be found in LICENSE.


Buy Me A Coffee

About

A lightweight TypeScript library for extracting transaction IDs from Apple's ASN.1 encoded receipts.

Topics

Resources

Security policy

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages