dooboolab-community / react-native-iap

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

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

Open mjfre opened 1 year ago

mjfre commented 1 year ago

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:

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 :(

rodrigocoliveira commented 1 year ago

I am also facing the same issue =/

umerdogar commented 1 year ago

Facing same issue..Is there a fix yet?

Relax594 commented 1 year ago

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.

andresesfm commented 1 year ago

Check currentPurchaseError

mjfre commented 1 year ago

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 commented 1 year ago

Anyone have any ideas? I'm getting desperate.

claudiaTonak commented 1 year ago

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

mjfre commented 1 year ago

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!

Prathameshlabde commented 1 year ago

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

robertcreaner commented 6 months ago

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

Mihai-github commented 1 month ago

Do we know what's the solution for this?

For me trying to downgrade is not working, the purchaseErrorListener fires with this error:

{
    "responseCode": "0",
    "code": "E_UNKNOWN",
    "debugMessage": "An unknown error occurred",
    "message": "An unknown error occurred",
    "productId": "_______"
}
SabahatRathore commented 1 month ago

{"error": [Error: Purchased failed for sku:Feast_179: Unable to Complete Request], "success": false} i have this error