react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

getSubscriptions returns an empty array on iOS TestFlight build

Open G2Patrik opened this issue 1 year ago • 6 comments

Environment:

  • react-native-iap: 12.12.2
  • react-native: 0.72.12
  • Platforms (physical & simulator): iPhone 11 - OS version 17.4 /// iOS Simulator iPhone 15 Pro Max - OS version 17.4

Description Hello, I am trying to test the getSubscriptions() function in my TestFlight build for iOS. In my local setup I managed to fetch the subscriptions correctly when I created an App.storekit file in Xcode. I am trying to use my TestFlight build using the sandbox environment to test the same thing (fetching subscriptions) but the response is an empty array.

Expected Behavior The code below should return the subscriptions and their details that I setup in the App Store Connect dashboard.

subscriptions = await getSubscriptions({skus: ['example_monthly_subscription', 'example_yearly_subscription']});

The response is an empty array. Am I missing a step to setup the sandbox environment for TestFlight correctly? Once I created the App.storekit file and sync the subscription content from App Store Connect, the response works perfectly fine if I load the app locally.

Any help would be appreciated.

G2Patrik avatar May 23 '24 14:05 G2Patrik

I'm having the same issue, did you find anything helpful?

bermann avatar May 23 '24 19:05 bermann

I ran into something similar. The things I had to do:

  1. I had to create a subscription group in App Store Connect
  2. Create a subscription within the subscription group and fill in all the details
  3. Wait several hours for the subscription to propagate for some reason, then it showed up.

samcorcos avatar May 23 '24 22:05 samcorcos

I managed to make it work. You have to make sure you have your Tax Information and Banking information filled out. Once I agreed to the terms and added banking info everything started working fine.

You can find these agreements in App Store Connect > Business > {Select Own Business}

Make sure you have the Agreements / Bank Accounts / Tax Forms filled out correctly. Hope this helps.

G2Patrik avatar May 24 '24 14:05 G2Patrik

Hey guys. How are you? I have the same problem. My subscription returns empty. I don't know how to solve it. Can someone help me?

Here is my code.

`import React, { useState } from "react"; import { ActivityIndicator, Platform, ScrollView, StyleSheet, Text, View } from "react-native"; import { useFocusEffect } from "@react-navigation/native";

import { connect } from "react-redux";

import { _getPlanosAssinatura } from "../../services/shopService";

import BackgroundApp from "../../components/BackgroundApp/"; import { PlanoAssinatura } from "../../components/PlanosAssinatura"; import CustomButton from "../../components/CustomButton"; import { AppState } from "../../store"; import LinearGradient from "react-native-linear-gradient";

import { PurchaseError, requestSubscription, useIAP, validateReceiptIos, initConnection, endConnection, withIAPContext, getSubscriptions, getProducts, getAvailablePurchases, requestPurchase } from 'react-native-iap'; import { APP_STORE_SECRET } from '@env';

const skus = Platform.select({ ios: ['2301Anual'], android: [''] }) || [];

const ApplePay = (Props: any) => { const { connected, subscriptions, // getSubscriptions, currentPurchase, finishTransaction, purchaseHistory, getPurchaseHistory, requestPurchase } = useIAP();

const [isLoading, setIsLoading] = useState(true); const [loadingFail, setLoadingFail] = useState(false); const [planos, setPlanos] = useState([]);

const getPlanosAssinatura = () => { setLoadingFail(false);

const success = (resp?: any) => {
  setPlanos(resp);
  setIsLoading(false)
}

const error = (e?: any) => {
  console.warn(e);
  setLoadingFail(true);
}

_getPlanosAssinatura(Props.token, success, error);

};

const getProductsAppleStore = async () => { try { await initConnection(); const products = await getSubscriptions({ skus: skus }); console.log('Produtos => ', products);

} catch (err) {
  console.warn(err)

} finally {
  await endConnection;
}

}

useFocusEffect( React.useCallback(() => { getProductsAppleStore(); getPlanosAssinatura(); }, []) );

return ( <BackgroundApp screenTitle={"Matricule-se"} type="View" style={{ paddingTop: 0, }}>

  {
    (isLoading && !loadingFail) && (
      <View style={styles.containerLoading}>
        <ActivityIndicator color="#82689b" size="large" />
      </View>
    )
  }

  {
    loadingFail && (
      <View style={styles.boxLoading}>
        <Text style={styles.labelFail}>Não conseguimos acessar nossos servidores</Text>
        <CustomButton title="Tentar novamente" onPress={getPlanosAssinatura} />
      </View>
    )
  }

  {
    (!isLoading && !loadingFail) && (
      <LinearGradient
        colors={['#262626', '#1A1A1A']}
        angle={360}
        style={{
          paddingHorizontal: 15,
          paddingTop: 30,
          flex: 1
        }}
      >
        <ScrollView showsVerticalScrollIndicator={false} >
          {
            planos.map((item, index) =>
              <PlanoAssinatura key={index} plano={item} />
            )
          }
        </ScrollView>
      </LinearGradient>
    )
  }
</BackgroundApp>

); }

const mapStateToProps = (state: AppState) => { return { token: state.auth.token, tabBarVisible: state.tab.showTabBar, checked_user: state.auth.checked_user, phone_number: state.auth.phone_number, loggedIn: state.auth.loggedIn, isPro: state.profile.isPro, } }

const ApplePayconnect = connect(mapStateToProps)(ApplePay); export default withIAPContext(ApplePayconnect);

const styles = StyleSheet.create({ containerLoading: { flex: 1, justifyContent: "center", alignItems: "center" }, boxLoading: { flex: 1, alignItems: "center", justifyContent: "center", }, labelFail: { marginBottom: 10 } })`

ericfreitas88 avatar May 29 '24 14:05 ericfreitas88

hey @ericfreitas88 , did you solved the problem? i still can't see my subscriptions properly when running the app

pablo4lvarez avatar Jul 09 '24 21:07 pablo4lvarez

ei@ericfreitas88, você resolveu o problema? ainda não consigo ver minhas assinaturas corretamente ao executar o aplicativo

@pablo4lvarez , Is everything ok? I managed to solve it. The problem was with the app store connect, as there were terms pending confirmation.

My tip is, before you actually start coding, you need to ensure that all the bureaucratic part is 100% resolved.

In my case, I needed the app store connect master account to complete the acceptance of all Apple terms and register the bank accounts.

Shortly after this was done, getSubscriptions worked normally.

ericfreitas88 avatar Jul 13 '24 13:07 ericfreitas88

I’m closing all issues reported in versions below 14, as the library now supports the new architecture with NitroModules and has been completely revamped.

Also, getSubscriptions no longer exists. fetchProduct with type subs.

hyochan avatar Sep 30 '25 18:09 hyochan