dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.78k stars 634 forks source link

beginRefundRequest can't find product for sku #2570

Open spidergears opened 10 months ago

spidergears commented 10 months ago

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:

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 commented 10 months ago

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

moYousefAlarand commented 8 months ago

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

quangkhait98 commented 8 months ago

how to solve problems ? 😪

dongminlim commented 7 months ago

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

borra27 commented 6 days ago

This code will work

import { IapIosSk2, getProducts, setup } from "react-native-iap";

setup({ storekitMode: "STOREKIT2_MODE" });
await getProducts({ skus: ["sku"] });
await IapIosSk2.beginRefundRequest("sku");