diff --git a/IapExample/src/App.tsx b/IapExample/src/App.tsx index e5702937c..d5ee2920c 100644 --- a/IapExample/src/App.tsx +++ b/IapExample/src/App.tsx @@ -1,9 +1,7 @@ import React from 'react'; -import {storeKit2} from 'react-native-iap'; import {NavigationContainer} from '@react-navigation/native'; import {StackNavigator} from './navigators'; -storeKit2(); export const App = () => ( diff --git a/IapExample/src/components/State.tsx b/IapExample/src/components/State.tsx index 9fc0385d2..891109f67 100644 --- a/IapExample/src/components/State.tsx +++ b/IapExample/src/components/State.tsx @@ -7,11 +7,17 @@ import {Box} from './Box'; interface StateProps { connected: boolean; + storekit2?: boolean; } -export const State = ({connected}: StateProps) => ( - - State - {connected ? 'connected' : 'not connected'} - -); +export const State = ({connected, storekit2}: StateProps) => { + const stateText = + (connected ? 'connected' : 'not connected') + + (storekit2 ? ' | Storekit 2' : ''); + return ( + + State + {stateText} + + ); +}; diff --git a/IapExample/src/screens/Products.tsx b/IapExample/src/screens/Products.tsx index 69f4ade55..3b236e5e3 100644 --- a/IapExample/src/screens/Products.tsx +++ b/IapExample/src/screens/Products.tsx @@ -77,7 +77,7 @@ export const Products = () => { return ( - + {initConnectionError && ( diff --git a/IapExample/src/screens/Subscriptions.tsx b/IapExample/src/screens/Subscriptions.tsx index 840099553..b95843b18 100644 --- a/IapExample/src/screens/Subscriptions.tsx +++ b/IapExample/src/screens/Subscriptions.tsx @@ -1,6 +1,11 @@ import React, {useEffect, useState} from 'react'; import {Platform, ScrollView, StyleSheet, Text, View} from 'react-native'; -import {PurchaseError, requestSubscription, useIAP} from 'react-native-iap'; +import { + isIosStorekit2, + PurchaseError, + requestSubscription, + useIAP, +} from 'react-native-iap'; import {Box, Button, Heading, Row, State} from '../components'; import {constants, contentContainerStyle, errorLog} from '../utils'; @@ -74,7 +79,7 @@ export const Subscriptions = () => { return ( - + diff --git a/src/iap.ts b/src/iap.ts index f0c6d361d..4561b081a 100644 --- a/src/iap.ts +++ b/src/iap.ts @@ -35,14 +35,10 @@ export const getInstallSourceAndroid = (): InstallSourceAndroid => { let androidNativeModule = RNIapModule; -let iosNativeModule = RNIapIos; +let iosNativeModule = RNIapIosSk2; export const isIosStorekit2 = () => iosNativeModule === RNIapIosSk2; -export const storeKit2 = () => { - iosNativeModule = RNIapIosSk2; -}; - export const setAndroidNativeModule = ( nativeModule: typeof RNIapModule, ): void => { @@ -82,7 +78,11 @@ const checkNativeIOSAvailable = (): void => { export const getIosModule = (): typeof RNIapIos => { checkNativeIOSAvailable(); - return iosNativeModule ? iosNativeModule : RNIapIos ? RNIapIos : RNIapIosSk2; + return iosNativeModule + ? iosNativeModule + : RNIapIosSk2 + ? RNIapIosSk2 + : RNIapIos; }; export const getNativeModule = (): @@ -452,6 +452,23 @@ export const acknowledgePurchaseAndroid = ({ return getAndroidModule().acknowledgePurchase(token, developerPayload); }; +/** + * Deep link to subscriptions screen on Android. No-op on iOS. + * @param {string} sku The product's SKU (on Android) + * @returns {Promise} + */ +export const deepLinkToSubscriptionsAndroid = async ({ + sku, +}: { + sku: Sku; +}): Promise => { + checkNativeAndroidAvailable(); + + return Linking.openURL( + `https://play.google.com/store/account/subscriptions?package=${await RNIapModule.getPackageName()}&sku=${sku}`, + ); +}; + /** * Should Add Store Payment (iOS only) * Indicates the the App Store purchase should continue from the app instead of the App Store. @@ -551,23 +568,6 @@ export const validateReceiptIos = async ({ return await enhancedFetch(url); }; -/** - * Deep link to subscriptions screen on Android. No-op on iOS. - * @param {string} sku The product's SKU (on Android) - * @returns {Promise} - */ -export const deepLinkToSubscriptionsAndroid = async ({ - sku, -}: { - sku: Sku; -}): Promise => { - checkNativeAndroidAvailable(); - - return Linking.openURL( - `https://play.google.com/store/account/subscriptions?package=${await RNIapModule.getPackageName()}&sku=${sku}`, - ); -}; - /** * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including * your access token in the binary you ship to users is potentially dangerous.