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

beginRefundRequest can't find product for sku #2570

Open
spidergears opened this issue Oct 4, 2023 · 4 comments
Open

beginRefundRequest can't find product for sku #2570

spidergears opened this issue Oct 4, 2023 · 4 comments

Comments

@spidergears
Copy link

Description

Calling

IapIosSk2.beginRefundRequest(sku)
          .then(resp => console.log({resp}))
          .catch(e => console.log({e}));

it fails with [Error: Can't find product for sku <sku_here>]

I am using useIAP for the purchase process and have already called the getProducts call.

It looks like before I can make the beginRefundRequest call, I probably should call getItems which would set the products array internally but this is not exposed by IapIosSk2.

I may be completely wrong and may have misunderstood the implementation.

Expected Behavior

it should show the refund dialog screen

Environment:

  • react-native-iap: 12.10.8
  • react-native: 0.71.0
  • Platforms (iOS, Android, emulator, simulator, device): iOS (16.6, physical device)

To Reproduce

import { useIAP, IapIosSk2 } from "react-native-iap";
....
const {
    connected,
    currentPurchase,
    currentPurchaseError,
    requestPurchase,
    finishTransaction,
    getProducts,
  } = useIAP();


useEffect(() => {
    // ... listen to currentPurchaseError, to check if any error happened
    if (!currentPurchaseError) {
      return;
    }

    switch (currentPurchaseError?.code) {
      case "E_USER_CANCELLED":
        toast.error("Purchase request cancelled.");
....
    }
  }, [currentPurchaseError]);

  useEffect(() => {
    // ... listen to currentPurchase, to check if the purchase went through
    if (!currentPurchase) {
      return;
    }

    const receipt = currentPurchase.transactionReceipt;
    if (receipt) {
      validatePurchase(... , { receipt })
        .then(async response => {
          await finishTransaction({
            purchase: currentPurchase,
            isConsumable: true,
          });
          toast.success("Purchase completed.", "success");
        })
        .catch(error => {
          ...
        })
        .finally(_ => {
          ...
        });
    }
  }, [currentPurchase, finishTransaction]);

  useEffect(() => {
    const getIAPProducts = async () => {
      if (connected && sku) {
        try {
          await getProducts({ skus: [sku] });
        } catch (error) {
          ...
        } finally {
          // Do nothing
        }
      }
    };
    getIAPProducts();
  }, [connected, getProducts, sku]);

..

const requestRefund= () => {
   IapIosSk2.beginRefundRequest(sku)
          .then(resp => console.log({resp}))
          .catch(e => console.log({e}));
}

@ramakula
Copy link

ramakula commented Oct 9, 2023

We are also facing the same issue, keep getting the error: 'can't find product for sku...'

@moYousefAlarand
Copy link

the same issue, 'can't find product for sku...'

@quangkhait98
Copy link

quangkhait98 commented Dec 21, 2023

how to solve problems ? 😪

@dongminlim
Copy link

guys.. you need to understand storekit1, or 2.
and Please set
setup({storekitMode: 'STOREKIT2_MODE'});
beginRefundRequest only available above iOS 15

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

5 participants