Skip to main content

modules

react-native-iap / Exports

react-native-iap

Table of contents

References

Namespaces

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

References

AmazonModule

Re-exports AmazonModule


AmazonModuleProps

Re-exports AmazonModuleProps


AndroidModule

Re-exports AndroidModule


AndroidModuleProps

Re-exports AndroidModuleProps


BuyItemByType

Re-exports BuyItemByType


BuyProduct

Re-exports BuyProduct


IosModuleProps

Re-exports IosModuleProps


acknowledgePurchaseAndroid

Re-exports acknowledgePurchaseAndroid


buyPromotedProductIOS

Re-exports buyPromotedProductIOS


clearProductsIOS

Re-exports clearProductsIOS


clearTransactionIOS

Re-exports clearTransactionIOS


deepLinkToSubscriptionsAmazon

Re-exports deepLinkToSubscriptionsAmazon


deepLinkToSubscriptionsAndroid

Re-exports deepLinkToSubscriptionsAndroid


deepLinkToSubscriptionsIos

Re-exports deepLinkToSubscriptionsIos


getInstallSourceAndroid

Re-exports getInstallSourceAndroid


getPendingPurchasesIOS

Re-exports getPendingPurchasesIOS


getPromotedProductIOS

Re-exports getPromotedProductIOS


getReceiptIOS

Re-exports getReceiptIOS


isFeatureSupported

Re-exports isFeatureSupported


presentCodeRedemptionSheetIOS

Re-exports presentCodeRedemptionSheetIOS


validateReceiptAmazon

Re-exports validateReceiptAmazon


validateReceiptAndroid

Re-exports validateReceiptAndroid


validateReceiptIos

Re-exports validateReceiptIos


verifyLicense

Re-exports verifyLicense

Type Aliases

AmazonPlatform

Ƭ AmazonPlatform: Object

Type declaration

NameType
platform"amazon"

Defined in

types/index.ts:15


AndroidPlatform

Ƭ AndroidPlatform: Object

Type declaration

NameType
platform"android"

Defined in

types/index.ts:14


IosPlatform

Ƭ IosPlatform: Object

Type declaration

NameType
platform"ios"

Defined in

types/index.ts:13


Product

Ƭ Product: ProductAndroid & ProductIOS

Defined in

types/index.ts:196


ProductLegacy

Ƭ ProductLegacy: ProductAndroid & ProductIOS

Defined in

types/index.ts:188


ProductWithPlatform

Ƭ ProductWithPlatform: ProductAndroid & AndroidPlatform | ProductIOS & IosPlatform

Defined in

types/index.ts:191


ProrationModesAmazon

Ƭ ProrationModesAmazon: "" | "DEFERRED" | "IMMEDIATE"

Defined in

types/index.ts:17


Purchase

Ƭ Purchase: ProductPurchase | SubscriptionPurchase

Defined in

types/index.ts:157


PurchaseWithPlatform

Ƭ PurchaseWithPlatform: ProductPurchase & { productIds?: string[] } & AndroidPlatform | ProductPurchase & { quantityIOS?: number } & IosPlatform | ProductPurchase & { userIdAmazon?: string } & AmazonPlatform | SubscriptionPurchase

Defined in

types/index.ts:150


RequestPurchase

Ƭ RequestPurchase: RequestPurchaseAndroid | RequestPurchaseAmazon | RequestPurchaseIOS

Defined in

types/index.ts:300


RequestPurchaseAmazon

Ƭ RequestPurchaseAmazon: RequestPurchaseIOS

As of 2022-10-12, we only use the sku field for Amazon purchases

Defined in

types/index.ts:298


RequestSubscription

Ƭ RequestSubscription: RequestSubscriptionAndroid | RequestSubscriptionAmazon | RequestSubscriptionIOS

Defined in

types/index.ts:327


RequestSubscriptionIOS

Ƭ RequestSubscriptionIOS: RequestPurchaseIOS

Defined in

types/index.ts:320


STOREKIT_OPTIONS

Ƭ STOREKIT_OPTIONS: "STOREKIT1_MODE" | "STOREKIT_HYBRID_MODE" | "STOREKIT2_MODE"

STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before, minimum changes required in the migration guide (default) HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices There are some edge cases that you need to handle in this case (described in migration guide). This mode is for developers that are migrating to Storekit 2 but want to keep supporting older versions. STOREKIT2_MODE: Will only enable Storekit 2. This disables Storekit 1. This is for apps that have already targeted a min version of 15 for their app.

Defined in

iap.ts:61


Sku

Ƭ Sku: string

Defined in

types/index.ts:10


Subscription

Ƭ Subscription: SubscriptionAndroid | SubscriptionAmazon | SubscriptionIOS

Defined in

types/index.ts:271


SubscriptionIosPeriod

Ƭ SubscriptionIosPeriod: "DAY" | "WEEK" | "MONTH" | "YEAR" | ""

Defined in

types/index.ts:252

Variables

ErrorCodeMapping

Const ErrorCodeMapping: Object

Platform-specific error code mappings Maps ErrorCode enum values to platform-specific integer codes

Type declaration

NameType
android{ E_ACTIVITY_UNAVAILABLE: "E_ACTIVITY_UNAVAILABLE" = 'E_ACTIVITY_UNAVAILABLE'; E_ALREADY_OWNED: "E_ALREADY_OWNED" = 'E_ALREADY_OWNED'; E_ALREADY_PREPARED: "E_ALREADY_PREPARED" = 'E_ALREADY_PREPARED'; E_BILLING_RESPONSE_JSON_PARSE_ERROR: "E_BILLING_RESPONSE_JSON_PARSE_ERROR" = 'E_BILLING_RESPONSE_JSON_PARSE_ERROR'; E_CONNECTION_CLOSED: "E_CONNECTION_CLOSED" = 'E_CONNECTION_CLOSED'; E_DEFERRED_PAYMENT: "E_DEFERRED_PAYMENT" = 'E_DEFERRED_PAYMENT'; E_DEVELOPER_ERROR: "E_DEVELOPER_ERROR" = 'E_DEVELOPER_ERROR'; E_IAP_NOT_AVAILABLE: "E_IAP_NOT_AVAILABLE" = 'E_IAP_NOT_AVAILABLE'; E_INTERRUPTED: "E_INTERRUPTED" = 'E_INTERRUPTED'; E_ITEM_UNAVAILABLE: "E_ITEM_UNAVAILABLE" = 'E_ITEM_UNAVAILABLE'; E_NETWORK_ERROR: "E_NETWORK_ERROR" = 'E_NETWORK_ERROR'; E_NOT_ENDED: "E_NOT_ENDED" = 'E_NOT_ENDED'; E_NOT_PREPARED: "E_NOT_PREPARED" = 'E_NOT_PREPARED'; E_PENDING: "E_PENDING" = 'E_PENDING'; E_PURCHASE_ERROR: "E_PURCHASE_ERROR" = 'E_PURCHASE_ERROR'; E_RECEIPT_FAILED: "E_RECEIPT_FAILED" = 'E_RECEIPT_FAILED'; E_RECEIPT_FINISHED_FAILED: "E_RECEIPT_FINISHED_FAILED" = 'E_RECEIPT_FINISHED_FAILED'; E_REMOTE_ERROR: "E_REMOTE_ERROR" = 'E_REMOTE_ERROR'; E_SERVICE_ERROR: "E_SERVICE_ERROR" = 'E_SERVICE_ERROR'; E_SYNC_ERROR: "E_SYNC_ERROR" = 'E_SYNC_ERROR'; E_TRANSACTION_VALIDATION_FAILED: "E_TRANSACTION_VALIDATION_FAILED" = 'E_TRANSACTION_VALIDATION_FAILED'; E_UNKNOWN: "E_UNKNOWN" = 'E_UNKNOWN'; E_USER_CANCELLED: "E_USER_CANCELLED" = 'E_USER_CANCELLED'; E_USER_ERROR: "E_USER_ERROR" = 'E_USER_ERROR' }
android.E_ACTIVITY_UNAVAILABLE"E_ACTIVITY_UNAVAILABLE"
android.E_ALREADY_OWNED"E_ALREADY_OWNED"
android.E_ALREADY_PREPARED"E_ALREADY_PREPARED"
android.E_BILLING_RESPONSE_JSON_PARSE_ERROR"E_BILLING_RESPONSE_JSON_PARSE_ERROR"
android.E_CONNECTION_CLOSED"E_CONNECTION_CLOSED"
android.E_DEFERRED_PAYMENT"E_DEFERRED_PAYMENT"
android.E_DEVELOPER_ERROR"E_DEVELOPER_ERROR"
android.E_IAP_NOT_AVAILABLE"E_IAP_NOT_AVAILABLE"
android.E_INTERRUPTED"E_INTERRUPTED"
android.E_ITEM_UNAVAILABLE"E_ITEM_UNAVAILABLE"
android.E_NETWORK_ERROR"E_NETWORK_ERROR"
android.E_NOT_ENDED"E_NOT_ENDED"
android.E_NOT_PREPARED"E_NOT_PREPARED"
android.E_PENDING"E_PENDING"
android.E_PURCHASE_ERROR"E_PURCHASE_ERROR"
android.E_RECEIPT_FAILED"E_RECEIPT_FAILED"
android.E_RECEIPT_FINISHED_FAILED"E_RECEIPT_FINISHED_FAILED"
android.E_REMOTE_ERROR"E_REMOTE_ERROR"
android.E_SERVICE_ERROR"E_SERVICE_ERROR"
android.E_SYNC_ERROR"E_SYNC_ERROR"
android.E_TRANSACTION_VALIDATION_FAILED"E_TRANSACTION_VALIDATION_FAILED"
android.E_UNKNOWN"E_UNKNOWN"
android.E_USER_CANCELLED"E_USER_CANCELLED"
android.E_USER_ERROR"E_USER_ERROR"
ios{ E_ACTIVITY_UNAVAILABLE: 20 = 20; E_ALREADY_OWNED: 16 = 16; E_ALREADY_PREPARED: 21 = 21; E_BILLING_RESPONSE_JSON_PARSE_ERROR: 17 = 17; E_CONNECTION_CLOSED: 23 = 23; E_DEFERRED_PAYMENT: 12 = 12; E_DEVELOPER_ERROR: 9 = 9; E_IAP_NOT_AVAILABLE: 19 = 19; E_INTERRUPTED: 18 = 18; E_ITEM_UNAVAILABLE: 4 = 4; E_NETWORK_ERROR: 6 = 6; E_NOT_ENDED: 15 = 15; E_NOT_PREPARED: 14 = 14; E_PENDING: 22 = 22; E_PURCHASE_ERROR: 10 = 10; E_RECEIPT_FAILED: 7 = 7; E_RECEIPT_FINISHED_FAILED: 8 = 8; E_REMOTE_ERROR: 5 = 5; E_SERVICE_ERROR: 1 = 1; E_SYNC_ERROR: 11 = 11; E_TRANSACTION_VALIDATION_FAILED: 13 = 13; E_UNKNOWN: 0 = 0; E_USER_CANCELLED: 2 = 2; E_USER_ERROR: 3 = 3 }
ios.E_ACTIVITY_UNAVAILABLE20
ios.E_ALREADY_OWNED16
ios.E_ALREADY_PREPARED21
ios.E_BILLING_RESPONSE_JSON_PARSE_ERROR17
ios.E_CONNECTION_CLOSED23
ios.E_DEFERRED_PAYMENT12
ios.E_DEVELOPER_ERROR9
ios.E_IAP_NOT_AVAILABLE19
ios.E_INTERRUPTED18
ios.E_ITEM_UNAVAILABLE4
ios.E_NETWORK_ERROR6
ios.E_NOT_ENDED15
ios.E_NOT_PREPARED14
ios.E_PENDING22
ios.E_PURCHASE_ERROR10
ios.E_RECEIPT_FAILED7
ios.E_RECEIPT_FINISHED_FAILED8
ios.E_REMOTE_ERROR5
ios.E_SERVICE_ERROR1
ios.E_SYNC_ERROR11
ios.E_TRANSACTION_VALIDATION_FAILED13
ios.E_UNKNOWN0
ios.E_USER_CANCELLED2
ios.E_USER_ERROR3

Defined in

purchaseError.ts:32


ErrorCodeUtils

Const ErrorCodeUtils: Object

Utility functions for error code mapping and validation

Type declaration

NameType
fromPlatformCode(platformCode: string | number, platform: "ios" | "android") => ErrorCode
isValidForPlatform(errorCode: ErrorCode, platform: "ios" | "android") => boolean
toPlatformCode(errorCode: ErrorCode, platform: "ios" | "android") => string | number

Defined in

purchaseError.ts:146


Const PROMOTED_PRODUCT: "iap-promoted-product"

Defined in

types/index.ts:34

Functions

deepLinkToSubscriptions

deepLinkToSubscriptions(«destructured»): Promise\<void>

Deeplinks to native interface that allows users to manage their subscriptions

Parameters

NameType
«destructured»Object
› isAmazonDevice?boolean
› sku?string

Returns

Promise\<void>

Defined in

iap.ts:913


endConnection

endConnection(): Promise\<boolean>

Disconnects from native SDK Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {endConnection} from 'react-native-iap';

const App = () => {
useEffect(() => {
return () => {
void endConnection();
};
}, []);

return <View />;
};

Returns

Promise\<boolean>

Defined in

iap.ts:127


finishTransaction

finishTransaction(«destructured»): Promise\<boolean | PurchaseResult>

Finish Transaction (both platforms) Abstracts Finish Transaction iOS: Tells StoreKit that you have delivered the purchase to the user and StoreKit can now let go of the transaction. Call this after you have persisted the purchased state to your server or local data in your app. react-native-iap will continue to deliver the purchase updated events with the successful purchase until you finish the transaction. Even after the app has relaunched. Android: it will consume purchase for consumables and acknowledge purchase for non-consumables.

import React from 'react';
import {Button} from 'react-native';
import {finishTransaction} from 'react-native-iap';

const App = () => {
const handlePurchase = async () => {
// ... handle the purchase request

const result = finishTransaction({purchase});
};

return <Button title="Buy product" onPress={handlePurchase} />;
};

Parameters

NameType
«destructured»Object
› developerPayloadAndroid?string
› isConsumable?boolean
› purchasePurchase

Returns

Promise\<boolean | PurchaseResult>

Android: PurchaseResult, iOS: true

Defined in

iap.ts:857


flushFailedPurchasesCachedAsPendingAndroid

flushFailedPurchasesCachedAsPendingAndroid(): Promise\<boolean>

Consume all 'ghost' purchases (that is, pending payment that already failed but is still marked as pending in Play Store cache). Android only.

Returns

Promise\<boolean>

Defined in

iap.ts:135


getAvailablePurchases

getAvailablePurchases(:boolean?): Promise\<Purchase[]>

Get all purchases made by the user (either non-consumable, or haven't been consumed yet)

Usage

import React, {useCallback} from 'react';
import {View} from 'react-native';
import {getAvailablePurchases} from 'react-native-iap';

const App = () => {
const availablePurchases = useCallback(
async () => await getAvailablePurchases(),
[],
);

return <View />;
};

Restoring purchases

You can use getAvailablePurchases() to do what's commonly understood as "restoring" purchases.

note

For debugging you may want to consume all items, you have then to iterate over the purchases returned by getAvailablePurchases().

danger

Beware that if you consume an item without having recorded the purchase in your database the user may have paid for something without getting it delivered and you will have no way to recover the receipt to validate and restore their purchase.

import React from 'react';
import {Button} from 'react-native';
import {getAvailablePurchases,finishTransaction} from 'react-native-iap';

const App = () => {
handleRestore = async () => {
try {
const purchases = await getAvailablePurchases();
const newState = {premium: false, ads: true};
let titles = [];

await Promise.all(purchases.map(async purchase => {
switch (purchase.productId) {
case 'com.example.premium':
newState.premium = true;
titles.push('Premium Version');
break;

case 'com.example.no_ads':
newState.ads = false;
titles.push('No Ads');
break;

case 'com.example.coins100':
await finishTransaction({purchase});
CoinStore.addCoins(100);
}
}));

Alert.alert(
'Restore Successful',
`You successfully restored the following purchases: ${titles.join(', ')}`,
);
} catch (error) {
console.warn(error);
Alert.alert(error.message);
}
};

return (
<Button title="Restore purchases" onPress={handleRestore} />
)
};

Parameters

NameTypeDescription
:booleanObjectWhen true, every element will also be pushed to the purchaseUpdated listener. Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to false
:boolean.alsoPublishToEventListener?boolean-
:boolean.automaticallyFinishRestoredTransactions?boolean-
:boolean.onlyIncludeActiveItems?boolean-

Returns

Promise\<Purchase[]>

See

https://developer.apple.com/documentation/storekit/transaction/3851204-currententitlements for details

Defined in

iap.ts:465


getDisplayPrice

getDisplayPrice(item): string

Helper to get the display price from either field name

Parameters

NameType
itemObject
item.displayPrice?string
item.localizedPrice?string

Returns

string

Defined in

utils/typeGuards.ts:85


getProductId

getProductId(item): string

Helper to get the product ID from either field name

Parameters

NameType
itemObject
item.id?string
item.productId?string

Returns

string

Defined in

utils/typeGuards.ts:78


getProducts

getProducts(«destructured»): Promise\<Product[]>

Get a list of products (consumable and non-consumable items, but not subscriptions)

Usage

import React, {useState} from 'react';
import {Platform} from 'react-native';
import {getProducts, Product} from 'react-native-iap';

const skus = Platform.select({
ios: ['com.example.consumableIos'],
android: ['com.example.consumableAndroid'],
});

const App = () => {
const [products, setProducts] = useState<Product[]>([]);

const handleProducts = async () => {
const items = await getProducts({skus});

setProducts(items);
};

useEffect(() => {
void handleProducts();
}, []);

return (
<>
{products.map((product) => (
<Text key={product.productId}>{product.productId}</Text>
))}
</>
);
};

Just a few things to keep in mind:

  • You can get your products in componentDidMount, useEffect or another appropriate area of your app.
  • Since a user may start your app with a bad or no internet connection, preparing/getting the items more than once may be a good idea.
  • If the user has no IAPs available when the app starts first, you may want to check again when the user enters your IAP store.

Parameters

NameType
«destructured»Object
› skusstring[]

Returns

Promise\<Product[]>

Defined in

iap.ts:182


getPurchaseHistory

getPurchaseHistory(«destructured»?): Promise\<Purchase[]>

Gets an inventory of purchases made by the user regardless of consumption status

Usage

import React, {useCallback} from 'react';
import {View} from 'react-native';
import {getPurchaseHistory} from 'react-native-iap';

const App = () => {
const history = useCallback(
async () =>
await getPurchaseHistory([
'com.example.product1',
'com.example.product2',
]),
[],
);

return <View />;
};

Parameters

NameType
«destructured»Object
› alsoPublishToEventListener?boolean
› automaticallyFinishRestoredTransactions?boolean
› onlyIncludeActiveItems?boolean

Returns

Promise\<Purchase[]>

See

https://developer.apple.com/documentation/storekit/transaction/3851204-currententitlements for details

Defined in

iap.ts:338


getStorefront

getStorefront(): Promise\<string>

Get App Store and Google Play device region.

App Store: string - ISO 3166-1 Alpha-3 country code representation https://developer.apple.com/documentation/storekit/storefront.

Google Play: string - ISO-3166-1 alpha2 country code representation https://developer.android.com/reference/com/android/billingclient/api/BillingConfig#getCountryCode()

import React from 'react';
import {getStorefront} from 'react-native-iap';

const App = () => {
React.useEffect(() => {
getStorefront().then((countryCode) => {
// ... handle region
});
}, []);
};

Returns

Promise\<string>

Defined in

iap.ts:962


getSubscriptions

getSubscriptions(«destructured»): Promise\<Subscription[]>

Get a list of subscriptions

Usage

import React, {useCallback} from 'react';
import {View} from 'react-native';
import {getSubscriptions} from 'react-native-iap';

const App = () => {
const subscriptions = useCallback(
async () =>
await getSubscriptions({skus:['com.example.product1', 'com.example.product2']}),
[],
);

return <View />;
};

Parameters

NameType
«destructured»Object
› skusstring[]

Returns

Promise\<Subscription[]>

Defined in

iap.ts:235


getUserFriendlyErrorMessage

getUserFriendlyErrorMessage(error): string

Gets a user-friendly error message for display

Parameters

NameTypeDescription
erroranyError object or error code

Returns

string

User-friendly error message

Defined in

utils/errorMapping.ts:63


initConnection

initConnection(): Promise\<boolean>

Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {initConnection} from 'react-native-iap';

const App = () => {
useEffect(() => {
void initConnection();
}, []);

return <View />;
};

Returns

Promise\<boolean>

Defined in

iap.ts:104


isIosStorekit2

isIosStorekit2(): boolean

Returns

boolean

Defined in

internal/platform.ts:75


isNetworkError

isNetworkError(error): boolean

Checks if an error is related to network connectivity

Parameters

NameTypeDescription
erroranyError object or error code

Returns

boolean

True if the error is network-related

Defined in

utils/errorMapping.ts:30


isProductAndroid

isProductAndroid(product): product is ProductAndroid & ProductIOS & Object

Type guard to check if a product is from Android

Parameters

NameType
productProduct | ProductWithPlatform

Returns

product is ProductAndroid & ProductIOS & Object

Defined in

utils/typeGuards.ts:27


isProductIos

isProductIos(product): product is ProductAndroid & ProductIOS & Object

Type guard to check if a product is from iOS

Parameters

NameType
productProduct | ProductWithPlatform

Returns

product is ProductAndroid & ProductIOS & Object

Defined in

utils/typeGuards.ts:18


isProductPurchase

isProductPurchase(item): item is ProductPurchase

Type guard to check if an item is a ProductPurchase

Parameters

NameType
itemunknown

Returns

item is ProductPurchase

Defined in

utils/typeGuards.ts:65


isPurchaseAmazon

isPurchaseAmazon(purchase): purchase is Object

Type guard to check if a purchase is from Amazon

Parameters

NameType
purchaseProductPurchase | SubscriptionPurchase | ProductPurchase & { productIds?: string[] } & AndroidPlatform | ProductPurchase & { quantityIOS?: number } & IosPlatform | ProductPurchase & { userIdAmazon?: string } & AmazonPlatform

Returns

purchase is Object

Defined in

utils/typeGuards.ts:54


isPurchaseAndroid

isPurchaseAndroid(purchase): purchase is Object

Type guard to check if a purchase is from Android

Parameters

NameType
purchaseProductPurchase | SubscriptionPurchase | ProductPurchase & { productIds?: string[] } & AndroidPlatform | ProductPurchase & { quantityIOS?: number } & IosPlatform | ProductPurchase & { userIdAmazon?: string } & AmazonPlatform

Returns

purchase is Object

Defined in

utils/typeGuards.ts:45


isPurchaseIos

isPurchaseIos(purchase): purchase is Object

Type guard to check if a purchase is from iOS

Parameters

NameType
purchaseProductPurchase | SubscriptionPurchase | ProductPurchase & { productIds?: string[] } & AndroidPlatform | ProductPurchase & { quantityIOS?: number } & IosPlatform | ProductPurchase & { userIdAmazon?: string } & AmazonPlatform

Returns

purchase is Object

Defined in

utils/typeGuards.ts:36


isRecoverableError

isRecoverableError(error): boolean

Checks if an error is recoverable (user can retry)

Parameters

NameTypeDescription
erroranyError object or error code

Returns

boolean

True if the error is potentially recoverable

Defined in

utils/errorMapping.ts:46


isUserCancelledError

isUserCancelledError(error): boolean

Checks if an error is a user cancellation

Parameters

NameTypeDescription
erroranyError object or error code

Returns

boolean

True if the error represents user cancellation

Defined in

utils/errorMapping.ts:13


promotedProductListener

promotedProductListener(listener): null | EmitterSubscription

Add IAP promoted subscription event Add IAP promoted subscription event.

Signature

promotedProductListener((productId?: string) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {promotedProductListener} from 'react-native-iap';

const App = () => {
useEffect(() => {
const subscription = promotedProductListener((productId) => {
console.log(productId);
});

return () => {
subscription.remove();
};
}, []);

return <View />;
};

Parameters

NameType
listener() => void

Returns

null | EmitterSubscription

Platform

iOS

Defined in

eventEmitter.ts:150


purchaseErrorListener

purchaseErrorListener(listener): EmitterSubscription

Add IAP purchase error event Register a callback that gets called when there has been an error with a purchase. Returns a React Native EmitterSubscription on which you can call .remove() to stop receiving updates.

Signature

purchaseErrorListener((error: PurchaseError) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {purchaseErrorListener} from 'react-native-iap';

const App = () => {
useEffect(() => {
const subscription = purchaseErrorListener((error: PurchaseError) => {
console.log(error);
});

return () => {
subscription.remove();
};
}, []);

return <View />;
};

Parameters

NameType
listener(error: PurchaseError) => void

Returns

EmitterSubscription

Defined in

eventEmitter.ts:108


purchaseUpdatedListener

purchaseUpdatedListener(listener, errorCallback?): EmitterSubscription

Add IAP purchase event Register a callback that gets called when the store has any updates to purchases that have not yet been finished, consumed or acknowledged. Returns a React Native EmitterSubscription on which you can call .remove() to stop receiving updates. Register you listener as soon as possible and react to updates at all times.

Signature

purchaseUpdatedListener((purchase: Purchase) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {purchaseUpdatedListener} from 'react-native-iap';

const App = () => {
useEffect(() => {
const subscription = purchaseUpdatedListener((purchase: Purchase) => {
console.log(purchase);
});

return () => {
subscription.remove();
};
}, []);

return <View />;
};

Parameters

NameType
listener(event: Purchase) => void
errorCallback?(error: unknown) => void

Returns

EmitterSubscription

Defined in

eventEmitter.ts:47


requestPurchase

requestPurchase(request): Promise\<void | ProductPurchase | ProductPurchase[]>

Request a purchase for product. This will be received in PurchaseUpdatedListener. Request a purchase for a product (consumables or non-consumables).

The response will be received through the PurchaseUpdatedListener.

note

andDangerouslyFinishTransactionAutomatically defaults to false. We recommend always keeping at false, and verifying the transaction receipts on the server-side.

Signature

requestPurchase(
The product's sku/ID
sku,

* You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user.
* @default false

andDangerouslyFinishTransactionAutomaticallyIOS = false,

/** Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
obfuscatedAccountIdAndroid,

Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
obfuscatedProfileIdAndroid,

The purchaser's user ID
applicationUsername,
): Promise<ProductPurchase>;

Usage

import React, { useState, useEffect } from 'react';
import {Button} from 'react-native';
import {requestPurchase, Product, Sku, getProducts} from 'react-native-iap';

const App = () => {
const [products, setProducts] = useState<Product[]>([]);

useEffect(() => {
const fetchProducts = async () => {
const productList = await getProducts({skus:['com.example.product']});
setProducts(productList);
}

fetchProducts();
}, []);

const handlePurchase = async (sku: Sku) => {
await requestPurchase({sku});
};

return (
<>
{products.map((product) => (
<Button
key={product.productId}
title="Buy product"
onPress={() => handlePurchase(product.productId)}
/>
))}
</>
);
};

Parameters

NameType
requestRequestPurchase

Returns

Promise\<void | ProductPurchase | ProductPurchase[]>

Defined in

iap.ts:584


requestSubscription

requestSubscription(request): Promise\<null | void | SubscriptionPurchase | SubscriptionPurchase[]>

Request a purchase for product. This will be received in PurchaseUpdatedListener. Request a purchase for a subscription.

The response will be received through the PurchaseUpdatedListener.

note

andDangerouslyFinishTransactionAutomatically defaults to false. We recommend always keeping at false, and verifying the transaction receipts on the server-side.

Signature

requestSubscription(
The product's sku/ID
sku,

* You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user.
* @default false

andDangerouslyFinishTransactionAutomaticallyIOS = false,

purchaseToken that the user is upgrading or downgrading from (Android).
purchaseTokenAndroid,

UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
prorationModeAndroid = -1,

/** Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
obfuscatedAccountIdAndroid,

Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
obfuscatedProfileIdAndroid,

The purchaser's user ID
applicationUsername,
): Promise<SubscriptionPurchase>

Usage

import React, {useCallback} from 'react';
import {Button} from 'react-native';
import {
requestSubscription,
Product,
Sku,
getSubscriptions,
} from 'react-native-iap';

const App = () => {
const subscriptions = useCallback(
async () => getSubscriptions(['com.example.subscription']),
[],
);

const handlePurchase = async (sku: Sku) => {
await requestSubscription({sku});
};

return (
<>
{subscriptions.map((subscription) => (
<Button
key={subscription.productId}
title="Buy subscription"
onPress={() => handlePurchase(subscription.productId)}
/>
))}
</>
);
};

Parameters

NameType
requestRequestSubscription

Returns

Promise\<null | void | SubscriptionPurchase | SubscriptionPurchase[]>

Defined in

iap.ts:740


setup

setup(«destructured»?): void

Parameters

NameType
«destructured»Object
› storekitMode?STOREKIT_OPTIONS

Returns

void

Defined in

iap.ts:66


transactionListener

transactionListener(listener): null | EmitterSubscription

Updated transactions for iOS Sk2 Register a callback that gets called when the store has any updates to transactions related to purchases that have not yet been finished, consumed or acknowledged. Returns a React Native EmitterSubscription on which you can call .remove() to stop receiving updates. Register you listener as soon as possible and react to updates at all times.

*Warning** This is only available for iOS 15 and higher and Storekit 2 is activated

Signature

purchaseUpdatedListener((transactionOrError: TransactionOrError) => {});

Usage

import React, {useEffect} from 'react';
import {View} from 'react-native';
import {purchaseUpdatedListener} from 'react-native-iap';

const App = () => {
useEffect(() => {
const subscription = purchaseUpdatedListener((transactionOrError: TransactionOrError) => {
if(transactionOrError.transaction){
console.log("There's an update to a transaction", transactionOrError.transaction);
}else{
console.log("There's been an error with a received transaction")
}
});

return () => {
subscription.remove();
};
}, []);

return <View />;
};

Parameters

NameType
listener(event: TransactionEvent) => void

Returns

null | EmitterSubscription

Platform

iOS (Sk2)

Defined in

eventEmitter.ts:201


useIAP

useIAP(options?): IAP_STATUS

Parameters

NameType
options?UseIAPOptions

Returns

IAP_STATUS

Defined in

hooks/useIAP.ts:65


useIAPContext

useIAPContext(): IAPContextType

Returns

IAPContextType

Defined in

hooks/withIAPContext.tsx:45


withIAPContext

withIAPContext\<T>(Component): (props: T) => Element

Type parameters

Name
T

Parameters

NameType
ComponentComponentType\<T>

Returns

fn

▸ (props): Element

Parameters
NameType
propsT
Returns

Element

Defined in

hooks/withIAPContext.tsx:55