RevenueCat / react-native-purchases

React Native in-app purchases and subscriptions made easy. Support for iOS and Android.
https://www.revenuecat.com
MIT License
735 stars 81 forks source link

ProductAlreadyPurchasedError whereas is not the case. (Payment pending cards Android) #139

Open AlexisChup opened 4 years ago

AlexisChup commented 4 years ago

I'm using RevenueCat on android now, in order to purchase 'non-consumable product'. I've configured my account following the doc (great doc !). However I'm facing an issue.

First of all, you know that android allow to purchase product with 4 different cards in tester account. I've no problem with card always denied, card always accepted and card accepted after a delays. But my problem is with card cancel after few minutes.

Here how I proceed :

1.

Add listener

// function for purchase Listener
this.purchaserInfoUpdateListener = (info) => {
    checkIfPro(info, this._becomePremium);
};

// add this function to Purchases's Listener
Purchases.addPurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);

//function call when listener is called 
function checkIfPro(purchaserInfo, callbackFunction) {
    // Check when function is called
    console.log('checkIfPro is called ! ');
    if (typeof purchaserInfo.entitlements.active.premium !== 'undefined') {
        // Unlock premium content :
        console.log('#Unlock great content#');

        // Active premium
        callbackFunction();
    } else {
        console.log('Not premium');
    }
}

2.

Purchase a product (with card cancelled after few minutes)

const { purchaserInfo, productIdentifier } = await Purchases.purchaseProduct(
    itemToPurchase,
    null,
    Purchases.PURCHASE_TYPE.INAPP
);

3.

See the logs

e.userInfo.readableErrorCode = 'PaymentPendingError'

We can see 'PaymentPendingError', ok it's normal, the transaction isn't finished yet.

4.

Wait few minutes

5.

Because nothing happened (Listener isn't call, or anything show that transaction is cancelled), I try to purchase the product again. However the logs say :

ProductAlreadyPurchasedError

whereas when I call

await Purchases.getPurchaserInfo()

the entitlement is not active.

My issues :

aboedo commented 4 years ago

Hi! Thanks for reporting. This is a very valid concern, and we're aware that we need to improve our treatment of the Pending purchases on Android. We've actually been discussing it quite a bit recently - see https://github.com/RevenueCat/purchases-android/issues/160 and https://github.com/RevenueCat/purchases-flutter/issues/60 for details. I'm moving this to backlog, but I unfortunately don't have an ETA for it.