From c5c1ad2ee6115b1ee3f7efec2e59dabd4e2eea18 Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Sat, 13 Aug 2022 15:20:21 +0500 Subject: [PATCH] parse points url with product id and navigate to purchase --- src/containers/inAppPurchaseContainer.ts | 11 ++++++++++- src/utils/deepLinkParser.ts | 5 +++-- src/utils/parsePurchaseUrl.ts | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/containers/inAppPurchaseContainer.ts b/src/containers/inAppPurchaseContainer.ts index 62f7d288a..f083480b7 100644 --- a/src/containers/inAppPurchaseContainer.ts +++ b/src/containers/inAppPurchaseContainer.ts @@ -59,7 +59,7 @@ class InAppPurchaseContainer extends Component { await this._consumeAvailablePurchases() this._getItems(); this._purchaseUpdatedListener(); - + await this._handleQrPurchase(); } catch (err) { bugsnagInstance.notify(err); console.warn(err.code, err.message); @@ -202,6 +202,15 @@ class InAppPurchaseContainer extends Component { } }; + _handleQrPurchase = async () => { + const { navigation, skus } = this.props as any; + const products = await RNIap.getProducts(skus); + const productId = navigation.getParam('productId', ''); + if(productId && products && products.find((product) => product.productId === productId)){ + await this._buyItem(productId); + } + } + render() { const { children, isNoSpin } = this.props; const { productList, isLoading, isProcessing } = this.state; diff --git a/src/utils/deepLinkParser.ts b/src/utils/deepLinkParser.ts index 62cf50819..d64dd510f 100644 --- a/src/utils/deepLinkParser.ts +++ b/src/utils/deepLinkParser.ts @@ -83,8 +83,8 @@ export const deepLinkParser = async (url, currentAccount) => { } //if url is for purchase - const { type, username} = parsePurchaseUrl(url) || {}; - console.log('type, username : ', type, username); + const { type, username, productId} = parsePurchaseUrl(url) || {}; + // console.log('type, username, productId : ', type, username, productId); if(type && type === 'boost'){ routeName = ROUTES.SCREENS.ACCOUNT_BOOST; params = { @@ -96,6 +96,7 @@ export const deepLinkParser = async (url, currentAccount) => { routeName = ROUTES.SCREENS.BOOST; params = { username, + productId }; keey = `${type}/${username || ''}`; } diff --git a/src/utils/parsePurchaseUrl.ts b/src/utils/parsePurchaseUrl.ts index 801a05510..b977276b0 100644 --- a/src/utils/parsePurchaseUrl.ts +++ b/src/utils/parsePurchaseUrl.ts @@ -10,9 +10,11 @@ export default (urlString:string) => { if(url.pathname === '/purchase'){ const type = url.searchParams.get('type'); const username = url.searchParams.get('username'); + const productId = url.searchParams.get('product_id'); return { type, - username + username, + productId } }