npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iap-apple

v2.0.5

Published

Integration with Apples InAppPurchases in Typescript, available for NodeJS environments.

Downloads

243

Readme

| Statements | Branches | Functions | Lines | | --------------------------- | ----------------------- | ------------------------- | ----------------- | | Statements | Branches | Functions | Lines |

iap-apple

https://img.shields.io/npm/v/iap-apple https://img.shields.io/github/issues-raw/ssbarbee/iap-apple https://img.shields.io/npm/dw/iap-apple

📦🚀 Integration of Apples  validation service for App Store Receipts, written in Typescript, available for NodeJS environments.

A NodeJS module for in-app purchase (in-app billing) and subscription for Apple.

Overview 🧐

Create a Typescript package for validation of App Store Receipts.
This package is meant to be used server side to validate receipts from the App Store by talking to Apples servers.

Installation 📦

npm

npm install iap-apple

yarn

yarn add iap-apple

API documentation 📚

verify 🧪

API used to verify receipt data received during an App Store purchase. Requires appSharedSecret to be passed as part of the configuration. See example for more details.


import { verify, IAPAppleError, IVerifyReceiptResponseBody } from 'iap-apple';

async function verifyAppleReceipt(receipt: string) {
    try {
        const verifyReceiptResponse = await verify(receipt, { 
            /*
              Your app's shared secret, which is a hexadecimal string. For more information about the shared secret.
              https://help.apple.com/app-store-connect/#/devf341c0f01
            */
            appSharedSecret, 
            /*
              To exclude old transaction, set this to true. 
              Default is false.
            */
            excludeOldTransactions: false,
            /*
              Force validation against Apple Sandbox only.
              In effect this means that the validation against Apple Production endpoint won't be used.
              Default is false.
            */
            test: false,
            /* 
              Optional can be omitted, pass logger object if you want to debug.
              Default is null object.
            */
            logger: console,
        });
        console.log('verifyReceiptResponse', verifyReceiptResponse);
    } catch(error) {
        const iapAppleError = error as IAPAppleError;
        const rejectionMessage: string = error.rejectionMessage;
        const errorData: IVerifyReceiptResponseBody | null = error.data;
        console.error('Error happened', rejectionMessage);
        console.error('Details', errorData);
    }
}

isVerifiedReceipt 🧪

API used to verify if response returned by verify is verified. Requires the output of verify to be passed. See example for more details.


import { verify, isVerifiedReceipt, IIAPAppleConfig } from 'iap-apple';

async function isVerifiedAppleReceipt(receipt: string, config: IIAPAppleConfig) {
    try {
        const verifyReceiptResponse = await verify(receipt, config);
        const isVerifiedReceipt = isVerifiedReceipt(verifyReceiptResponse);
    } catch(error) {
        const iapAppleError = error as IAPAppleError;
        const rejectionMessage: string = error.rejectionMessage;
        const errorData: IVerifyReceiptResponseBody | null = error.data;
        console.error('Error happened', rejectionMessage);
        console.error('Details', errorData);
    }
}

getPurchasedItems 🧪

API used to get an array of PurchasedItem objects from the Apple App Store response, sort by their purchase date descending. Usually what we are interested in is the first item of the purchase. Requires the output of verify to be passed. See example for more details.


import { verify, getPurchasedItems, IIAPAppleConfig } from 'iap-apple';

async function isVerifiedAppleReceipt(receipt: string, config: IIAPAppleConfig) {
    try {
        const verifyReceiptResponse = await verify(receipt, config);
        const purchasedItems = getPurchasedItems(verifyReceiptResponse);
        const latestPurchase = purchasedItems[0];
    } catch(error) {
        const iapAppleError = error as IAPAppleError;
        const rejectionMessage: string = error.rejectionMessage;
        const errorData: IVerifyReceiptResponseBody | null = error.data;
        console.error('Error happened', rejectionMessage);
        console.error('Details', errorData);
    }
}

isPurchasedItemCanceled 🧪

API used to check if a purchased item is canceled. Requires the output of getPurchasedItems to be passed. See example for more details.


import { verify, getPurchasedItems, isPurchasedItemCanceled, IIAPAppleConfig } from 'iap-apple';

async function isVerifiedAppleReceipt(receipt: string, config: IIAPAppleConfig) {
    try {
        const verifyReceiptResponse = await verify(receipt, config);
        const purchasedItems = getPurchasedItems(verifyReceiptResponse);
        const latestPurchase = purchasedItems[0];
        const isCanceled = isPurchasedItemCanceled(latestPurchase);
    } catch(error) {
        const iapAppleError = error as IAPAppleError;
        const rejectionMessage: string = error.rejectionMessage;
        const errorData: IVerifyReceiptResponseBody | null = error.data;
        console.error('Error happened', rejectionMessage);
        console.error('Details', errorData);
    }
}

isPurchasedItemExpired 🧪

API used to check if a purchased item is expired. Requires the output of getPurchasedItems to be passed. See example for more details.


import { verify, getPurchasedItems, isPurchasedItemExpired, IIAPAppleConfig } from 'iap-apple';

async function isVerifiedAppleReceipt(receipt: string, config: IIAPAppleConfig) {
    try {
        const verifyReceiptResponse = await verify(receipt, config);
        const purchasedItems = getPurchasedItems(verifyReceiptResponse);
        const latestPurchase = purchasedItems[0];
        const isExpired = isPurchasedItemExpired(latestPurchase);
    } catch(error) {
        const iapAppleError = error as IAPAppleError;
        const rejectionMessage: string = error.rejectionMessage;
        const errorData: IVerifyReceiptResponseBody | null = error.data;
        console.error('Error happened', rejectionMessage);
        console.error('Details', errorData);
    }
}