Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React Native IAP Auto Renewal Subscription check Expiration

$
0
0

I am trying to restore and detect the end of auto renewal subscriptions on iOS using https://www.npmjs.com/package/react-native-iap/v/4.0.8By calling getAvailablePurchases() I get a different number of purchases everytime I invoke this function (e.g 7, next time 23, then 4..). This makes no sense to me. I know the subscription renews any 5 minutes for monthly subscription.My idea is to get the latest purchase and just check the expired dates in the receipt from this one. (at the moment I am parsing over all of them, this cannot be best practice). Another thing is that I detect several active purchases with different transactionReceipts eventhough there is just one active.

RNIap.getAvailablePurchases().then((purchases) => {            if(purchases != undefined && purchases.length > 0){                alert(purchases.length +' purchases');                purchases.forEach((purchase) => {                    const receiptBody = {'receipt-data': purchase.transactionReceipt,'password': appSubscriptionId                    };                    RNIap.validateReceiptIos(receiptBody, true).then((result) => { // false for production                        let from, to, lastRenewal = '';                        if(result.status == 0){ // 0 means receipt is correct..                            result.latest_receipt_info.forEach((info) => {                                 if(this.dateIsInFuture(info.expires_date)){                                    to = moment.utc(info.expires_date, "YYYY-MM-DD HH:mm:ss").toString();                                    from = moment.utc(info.original_purchase_date, "YYYY-MM-DD HH:mm:ss").toString();                                    lastRenewal = moment.utc(info.purchase_date, "YYYY-MM-DD HH:mm:ss").toString();                                    this.setState({ premium: true, from: from, to: to, lastRenewal: lastRenewal});                                }else{                                    alert('nicht aktiv');                                }                            });                        }                    });                 });             }else{                alert('No purchases found');            }        });

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>