Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSubscriptions returns an empty array on iOS TestFlight build #2747

Open
G2Patrik opened this issue May 23, 2024 · 4 comments
Open

getSubscriptions returns an empty array on iOS TestFlight build #2747

G2Patrik opened this issue May 23, 2024 · 4 comments

Comments

@G2Patrik
Copy link

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.

@bermann
Copy link

bermann commented May 23, 2024

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

@samcorcos
Copy link

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
Copy link
Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants