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

Subscription Error - "The item you were attempting to purchase could not be found" #2856

Open
Invariant-tech-green opened this issue Sep 25, 2024 · 0 comments

Comments

@Invariant-tech-green
Copy link

Description

I am encountering an issue when attempting to request a subscription using the react-native-iap library in my Expo React Native app. The subscription request fails with the error message: "The item you were attempting to purchase could not be found."

Steps to Reproduce

  1. Initialize the in-app purchase connection and fetch the subscription details.
  2. Attempt to request a subscription using the fetched product details and subscription offers.

Code Snippet

import * as RNIap from 'react-native-iap';
import { useEffect, useState } from 'react';
import { Button, View, Text } from 'react-native';

const App = () => {
  const [products, setProducts] = useState([]);

  const initIAP = async () => {
    try {
      const result = await RNIap.initConnection();
      console.log('IAP connection result:', result);
      await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
      const request = { skus: ['dorm_deal_1'] };
      const fetchedProducts = await RNIap.getSubscriptions(request);
      setProducts(fetchedProducts);
      console.log('Fetched products:', fetchedProducts);
    } catch (err) {
      console.log('IAP initialization error:', err, err.message);
    }
  };

  useEffect(() => {
    initIAP();
    return () => {
      RNIap.endConnection();
    };
  }, [useIsFocused()]);

  const subscribe = async () => {
    try {
      if (products.length > 0) {
        const product = products.find(p => p.productId === 'dorm_deal_1');
        if (product && product.subscriptionOfferDetails) {
          const subscriptionOffers = product.subscriptionOfferDetails.map(offer => ({
            sku: product.productId,
            offerToken: offer.offerToken,
          }));

          console.log('Requesting subscription for product ID: dorm_deal_1 with offers:', subscriptionOffers);
          const request = {
            sku: 'dorm_deal_1',
            subscriptionOffers,
          };
          const result = await RNIap.requestSubscription(request);
          console.log(result, "result");
          if (result && typeof result === 'object') {
            console.log('Subscription result:', result);
          } else {
            console.warn('Invalid subscription result:', result);
          }
        } else {
          console.warn('No subscription offers available for product ID: dorm_deal_1');
        }
      } else {
        console.warn('No products available for subscription');
      }
    } catch (err) {
      console.warn('Subscription error:', err, JSON.stringify(err.message));
    }
  };

  return (
    <View>
      <Button title="Subscribe" onPress={subscribe} />
      {products.length > 0 && <Text>Product is valid: {JSON.stringify(products)}</Text>}
    </View>
  );
};

export default App;

Logs

LOG  Requesting subscription for product ID: dorm_deal_1 with offers: [{"offerToken": "AarRn8pLX3OymDFBdywYOYrVglI4B3/kk4F0yjO1ZTE182iAPFwJxemReMaihMBw6a/et8df5bdJeL7gl2H28ba5ig==", "sku": "dorm_deal_1"}]
WARN  Subscription error: [Error: The item you were attempting to purchase could not be found] "The item you were attempting to purchase could not be found"

Additional Context

  • The product ID dorm_deal_1 is correctly set up in the Google Play Console and is active.
  • The subscription offers are fetched and logged correctly before making the subscription request.
  • The error occurs when calling requestSubscription with the fetched subscription offers.

Expected Behavior

The subscription request should succeed, and the user should be able to subscribe to the product dorm_deal_1.

Actual Behavior

The subscription request fails with the error message: "The item you were attempting to purchase could not be found."

Environment

  • react-native-iap version: ^12.15.4
  • React Native version: 0.74.5
  • Expo version: ~51.0.34
  • Platform: Android

Steps Taken

  • Verified the product ID and subscription offers in the Google Play Console.
  • Ensured the product is active and available for purchase.
  • Used test accounts for testing the subscription.

Any help or guidance on resolving this issue would be greatly appreciated. Thank you!

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

1 participant