Skip to content

Commit

Permalink
Upgrade react native iap (#196)
Browse files Browse the repository at this point in the history
* uncomment purchasing code

* upgraded iap library to latest version
  • Loading branch information
kamalkishor1991 authored Mar 13, 2024
1 parent 201d088 commit b3cb72f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 42 deletions.
7 changes: 5 additions & 2 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { ActivityIndicator } from 'react-native';
import LoginOverlayScreen from './components/LoginOverlayScreen';
import ApplicationRoot from './ApplicationRoot';
import Storage from './libs/Storage';
import { withIAPContext } from 'react-native-iap';

export default function App() {
const App = () => {
const [isLoading, setIsLoading] = React.useState(false);
const [isLoginOverlayStepDone, setIsLoginOverlayStepDone] = React.useState(true);
React.useEffect(() => {
Expand All @@ -29,4 +30,6 @@ export default function App() {
) : (
<ActivityIndicator />
);
}
};

export default withIAPContext(App);
11 changes: 1 addition & 10 deletions ApplicationRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import HamburgerMenu from './components/HamburgerMenu';
import SideMenu from 'react-native-side-menu';
import { HEADER_HEIGHT } from './constants/Layout';
import Entypo from 'react-native-vector-icons/Entypo';
import { notifyMessage } from './libs/Helpers';
import RNIap from 'react-native-iap';
import { t } from 'i18next';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
const Stack = createNativeStackNavigator();

/*import { LogBox } from 'react-native'; // enabled for recording demos
LogBox.ignoreAllLogs();//Ignore all log notifications*/
export default function App() {
Expand All @@ -36,17 +35,9 @@ export default function App() {
const navigationRef = useNavigationContainerRef();
useEffect(() => {
(async () => {
try {
await RNIap.initConnection();
} catch (e) {
notifyMessage(t('Error initializing purchase: ') + e);
}
await applicationState.loadInitPaletteFromStore();
setIsPalettesLoaded(true);
})();
return () => {
RNIap.endConnection();
};
}, []);

const spinner = (
Expand Down
33 changes: 18 additions & 15 deletions libs/Helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { NativeModules, Platform, Alert, ToastAndroid } from 'react-native';
import RNIap from 'react-native-iap';
import * as RNIap from 'react-native-iap';
import { requestPurchase, getProducts } from 'react-native-iap';

const productSku = function () {
return Platform.OS === 'android' ? 'croma_pro' : 'app_croma';
};
Expand All @@ -24,8 +26,11 @@ const purchase = async function (setPurchase, productSKU) {
productSKU = productSku();
}
try {
await RNIap.getProducts([productSKU]);
const details = await RNIap.requestPurchase(productSKU, false);
await getProducts({ skus: [productSKU] });
const details = await requestPurchase({
skus: [productSKU],
andDangerouslyFinishTransactionAutomatically: true
});
await setPurchase(details);
logEvent('purchase_successful');
notifyMessage('Congrats, You are now a pro user!');
Expand All @@ -36,18 +41,16 @@ const purchase = async function (setPurchase, productSKU) {
}
};
const initPurchase = async function (setPurchase) {
// const productSKU = productSku();
await setPurchase('Free pro user');
notifyMessage('Congrats, You are a pro user. Huehive pro version is now free for limited time!');
// try {
// let products = await getAvailablePurchases();
// if (products.find((product) => product.productId === productSKU)) {
// await setPurchase(products.find((product) => product.productId === productSKU));
// notifyMessage('Congrats, You are already a pro user!');
// }
// } catch (e) {
// notifyMessage('Failed during initialization of purchase: ' + e);
// }
const productSKU = productSku();
try {
let products = await getAvailablePurchases();
if (products.find((product) => product.productId === productSKU)) {
await setPurchase(products.find((product) => product.productId === productSKU));
notifyMessage('Congrats, You are already a pro user!');
}
} catch (e) {
notifyMessage('Failed during initialization of purchase: ' + e);
}
};

const getAvailablePurchases = async () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"react-native-fs": "^2.18.0",
"react-native-gesture-handler": "^2.0.0",
"react-native-get-random-values": "^1.8.0",
"react-native-iap": "^7.5.5",
"react-native-iap": "^12.0.0",
"react-native-image-picker": "^4.3.0",
"react-native-localize": "^2.2.4",
"react-native-reanimated": "^2.2.3",
Expand Down
129 changes: 115 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,29 @@
xcode "^3.0.1"
xml2js "^0.4.23"

"@expo/config-plugins@^7.8.4":
version "7.8.4"
resolved "https://registry.yarnpkg.com/@expo/config-plugins/-/config-plugins-7.8.4.tgz#533b5d536c1dc8b5544d64878b51bda28f2e1a1f"
integrity sha512-hv03HYxb/5kX8Gxv/BTI8TLc9L06WzqAfHRRXdbar4zkLcP2oTzvsLEF4/L/TIpD3rsnYa0KU42d0gWRxzPCJg==
dependencies:
"@expo/config-types" "^50.0.0-alpha.1"
"@expo/fingerprint" "^0.6.0"
"@expo/json-file" "~8.3.0"
"@expo/plist" "^0.1.0"
"@expo/sdk-runtime-versions" "^1.0.0"
"@react-native/normalize-color" "^2.0.0"
chalk "^4.1.2"
debug "^4.3.1"
find-up "~5.0.0"
getenv "^1.0.0"
glob "7.1.6"
resolve-from "^5.0.0"
semver "^7.5.3"
slash "^3.0.0"
slugify "^1.6.6"
xcode "^3.0.1"
xml2js "0.6.0"

"@expo/config-types@^41.0.0":
version "41.0.0"
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-41.0.0.tgz#ffe1444c6c26e0e3a8f7149b4afe486e357536d1"
Expand All @@ -1430,6 +1453,11 @@
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-42.0.0.tgz#3e3e125ec092c0c34dbfaf19be5480402de3d677"
integrity sha512-Rj02OMZke2MrGa/1Y/EScmR7VuWbDEHPJyvfFyyLbadUt+Yv6isCdeFzDt71I7gJlPR9T4fzixeYLrtXXOTq0w==

"@expo/config-types@^50.0.0-alpha.1":
version "50.0.0"
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-50.0.0.tgz#b534d3ec997ec60f8af24f6ad56244c8afc71a0b"
integrity sha512-0kkhIwXRT6EdFDwn+zTg9R2MZIAEYGn1MVkyRohAd+C9cXOb5RA8WLQi7vuxKF9m1SMtNAUrf0pO+ENK0+/KSw==

"@expo/config@^4.0.0":
version "4.0.4"
resolved "https://registry.yarnpkg.com/@expo/config/-/config-4.0.4.tgz#48686c2b83bc00db469e01592e396e973e91e11d"
Expand All @@ -1450,6 +1478,19 @@
semver "7.3.2"
slugify "^1.3.4"

"@expo/fingerprint@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@expo/fingerprint/-/fingerprint-0.6.0.tgz#77366934673d4ecea37284109b4dd67f9e6a7487"
integrity sha512-KfpoVRTMwMNJ/Cf5o+Ou8M/Y0EGSTqK+rbi70M2Y0K2qgWNfMJ1gm6sYO9uc8lcTr7YSYM1Rme3dk7QXhpScNA==
dependencies:
"@expo/spawn-async" "^1.5.0"
chalk "^4.1.2"
debug "^4.3.4"
find-up "^5.0.0"
minimatch "^3.0.4"
p-limit "^3.1.0"
resolve-from "^5.0.0"

"@expo/[email protected]":
version "8.2.30"
resolved "https://registry.yarnpkg.com/@expo/json-file/-/json-file-8.2.30.tgz#bd855b6416b5c3af7e55b43f6761c1e7d2b755b0"
Expand All @@ -1469,6 +1510,15 @@
json5 "^1.0.1"
write-file-atomic "^2.3.0"

"@expo/json-file@~8.3.0":
version "8.3.0"
resolved "https://registry.yarnpkg.com/@expo/json-file/-/json-file-8.3.0.tgz#fc84af77b532a4e9bfb5beafd0e3b7f692b6bd7e"
integrity sha512-yROUeXJXR5goagB8c3muFLCzLmdGOvoPpR5yDNaXrnTp4euNykr9yW0wWhJx4YVRTNOPtGBnEbbJBW+a9q+S6g==
dependencies:
"@babel/code-frame" "~7.10.4"
json5 "^2.2.2"
write-file-atomic "^2.3.0"

"@expo/[email protected]":
version "0.0.13"
resolved "https://registry.yarnpkg.com/@expo/plist/-/plist-0.0.13.tgz#700a48d9927aa2b0257c613e13454164e7371a96"
Expand All @@ -1487,6 +1537,27 @@
base64-js "^1.2.3"
xmlbuilder "^14.0.0"

"@expo/plist@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@expo/plist/-/plist-0.1.0.tgz#eabc95f951d14e10c87fd0443ee01d567371f058"
integrity sha512-xWD+8vIFif0wKyuqe3fmnmnSouXYucciZXFzS0ZD5OV9eSAS1RGQI5FaGGJ6zxJ4mpdy/4QzbLdBjnYE5vxA0g==
dependencies:
"@xmldom/xmldom" "~0.7.7"
base64-js "^1.2.3"
xmlbuilder "^14.0.0"

"@expo/sdk-runtime-versions@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@expo/sdk-runtime-versions/-/sdk-runtime-versions-1.0.0.tgz#d7ebd21b19f1c6b0395e50d78da4416941c57f7c"
integrity sha512-Doz2bfiPndXYFPMRwPyGa1k5QaKDVpY806UJj570epIiMzWaYyCtobasyfC++qfIXVb5Ocy7r3tP9d62hAQ7IQ==

"@expo/spawn-async@^1.5.0":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@expo/spawn-async/-/spawn-async-1.7.2.tgz#fcfe66c3e387245e72154b1a7eae8cada6a47f58"
integrity sha512-QdWi16+CHB9JYP7gma19OVVg0BFkvU8zNj9GjWorYI8Iv8FUxjOCcYRuAmX4s/h91e4e7BPsskc8cSrZYho9Ew==
dependencies:
cross-spawn "^7.0.3"

"@hapi/hoek@^9.0.0":
version "9.2.1"
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.2.1.tgz#9551142a1980503752536b5050fd99f4a7f13b17"
Expand Down Expand Up @@ -1969,6 +2040,11 @@
resolved "https://registry.yarnpkg.com/@react-native/normalize-color/-/normalize-color-1.0.0.tgz#c52a99d4fe01049102d47dc45d40cbde4f720ab6"
integrity sha512-xUNRvNmCl3UGCPbbHvfyFMnpvLPoOjDCcp5bT9m2k+TF/ZBklEQwhPZlkrxRx2NhgFh1X3a5uL7mJ7ZR+8G7Qg==

"@react-native/normalize-color@^2.0.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@react-native/normalize-color/-/normalize-color-2.1.0.tgz#939b87a9849e81687d3640c5efa2a486ac266f91"
integrity sha512-Z1jQI2NpdFJCVgpY+8Dq/Bt3d+YUi1928Q+/CZm/oh66fzM0RUl54vvuXlPJKybH4pdCZey1eDTPaLHkMPNgWA==

"@react-native/normalize-colors@*":
version "0.73.0"
resolved "https://registry.yarnpkg.com/@react-native/normalize-colors/-/normalize-colors-0.73.0.tgz#23e15cf2a2b73ac7e5e6df8d5b86b173cfb35a3f"
Expand Down Expand Up @@ -2269,6 +2345,11 @@
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.7.5.tgz#09fa51e356d07d0be200642b0e4f91d8e6dd408d"
integrity sha512-V3BIhmY36fXZ1OtVcI9W+FxQqxVLsPKcNjWigIaa81dLC9IolJl5Mt4Cvhmr0flUnjSpTdrbMTSbXqYqV5dT6A==

"@xmldom/xmldom@~0.7.7":
version "0.7.13"
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.7.13.tgz#ff34942667a4e19a9f4a0996a76814daac364cf3"
integrity sha512-lm2GW5PkosIzccsaZIz7tp8cPADSIlIHWDFTR1N0SzfinhhYgeIQjFMz4rYzanCScr3DqQLeomUDArp6MWKm+g==

abab@^2.0.3, abab@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a"
Expand Down Expand Up @@ -3369,7 +3450,7 @@ cross-spawn@^6.0.0:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.2:
cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down Expand Up @@ -3437,7 +3518,7 @@ debug@4, debug@^4.1.1, debug@^4.3.1:
dependencies:
ms "2.1.2"

debug@^4.1.0, debug@^4.3.2:
debug@^4.1.0, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
Expand Down Expand Up @@ -3592,11 +3673,6 @@ domexception@^2.0.1:
dependencies:
webidl-conversions "^5.0.0"

[email protected]:
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==

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
Expand Down Expand Up @@ -4251,7 +4327,7 @@ find-up@^4.0.0, find-up@^4.1.0:
locate-path "^5.0.0"
path-exists "^4.0.0"

find-up@~5.0.0:
find-up@^5.0.0, find-up@~5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-5.0.0.tgz#4c92819ecb7083561e4f4a240a86be5198f536fc"
integrity sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==
Expand Down Expand Up @@ -5655,6 +5731,11 @@ json5@^2.1.2:
dependencies:
minimist "^1.2.5"

json5@^2.2.2:
version "2.2.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==

jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
Expand Down Expand Up @@ -6686,7 +6767,7 @@ p-limit@^2.0.0, p-limit@^2.2.0:
dependencies:
p-try "^2.0.0"

p-limit@^3.0.2:
p-limit@^3.0.2, p-limit@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
Expand Down Expand Up @@ -7214,12 +7295,12 @@ react-native-get-random-values@^1.8.0:
dependencies:
fast-base64-decode "^1.0.0"

react-native-iap@^7.5.5:
version "7.5.5"
resolved "https://registry.yarnpkg.com/react-native-iap/-/react-native-iap-7.5.5.tgz#63557cebab6e42b6b3a505c54b116dfda232e474"
integrity sha512-5m/zJJbN8W8/dDzIwveXApqi5nFfytBgb3ftCgOSEEkgcdZPomyyE2CoK9ntia8mrQOmoIuUlvDdkegqBW/5Pg==
react-native-iap@^12.0.0:
version "12.13.0"
resolved "https://registry.yarnpkg.com/react-native-iap/-/react-native-iap-12.13.0.tgz#8df99c616db5ba14bf34cf3f45e8730c3bcd2a7e"
integrity sha512-M9pyjTipgAl459S1xjLH2s+0AwiqAHgg3KRA8QSqR7dN3qyzV2dr4W6TH7HGUsdGIA6lEEbeco0gRk8BqoThow==
dependencies:
dooboolab-welcome "1.3.2"
"@expo/config-plugins" "^7.8.4"

react-native-image-picker@^4.3.0:
version "4.10.3"
Expand Down Expand Up @@ -7777,6 +7858,13 @@ semver@^7.3.2, semver@^7.3.5:
dependencies:
lru-cache "^6.0.0"

semver@^7.5.3:
version "7.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
dependencies:
lru-cache "^6.0.0"

[email protected]:
version "0.17.1"
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"
Expand Down Expand Up @@ -7959,6 +8047,11 @@ slugify@^1.3.4:
resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.2.tgz#4cb97220a2278e1b86fb017c6da668e6a865354c"
integrity sha512-XMtI8qD84LwCpthLMBHlIhcrj10cgA+U/Ot8G6FD6uFuWZtMfKK75JO7l81nzpFJsPlsW6LT+VKqWQJW3+6New==

slugify@^1.6.6:
version "1.6.6"
resolved "https://registry.yarnpkg.com/slugify/-/slugify-1.6.6.tgz#2d4ac0eacb47add6af9e04d3be79319cbcc7924b"
integrity sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==

snapdragon-node@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
Expand Down Expand Up @@ -8910,6 +9003,14 @@ xml-name-validator@^3.0.0:
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==

[email protected]:
version "0.6.0"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.0.tgz#07afc447a97d2bd6507a1f76eeadddb09f7a8282"
integrity sha512-eLTh0kA8uHceqesPqSE+VvO1CDDJWMwlQfB6LuN6T8w6MaDJ8Txm8P7s5cHD0miF0V+GGTZrDQfxPZQVsur33w==
dependencies:
sax ">=0.6.0"
xmlbuilder "~11.0.0"

xml2js@^0.4.23:
version "0.4.23"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66"
Expand Down

0 comments on commit b3cb72f

Please sign in to comment.