Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,10 @@ describe('Public API (src/index.ts)', () => {
.mockResolvedValueOnce([nitro('s1')]);
const res = await IAP.getAvailablePurchases();
expect(mockIap.getAvailablePurchases).toHaveBeenNthCalledWith(1, {
android: {type: 'inapp'},
android: {type: 'inapp', includeSuspended: false},
});
expect(mockIap.getAvailablePurchases).toHaveBeenNthCalledWith(2, {
android: {type: 'subs'},
android: {type: 'subs', includeSuspended: false},
});
expect(res.map((p: any) => p.productId).sort()).toEqual(['p1', 's1']);
});
Expand Down
38 changes: 22 additions & 16 deletions src/hooks/useIAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import type {
VerifyPurchaseResult,
VerifyPurchaseWithProviderProps,
VerifyPurchaseWithProviderResult,
PurchaseOptions,
} from '../types';
import type {
ActiveSubscription,
Expand All @@ -63,7 +64,7 @@ type UseIap = {
promotedProductIOS?: Product;
activeSubscriptions: ActiveSubscription[];
finishTransaction: (args: MutationFinishTransactionArgs) => Promise<void>;
getAvailablePurchases: (skus?: string[]) => Promise<void>;
getAvailablePurchases: (options?: PurchaseOptions) => Promise<void>;
fetchProducts: (params: {
Comment thread
hyochan marked this conversation as resolved.
skus: string[];
type?: ProductQueryType | null;
Expand All @@ -83,7 +84,7 @@ type UseIap = {
verifyPurchaseWithProvider: (
options: VerifyPurchaseWithProviderProps,
) => Promise<VerifyPurchaseWithProviderResult>;
restorePurchases: () => Promise<void>;
restorePurchases: (options?: PurchaseOptions) => Promise<void>;
getPromotedProductIOS: () => Promise<Product | null>;
requestPurchaseOnPromotedProductIOS: () => Promise<boolean>;
getActiveSubscriptions: (
Expand Down Expand Up @@ -271,11 +272,13 @@ export function useIAP(options?: UseIapOptions): UseIap {
);

const getAvailablePurchasesInternal = useCallback(
async (_skus?: string[]): Promise<void> => {
async (options?: PurchaseOptions): Promise<void> => {
try {
const result = await getAvailablePurchases({
alsoPublishToEventListenerIOS: false,
onlyIncludeActiveItemsIOS: true,
alsoPublishToEventListenerIOS:
options?.alsoPublishToEventListenerIOS ?? false,
onlyIncludeActiveItemsIOS: options?.onlyIncludeActiveItemsIOS ?? true,
includeSuspendedAndroid: options?.includeSuspendedAndroid ?? false,
});
Comment thread
hyochan marked this conversation as resolved.
setAvailablePurchases(result);
} catch (error) {
Expand Down Expand Up @@ -333,18 +336,21 @@ export function useIAP(options?: UseIapOptions): UseIap {
[],
);

const restorePurchases = useCallback(async (): Promise<void> => {
try {
if (Platform.OS === 'ios') {
await syncIOS();
}
const restorePurchases = useCallback(
async (options?: PurchaseOptions): Promise<void> => {
try {
if (Platform.OS === 'ios') {
await syncIOS();
}

await getAvailablePurchasesInternal();
} catch (error) {
RnIapConsole.warn('Failed to restore purchases:', error);
invokeOnError(error);
}
}, [getAvailablePurchasesInternal, invokeOnError]);
await getAvailablePurchasesInternal(options);
} catch (error) {
RnIapConsole.warn('Failed to restore purchases:', error);
invokeOnError(error);
}
},
[getAvailablePurchasesInternal, invokeOnError],
);

const validateReceipt = useCallback(
async (options: VerifyPurchaseProps): Promise<VerifyPurchaseResult> =>
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,14 @@ export const getAvailablePurchases: QueryField<
return validPurchases.map(convertNitroPurchaseToPurchase);
} else if (Platform.OS === 'android') {
// For Android, we need to call twice for inapp and subs
const includeSuspended = Boolean(
options?.includeSuspendedAndroid ?? false,
);
const inappNitroPurchases = await IAP.instance.getAvailablePurchases({
android: {type: 'inapp'},
android: {type: 'inapp', includeSuspended},
});
const subsNitroPurchases = await IAP.instance.getAvailablePurchases({
android: {type: 'subs'},
android: {type: 'subs', includeSuspended},
});

// Validate and convert both sets of purchases
Expand Down
Loading