React-native-iap: getProducts works, but requestPurchase fails

Created on 16 Jun 2019  路  18Comments  路  Source: dooboolab/react-native-iap

Version of react-native-iap

^3.0.0-rc.2

Version of react-native

0.59.5

Platforms you faced the error (IOS or Android or both?)

Android

Expected behavior

const products = await RNIap.getProducts(preorders);
Result: Products: Two products with productIds 'xyz1', 'xyz2'
const purchase = await RNIap.requestPurchase('xyz1');
Expected: Purchase successful.

Actual behavior

const products = await RNIap.getProducts(preorders);
Result: Products: Two products with productIds 'xyz1', 'xyz2'
const purchase = await RNIap.requestPurchase('xyz1');
Actually: 'PROMISE_BUY_ITEM', 'The sku was not found. Please fetch products first by calling getItems'

Tested environment (Emulator? Real Device?)

Real Device Samsung S8

Steps to reproduce the behavior

As described above.

This even happens when directly before the purchase, I fetch the products again via RNIap.getProducts('skus').

PlayStore since more than 24h:
Beta Release: 0.3.0
Full rollout.
1 app bundle, version code: 1

馃檹 help wanted 馃 android

Most helpful comment

same issue facing on iap : 4.5.0

All 18 comments

@joeroos Could you tell what you're receivin in purchaseUpdatedListener?

purchaseUpdateSubscription = purchaseUpdatedListener((purchase: ProductPurchase) => {
  console.log('purchaseUpdatedListener', purchase);
  this.setState({ receipt: purchase.transactionReceipt }, () => this.goNext());
});
purchaseErrorSubscription = purchaseErrorListener((error: PurchaseError) => {
  console.log('purchaseErrorListener', error);
  Alert.alert('purchase error', JSON.stringify(error));
});

Also please try 3.0.0-rc.7 if not working as expected. Feel free to reopen when you still face the problem.

Hi @hyochan I upgraded to 3.0.0-rc.7. Still the same mistake.

Additionally, I found that in the index.d.ts, purchaseUpdateListener is exported twice, but purchaseErrorListener never. I assume this is a bug.

purchaseUpdateListener does not give any output! purchaseErrorListener I cannot say as it fails upon initiation (probably due to the bug I mentioned above).

So I removed purchaseErrorListener and changed the functions to not await the purchase, but just call RNIap.requestPurchase(sku);

Now function looks like this:
buyProduct = async (sku) => { console.info(buy: ${sku}); try { console.log('Trying to requestPurchase with ID', sku); RNIap.requestPurchase(sku); } catch (err) { console.warn(err.code, err.message); Alert.alert('Error while buying', err.message); } console.log('finished buyProduct'); };

Console output:
'Trying to requestPurchase with ID ', 'xyz1'
finished BuyProduct

Around 2s later:
Possible Unhandled Promise Rejection (id: 1):
Error: The sku was not found. Please fetch products first by calling getItems

Typo is fixed in 3.0.0-rc.8. Could you provide a full code of yours? I don't understand your symptoms. Also, could you try the example project first?

i have same issue
i have used listener and i got this
purchaseErrorListener {debugMessage: "The sku was not found. Please fetch products first by calling getItems"}

@yogeshmoradiya121 Which version are you using? Please try the recent one.

"react-native-iap": "^3.3.2",
"react-native": "0.60.3",

problem solved in 3.3.5 latest version
thnx @hyochan

Could you provide any message I can look up?

Same here. I get an error message: This item is unavailable.
purchaseErrorListener:{"responseCode":4}

"react-native-iap": "^3.3.5",
"react-native": "0.60.0",

Same here. I get an error message: This item is unavailable.
purchaseErrorListener:{"responseCode":4}

"react-native-iap": "^3.3.5",
"react-native": "0.60.0",

same problem
but it is not observed on all devices.
on some devices a can bay subscriptions

I'm experiencing the same problem with a more recent version of RN and RN IAP.

"react-native-iap": "^4.2.2",
"react-native": "0.61.5",

Experiencing the same problem

"react-native": "0.59.8",
"react-native-iap": "^4.3.0"

Same to me. It only happens on Android devices (not all, some of them)

"react-native-iap": "^4.3.2"
"react-native": "0.61.4"

Could you share some useful information other than the versions? Something like code snippets or minimal reproduction so I can move this forward.

Also please try out the latest version which currently is 4.4.4.
Thanks.

It is working for me now, sadly I've lost context.

But remember the Issue being in project code.
Will update when I remember.

same issue facing on iap : 4.5.0

Same issue on iap 4.5.4

Was this page helpful?
0 / 5 - 0 ratings