React-native-iap: buyProduct not returning E_USER_CANCELLED when cancelling a transaction

Created on 5 Jul 2019  路  5Comments  路  Source: dooboolab/react-native-iap

Version of react-native-iap

3.2.3

Version of react-native

0.58.6

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

iOS

Expected behavior

When the user cancels a transaction, RNIap.buyProduct returns null instead of raising an exception with error.code E_USER_CANCELLED.

Actual behavior

When the user cancels a transaction, RNIap.buyProduct returns null

Tested environment (Emulator? Real Device?)

Real device

Steps to reproduce the behavior

This is the code:

 async buyItem(sku) {
    try {
      const purchase = await RNIap.buyProduct(sku)

      if (!purchase) {
        // This should not happen
        return
      }

      // Omitted code
    } catch (err) {
      if (err.code && err.code === 'E_USER_CANCELLED') {
        // Not being called
      }
    }
  }
  1. Tap on a product on device
  2. Wait for subscription confirmation dialog to appear.
  3. Click Cancel
馃摫 iOS 馃檹 help wanted

Most helpful comment

@solidfox I think it should be handled in plugin as @hyochan suggested. The plugin shall send the same error code for both Android and iOS in the updated listener pattern too.

I see currently Listner is sending error: responseCode, debugMessage. We can add additional error keys generated by rejectPromiseWithBillingError() or standardErrorCode.

I will try sending PR this weekend. If anyone can do it early, please do it 馃槃

All 5 comments

@kennym I've seen related issue earlier and we need to fix this. Currently, cancelling send @null array in ios. I hope you can give us a PR.

You can (and probably should) use the new listener pattern to listen to errors. An error with responseCode 1 on android and "2" on iOS means the user cancelled. Note that iOS will give you the code as a string while Android enters it as an integer.

@solidfox I think it should be handled in plugin as @hyochan suggested. The plugin shall send the same error code for both Android and iOS in the updated listener pattern too.

I see currently Listner is sending error: responseCode, debugMessage. We can add additional error keys generated by rejectPromiseWithBillingError() or standardErrorCode.

I will try sending PR this weekend. If anyone can do it early, please do it 馃槃

The flow and TypeScript type of responseCode is number, but it's string on iOS 馃し鈥嶁檪

Closed via #616

Was this page helpful?
0 / 5 - 0 ratings