hyochan / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.hyo.dev
MIT License
2.87k stars 648 forks source link

getSubscriptions returns an empty array on iOS TestFlight build #2747

Open G2Patrik opened 6 months ago

G2Patrik commented 6 months ago

Environment:

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.

bermann commented 6 months ago

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

samcorcos commented 6 months ago

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.
G2Patrik commented 6 months ago

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.

ericfreitas88 commented 6 months ago

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 } })`

pablo4lvarez commented 4 months ago

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

ericfreitas88 commented 4 months ago

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.