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

Cannot restore purchase using currentPurchaseError listner #2804

Open
ibraheem88 opened this issue Jul 12, 2024 · 0 comments
Open

Cannot restore purchase using currentPurchaseError listner #2804

ibraheem88 opened this issue Jul 12, 2024 · 0 comments

Comments

@ibraheem88
Copy link

ibraheem88 commented Jul 12, 2024

Please use the Discussion board if you want to get some help. Please use issues to report bugs.

Description

One of the user is not able to restore their subscription. They bought the subscription and were charged by apple but due to some reason (might be internet connection) the receipt did not reach backend and they did not get access. Now when they try to buy that subscription again, apple shows dialog that you can get this subscription when previous expires (Screenshot 1). Upon clicking subscribe for this subscription, they get the message: "All Set Purchase Successful" (Screenshot 2). But after that none of the listeners get activated, purchaseUpdated listner or currentPurchaseError. Although I tried to buy already bought subscription with another production account, it showed me popup in Screenshot 3 & it worked as expected.

Expected Behavior

User should get a popup in Screenshot 3. Instead they get popups in Screenshot 1 & 2 and no listener is activated to handle receipt.

Screenshots

media_20240708_084129_4327895667487383117
(Screenshot 1)
ImportedPhoto_1720433636543
(Screenshot 2)
ImportedPhoto 742301097 693189
Screenshot (3) Note: It is from beta version but I got the same in production on restoring subscription. Just this beta testers line was not there

Environment:

  • react-native-iap: ^12.12.2
  • react-native: 0.72.4
  • Platforms: iOS (Production)

To Reproduce
Steps to reproduce the behavior:

  1. Buy an auto renewable subscription.
  2. Try to buy it again if receipt is not sent to backend somehow & no access is given to user.
  3. Try to buy subscription again.

[Optional] Additional Context

Again this is happening to one user in production out of 2 who bought subscription and could be related to apple than library. But we verified they have the production apple receipt which I am sending from home screen to backend. Also they have subscription active in their apple subscriptions section in settings. But trying to buy it again does not trigger listeners.

`useEffect(() => {
const checkCurrentPurchase = async purchase => {
if (purchase) {
const receipt = purchase.transactionReceipt;

            console.log('RECEIPT: ', receipt);
            if (receipt && token !== '') {
                // Give full app access
                if (lastTransactionRecipe) return
                lastTransactionRecipe = true
                try {
                    const ackResult = await finishTransaction({ purchase: purchase, isConsumable: undefined, developerPayloadAndroid: undefined });
                    try {
                     //Api Call To Backend
                    } catch (e) {
                        setTransLoading(false)
                        console.log('Saving Subscription Success To Backend Error:', e);
                    }
                    console.log('ackResult: ', ackResult);
                } catch (ackErr) {
                    setTransLoading(false)
                    // We would need a backend to validate receipts for purhcases that pended for a while and were then declined. So I'll assume most purchase attempts go through successfully (OK ackResult) & take the hit for the ones that don't (user will still have full app access).
                    console.log('ackError: ', ackErr);
                }
            }
        }
    };
    checkCurrentPurchase(currentPurchase);
}, [currentPurchase, finishTransaction]);
// If user reinstalls app, then they can press purchase btn (SettingsScreen) to get full app without paying again.
useEffect(() => {
    const checkPurchaseError = async () => {
        console.log(currentPurchaseError, 'current purchase error')
        Alert.alert("", JSON.stringify(currentPurchaseError))
        if (currentPurchaseError) {
            Alert.alert("", JSON.stringify(token))
            if (currentPurchaseError.code === 'E_ALREADY_OWNED') {
                if (token !== '') {
                    //setTransLoading(true)
                    if (lastTransactionRecipe) return
                    lastTransactionRecipe = true
                    // Give full app access
                    try {
                       //Api Call To Backend
                    } catch (e) {
                        setTransLoading(false);
                        console.log('Saving Subscription Success To Backend Error:', e);
                    }
                }
            }
        }
    };
    checkPurchaseError();
}, [currentPurchaseError]);`
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