react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

requestPurchase({sku: 'validSku'}) not completing or failing

Open mjfre opened this issue 1 year ago • 12 comments

Discussed in https://github.com/dooboolab/react-native-iap/discussions/2253

Originally posted by mjfre February 18, 2023 Description

I switched to using react-native-iap hooks, but when I call requestPurchase({sku: 'validSku'}) the request does not proceed to either the 'then' or the 'catch', and the apple confirm purchase dialog does not appear. I have followed the hooks walkthrough, and went through every piece of documentation/issue/discussion I can find, to no avail. I provided the withIapContext at the app-level. Within the same component where I am experiencing the issue, I am successfully calling getProducts(...) and getSubscriptions(...) in a useEffect() that executes when the component mounts. I have also confirmed that connected === true immediately before requestPurchase, and that the value provided as a parameter to requestPurchase is as expected. I previously had all in-app purchases and subscriptions functioning completely, including backend receipt validation, so it doesn't seems as though there was in issue setting up the products on the apple side. In fact, when I provide an invalid sku to requestPurchase(), I receive an error, so it seems it is doing something.

Expected Behavior

When requestPurchase({sku: 'validSku'}) is called, the call resolves and the Apple purchase dialog appears.

Code Snippets

From App.js

import {withIAPContext} from "react-native-iap";  

...

export default withIAPContext(App);

From PurchaseView.js

import {useIAP} from "react-native-iap";

...

//START OF PART THAT WORKS FINE

const {
        connected,
        products,
        subscriptions,
        getProducts,
        getSubscriptions,
        finishTransaction,
        currentPurchase,
        currentPurchaseError,
        requestPurchase,
        requestPurchaseWithQuantityIOS,
        clearTransactionIOS
    } = useIAP();

    useEffect(() => {
        getSubscriptions({skus: premiumSubscriptionItemNames})
            .then((result) => {
                ...
            })
            .catch(() => {
               ...
            });
        getProducts({skus: consumableItemNames})
            .then((result) => {
              ...
            })
            .catch(() => {
                ...
            });

    }, []);

//END OF PART THAT WORKS FINE

...

const handlePurchase = async (sku) => {

        alert(sku + ' ' + connected);                  //output: '700credits' true

        await requestPurchase({sku: sku})
            .then((result) => {
                alert('transaction requested')       //this never runs
            })
            .catch((response) => {
                alert('request purchase failed')     //this also never runs
            });
};

...

<Pressable
        style={styles.PurchaseOption}
        disabled={consumable700CreditLocalizedPrice === null}
        onPress={() => {
        handlePurchase('700credits');
}}>

Environment:

  • react-native-iap: 12.0.0 (also tried 11.0.7 as one person had luck downgrading)
  • react-native: 0.71.2
  • Platforms (iOS, Android, emulator, simulator, device):
    - iPhone 14 (iOS version 16.0.3) - Xcode simulator (I know I shouldn't use this for testing, but it used to at least display the apple purchase dialog)

To Reproduce Steps to reproduce the behavior:

  1. Follow the directions in the hooks walkthrough
  2. Call requestPurchase({sku: 'validSku'})

Additional Context

Any help would be greatly appreciated! This issue is currently blocking the release of my App :(

mjfre avatar Feb 19 '23 00:02 mjfre

I am also facing the same issue =/

rodrigocoliveira avatar Feb 20 '23 03:02 rodrigocoliveira

Facing same issue..Is there a fix yet?

umerdogar avatar Feb 23 '23 06:02 umerdogar

Same issue here, only on iOS since updating to StoreKit 2.

For me it performs the purchase (Subscription) with a expired originalTransactionId which is stated inactive by Apples Verification Server without even providing the purchase popup dialog.

Relax594 avatar Feb 24 '23 08:02 Relax594

Check currentPurchaseError

andresesfm avatar Feb 24 '23 17:02 andresesfm

I'm nearly certain I haven't touched any of the purchase code since the last update. I've had a useEffect that follows currentPurchaseError, but today I am actually receiving an error in the simulator:

{"productId":"700credits","messages":"An unknown error occurred","debugMessage":"An unknown error occurred","responseCode":"0","code":"E_UNKNOWN"}

However deployed to a device, I am still receiving the same behavior as previously: requestPurchase just hangs with no visible side effects, and doesn't hit the "then", "catch" or even the useEffect that monitors currentPurchaseError (I have alerts that never appear in each of them).

mjfre avatar Feb 25 '23 21:02 mjfre

Anyone have any ideas? I'm getting desperate.

mjfre avatar Mar 02 '23 23:03 mjfre

await IAP.requestPurchase( Platform.select({ ios: { sku }, android: { skus: [sku] }, })

claudiaTonak avatar Mar 09 '23 10:03 claudiaTonak

Thanks for something to try! It didn't change the results per se, but something very strange happened. The code that I had previously deployed, which was hanging indefinitely, is displaying the apple purchase dialog today.....

So I guess the issue is solved? I'd be interested to hear if the others that were experiencing this issue also had it start working.

I'm quite nervous that the problem seemed to fix itself, and I'm hoping that it stays working. I'm not going to close the issue myself, because this still feels like something wrong with react-native-iap. Perhaps it was swallowing an exception thrown by apple which has for some reason self-resolved? I can promise that I haven't touched my purchase code, made any changes on Apple's side, or made any app-wide (e.g. version) changes since this issue first presented, as I've been focusing solely on totally unrelated parts of the app.

I'll check back for follow-up questions, and update this if it breaks again, but hopefully it doesn't come to that!

mjfre avatar Mar 09 '23 22:03 mjfre

https://github.com/dooboolab-community/react-native-iap/issues/2455 Can anyone please suggest on this issue Please ?

Prathameshlabde avatar Jun 06 '23 10:06 Prathameshlabde

@mjfre I'm currently receiving the exact same issue you described. Did you ever encounter this again or did it fix itself indefintely?

robertcreaner avatar Jan 06 '24 20:01 robertcreaner