Question

when purchaseStoreProduct, no response

  • 10 October 2023
  • 3 replies
  • 63 views

Badge

I am trying to purchase a product in React native.

my env:

"react-native": "0.68.2",

"react-native-purchases": "^6.6.5",

 

in iOS, after configure with iOS public key, I try to purchase a product by using a function purchaseStoreProduct

const { customerInfo, productIdentifier } = await Purchases.purchaseStoreProduct(product);

But I could not get any response as well as any errors.

In my test, I could get the Apple login modal prompt at the first function call.
But after some times, when trying to call this function, I could not get any response.

 


3 replies

Userlevel 5
Badge +8

Hey @cheng-he-70a75c,

Apologies, I’m not sure we have enough information to investigate what’s happening in this case.

Can you provide debug logs reproducing the issue?

Badge

Thanks for reaching me.

After following the sandbox test in iOS, (especially using StoreKit), then it worked.

Best.

Badge +3

I'm experiencing the same issue. There's no problem in the simulator, but when I try it on TestFlight with a real device, there's an issue. If I'm making a purchase, everything works fine, but if the user cancels the purchase, `purchaseStoreProduct` doesn't return any result at all. Therefore, my function doesn't enter into the `catch` or `finally` blocks.

 

{
"name": "evrakcepte",
"version": "1.0.0",
"private": true,
"scripts": {
"android": "npx react-native run-android",
"ios": "npx react-native run-ios --simulator 'iPhone 15'",
"6s": "npx react-native run-ios --device 'Tab iPhone’u'",
"start": "npx react-native start",
"lint": "eslint .",
"androidBuild": "cd android; ./gradlew assembleRelease; cd ..",
"androidBundle": "cd android; ./gradlew bundleRelease; cd ..",
"androidClean": "cd android; ./gradlew clean; cd ..",
"pod": "cd ios; pod install; cd ..",
"svgYap": "npx @svgr/cli ./src/assets/svg -d ./src/v2/Components/Svg --native --icon --svg-props \"width=24,height=24\""
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.18.1",
"@react-native-community/clipboard": "^1.5.1",
"@react-native-community/datetimepicker": "^7.1.0",
"@react-native-community/hooks": "^3.0.0",
"@react-native-community/netinfo": "^9.3.10",
"@react-native-community/push-notification-ios": "^1.11.0",
"@react-native-community/slider": "^4.4.2",
"@react-native-masked-view/masked-view": "^0.2.9",
"@react-native-picker/picker": "^1.16.8",
"@react-navigation/bottom-tabs": "^6.5.7",
"@react-navigation/drawer": "^6.6.2",
"@react-navigation/elements": "^1.3.17",
"@react-navigation/native": "^6.1.6",
"@react-navigation/native-stack": "^6.9.12",
"@react-navigation/stack": "^6.3.16",
"add": "^2.0.6",
"appcenter": "5.0.1",
"appcenter-analytics": "5.0.1",
"appcenter-crashes": "5.0.1",
"i": "^0.3.7",
"jail-monkey": "^2.8.0",
"md5": "^2.3.0",
"moment": "^2.29.4",
"popup-ui": "git+https://github.com/ilyasbat/react-native-popup-ui.git",
"react": "18.2.0",
"react-native": "0.71.7",
"react-native-actionsheet": "^2.4.2",
"react-native-autoheight-webview": "^1.6.5",
"react-native-autolink": "^4.1.0",
"react-native-background-timer": "^2.4.1",
"react-native-code-push": "^8.2.1",
"react-native-device-info": "^8.7.1",
"react-native-document-picker": "^6.1.1",
"react-native-easy-toast": "^2.3.0",
"react-native-fast-image": "^8.6.3",
"react-native-gesture-handler": "^2.15.0",
"react-native-gifted-chat": "^2.4.0",
"react-native-google-mobile-ads": "^12.6.0",
"react-native-iap": "^12.10.8",
"react-native-image-modal": "^2.0.4",
"react-native-image-picker": "^5.3.1",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-linear-gradient": "^2.6.2",
"react-native-modal": "^13.0.1",
"react-native-modal-datetime-picker": "^15.0.1",
"react-native-onesignal": "^5.0.4",
"react-native-pager-view": "^6.2.3",
"react-native-pell-rich-editor": "git+https://github.com/*****/react-native-rich-editor",
"react-native-permissions": "^4.0.0",
"react-native-picker-select": "git+https://github.com/*****/react-native-picker-select.git",
"react-native-popable": "^0.4.3",
"react-native-popup-menu": "^0.16.1",
"react-native-progress-steps": "^1.3.4",
"react-native-purchases": "^7.20.0",
"react-native-push-notification": "git+https://github.com/*****/react-native-push-notification",
"react-native-rate": "^1.2.12",
"react-native-reanimated": "^3.7.0",
"react-native-render-html": "^6.3.4",
"react-native-safe-area-context": "^3.4.1",
"react-native-screens": "^3.29.0",
"react-native-shimmer": "^0.6.0",
"react-native-snap-carousel": "^4.0.0-beta.6",
"react-native-sqlite-storage": "^6.0.1",
"react-native-svg": "^13.9.0",
"react-native-swipe-gestures": "^1.0.5",
"react-native-tab-view": "^3.5.2",
"react-native-table-component": "^1.2.2",
"react-native-video": "^5.2.1",
"react-native-walkthrough-tooltip": "^1.5.0",
"react-native-webview": "^13.6.4",
"react-redux": "^8.0.5",
"redux": "^4.2.1",
"redux-thunk": "^2.4.2",
"rn-emoji-keyboard": "^1.2.2",
"websqlite": "^1.3.1",
"yarn": "^1.22.19"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native-community/eslint-config": "^3.2.0",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^29.2.1",
"@types/react": "^18.0.24",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"eslint": "^8.22.0",
"jest": "^29.2.1",
"metro-react-native-babel-preset": "0.73.9",
"prettier": "^3.2.5",
"react-test-renderer": "18.2.0",
"typescript": "4.8.4"
},
"jest": {
"preset": "react-native"
},
"resolutions": {
"@react-native-community/cli-debugger-ui": "7.0.3"
}
}

my package.json 

and function

  const reqSubscription = async p => {
setBuyLoading(true);

const intervalId = setInterval(async () => {
const {customerInfo, created} = await Purchases.logIn(
store.getMemberReducer.uyeId.toString(),
);

if (customerInfo.activeSubscriptions.length > 0) {
const uyelik = parseInt(store.getMemberReducer.uyelik);

const exp = parseInt(
customerInfo.allExpirationDatesMillis[
customerInfo.activeSubscriptions[0]
] / 1000,
);
if (exp > now && store.getMemberReducer.uyeId && exp > uyelik) {
await finish(customerInfo);
clearInterval(intervalId);
}
}
}, 1000);

try {
const id = Platform.OS === 'ios' ? p.ios_paket : p.android_paket;
let product;
if (Platform.OS === 'ios') {
const r = revenuePackages.filter(f => f.identifier === id);
product = r[0];
} else {
const r = revenuePackages.filter(
f => f.subscriptionOptions[0].storeProductId === id,
);
product = r[0];
}
const pay = await Purchases.purchaseStoreProduct(product);
if (typeof pay.entitlements.active['Pro'] !== 'undefined') {
await finish(pay);
clearInterval(intervalId);
}
} catch (e) {
clearInterval(intervalId);
if (!e.userCancelled) {
PopupError(e.toString());
}
} finally {
setBuyLoading(false);
}
};

 

Reply