From c55512e7108adbd320450d486de7e0daf563360a Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 8 Nov 2022 17:39:45 +0500 Subject: [PATCH 1/2] upgraded iap --- ios/Podfile.lock | 6 +-- package.json | 2 +- src/containers/inAppPurchaseContainer.tsx | 48 +++++++++++++---------- yarn.lock | 15 ++----- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index ccc75725c..cde52a830 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -530,7 +530,7 @@ PODS: - RNFBApp - RNGestureHandler (2.8.0): - React-Core - - RNIap (7.5.6): + - RNIap (12.4.2): - React-Core - RNImageCropPicker (0.35.3): - React-Core @@ -958,7 +958,7 @@ SPEC CHECKSUMS: RNFBDynamicLinks: 538840f6e3f58511f857d15df1bc25ed655dc283 RNFBMessaging: 40dac204b4197a2661dec5be964780c6ec39bf65 RNGestureHandler: 62232ba8f562f7dea5ba1b3383494eb5bf97a4d3 - RNIap: d248609d1b8937e63bd904e865c318e9b1457eff + RNIap: e17233fe11083a71e0420682b0b09d497861faa1 RNImageCropPicker: 08ba3a2e2f4f8833d606f01906c371e382c4dea9 RNNotifee: dcb2593127f40945c4ee5fc09f61d71bbd00b9cf RNOS: 6f2f9a70895bbbfbdad7196abd952e7b01d45027 @@ -974,6 +974,6 @@ SPEC CHECKSUMS: toolbar-android: 2a73856e98b750d7e71ce4644d3f41cc98211719 Yoga: 2ed968a4f060a92834227c036279f2736de0fce3 -PODFILE CHECKSUM: 349fd1005f5ffc6e775051d22702d58ab1632517 +PODFILE CHECKSUM: 36d29e2c20cdf9c60df8598f3eb180df6812c820 COCOAPODS: 1.11.3 diff --git a/package.json b/package.json index 59a56aa49..325da28f6 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "react-native-fingerprint-scanner": "hieuvp/react-native-fingerprint-scanner", "react-native-gesture-handler": "^2.8.0", "react-native-highlight-words": "^1.0.1", - "react-native-iap": "^7.5.6", + "react-native-iap": "^12.4.2", "react-native-image-crop-picker": "^0.35.2", "react-native-image-zoom-viewer": "^2.2.27", "react-native-iphone-x-helper": "Norcy/react-native-iphone-x-helper", diff --git a/src/containers/inAppPurchaseContainer.tsx b/src/containers/inAppPurchaseContainer.tsx index 30370389b..cd3b11cb4 100644 --- a/src/containers/inAppPurchaseContainer.tsx +++ b/src/containers/inAppPurchaseContainer.tsx @@ -1,8 +1,8 @@ /* eslint-disable no-unused-vars */ import React, { Component } from 'react'; import { connect } from 'react-redux'; -import { Platform, Alert } from 'react-native'; -import RNIap, { purchaseErrorListener, purchaseUpdatedListener } from 'react-native-iap'; +import { Platform, Alert, EmitterSubscription } from 'react-native'; +import * as IAP from 'react-native-iap'; import { injectIntl } from 'react-intl'; import get from 'lodash/get'; @@ -17,9 +17,8 @@ import { showActionModal } from '../redux/actions/uiAction'; import { UserAvatar } from '../components'; class InAppPurchaseContainer extends Component { - purchaseUpdateSubscription = null; - - purchaseErrorSubscription = null; + purchaseUpdateSubscription: EmitterSubscription | null = null; + purchaseErrorSubscription: EmitterSubscription | null = null; constructor(props) { super(props); @@ -45,15 +44,15 @@ class InAppPurchaseContainer extends Component { this.purchaseErrorSubscription.remove(); this.purchaseErrorSubscription = null; } - RNIap.endConnection(); + IAP.endConnection(); } _initContainer = async () => { const { intl } = this.props; try { - await RNIap.initConnection(); + await IAP.initConnection(); if (Platform.OS === 'android') { - await RNIap.flushFailedPurchasesCachedAsPendingAndroid(); + await IAP.flushFailedPurchasesCachedAsPendingAndroid() } await this._consumeAvailablePurchases(); @@ -78,11 +77,14 @@ class InAppPurchaseContainer extends Component { _consumeAvailablePurchases = async () => { try { // get available purchase - const purchases = await RNIap.getAvailablePurchases(); + const purchases = await IAP.getAvailablePurchases(); // check consumeable status for (let i = 0; i < purchases.length; i++) { // consume item using finishTransactionx - await RNIap.finishTransaction(purchases[i], true); + await IAP.finishTransaction({ + purchase: purchases[i], + isConsumable: true + }); } } catch (err) { bugsnagInstance.notify(err); @@ -100,7 +102,7 @@ class InAppPurchaseContainer extends Component { username, } = this.props; - this.purchaseUpdateSubscription = purchaseUpdatedListener((purchase) => { + this.purchaseUpdateSubscription = IAP.purchaseUpdatedListener((purchase) => { const receipt = get(purchase, 'transactionReceipt'); const token = get(purchase, 'purchaseToken'); @@ -115,7 +117,10 @@ class InAppPurchaseContainer extends Component { purchaseOrder(data) .then(async () => { try { - const ackResult = await RNIap.finishTransaction(purchase, true); + const ackResult = await IAP.finishTransaction({ + purchase, + isConsumable: true + }); console.info('ackResult', ackResult); } catch (ackErr) { console.warn('ackErr', ackErr); @@ -135,7 +140,7 @@ class InAppPurchaseContainer extends Component { } }); - this.purchaseErrorSubscription = purchaseErrorListener((error) => { + this.purchaseErrorSubscription = IAP.purchaseErrorListener((error) => { bugsnagInstance.notify(error); if (get(error, 'responseCode') === '3' && Platform.OS === 'android') { Alert.alert( @@ -169,14 +174,14 @@ class InAppPurchaseContainer extends Component { }; _getItems = async () => { - const { skus } = this.props; + const { skus, intl } = this.props; try { - const products = await RNIap.getProducts(skus); + const products = await IAP.getProducts({ skus }); console.log(products); products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price)).reverse(); this.setState({ productList: products }); - } catch (err) { - bugsnagInstance.notify(err); + } catch (error) { + bugsnagInstance.notify(error); Alert.alert( intl.formatMessage({ id: 'alert.connection_issues', @@ -192,10 +197,11 @@ class InAppPurchaseContainer extends Component { const { navigation } = this.props; if (sku !== 'freePoints') { - await this.setState({ isProcessing: true }); + this.setState({ isProcessing: true }); + try { - RNIap.requestPurchase(sku, false); + IAP.requestPurchase(Platform.OS === 'ios' ? { sku } : { skus: [sku] }); } catch (err) { bugsnagInstance.notify(err, (report) => { report.addMetadata('sku', sku); @@ -210,11 +216,11 @@ class InAppPurchaseContainer extends Component { _handleQrPurchase = async () => { const { skus, dispatch, intl, route } = this.props; - const products = await RNIap.getProducts(skus); + const products = await IAP.getProducts({ skus }); const productId = route.param?.productId ?? ''; const username = route.param?.username ?? ''; - const product: Product = + const product: IAP.Product = productId && products && products.find((product) => product.productId === productId); if (product) { diff --git a/yarn.lock b/yarn.lock index 89dd7deb4..7b109c3b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4329,11 +4329,6 @@ domutils@^3.0.1: domelementtype "^2.3.0" domhandler "^5.0.1" -dooboolab-welcome@1.3.2: - version "1.3.2" - resolved "https://registry.yarnpkg.com/dooboolab-welcome/-/dooboolab-welcome-1.3.2.tgz#4928595312f0429b4ea1b485ba8767bae6acdab7" - integrity sha512-2NbMaIIURElxEf/UAoVUFlXrO+7n/FRhLCiQlk4fkbGRh9cJ3/f8VEMPveR9m4Ug2l2Zey+UCXjd6EcBqHJ5bw== - dottie@^2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/dottie/-/dottie-2.0.2.tgz#cc91c0726ce3a054ebf11c55fbc92a7f266dd154" @@ -9217,12 +9212,10 @@ react-native-highlight-words@^1.0.1: highlight-words-core "^1.0.3" prop-types "^15.5.7" -react-native-iap@^7.5.6: - version "7.5.6" - resolved "https://registry.yarnpkg.com/react-native-iap/-/react-native-iap-7.5.6.tgz#75a370f0a689da4fbe5ecf2cd9b7bdd0f7d20f2f" - integrity sha512-ua+KTq7NO+/Rw+S9cGDZizR45AdmpQ0LEx9gSubbRD3f5KSTp91mEMHgdyVcqUcxiBuVgRTfv3zy9mbPEdo8Mg== - dependencies: - dooboolab-welcome "1.3.2" +react-native-iap@^12.4.2: + version "12.4.2" + resolved "https://registry.yarnpkg.com/react-native-iap/-/react-native-iap-12.4.2.tgz#98f4a4f653f8beb7324cab5bb333308cc46d63a1" + integrity sha512-pl4mgkYQOf5uQPt5NX5ySW6+JhOhalvbqw+fGJ5lJ+ZxnDF/UMNEw6SWWjNF7XrU8X7yGkWamOHmco4RDPlFYg== react-native-image-crop-picker@^0.35.2: version "0.35.3" From 47621849279b2e961ff215eabbe0498f62153d97 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Tue, 8 Nov 2022 17:40:05 +0500 Subject: [PATCH 2/2] lint --- src/containers/inAppPurchaseContainer.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/containers/inAppPurchaseContainer.tsx b/src/containers/inAppPurchaseContainer.tsx index cd3b11cb4..c27748099 100644 --- a/src/containers/inAppPurchaseContainer.tsx +++ b/src/containers/inAppPurchaseContainer.tsx @@ -18,6 +18,7 @@ import { UserAvatar } from '../components'; class InAppPurchaseContainer extends Component { purchaseUpdateSubscription: EmitterSubscription | null = null; + purchaseErrorSubscription: EmitterSubscription | null = null; constructor(props) { @@ -52,7 +53,7 @@ class InAppPurchaseContainer extends Component { try { await IAP.initConnection(); if (Platform.OS === 'android') { - await IAP.flushFailedPurchasesCachedAsPendingAndroid() + await IAP.flushFailedPurchasesCachedAsPendingAndroid(); } await this._consumeAvailablePurchases(); @@ -83,7 +84,7 @@ class InAppPurchaseContainer extends Component { // consume item using finishTransactionx await IAP.finishTransaction({ purchase: purchases[i], - isConsumable: true + isConsumable: true, }); } } catch (err) { @@ -119,7 +120,7 @@ class InAppPurchaseContainer extends Component { try { const ackResult = await IAP.finishTransaction({ purchase, - isConsumable: true + isConsumable: true, }); console.info('ackResult', ackResult); } catch (ackErr) { @@ -199,7 +200,6 @@ class InAppPurchaseContainer extends Component { if (sku !== 'freePoints') { this.setState({ isProcessing: true }); - try { IAP.requestPurchase(Platform.OS === 'ios' ? { sku } : { skus: [sku] }); } catch (err) {