React-native-iap: [RNIAP - 3.5.1]Cannot read property 'getItemsByType' of undefined when using getSubscriptions after migrating to new version of RNIAP

Created on 30 Sep 2019  路  8Comments  路  Source: dooboolab/react-native-iap

Version of react-native-iap

3.5.1

Version of react-native

0.61.1

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

Android for now

Expected behavior

It should returns subscriptions info just like the old version of RNIAP (old version was 2.4.1)

Actual behavior

It shows error Cannot read property 'getItemsByType' of undefined

Tested environment (Emulator? Real Device?)

Android Real Device (Debug Mode)

Steps to reproduce the behavior

  • Unlink RNIAP 2.4.1
  • Install new RNIAP 3.5.1
  • Follow the instruction of the new version
    image
    I use the AndroidX in this case
  • Update deprecated function such as: endConnection to endConnectionAndroid, buySubscription to requestSubscription
  • react-native run-android on real android device
  • Go to the screen that use RNIap.getSubscriptions(itemSkus), then receive the above error
馃懀 waiting for response 馃檹 help wanted 馃 android

Most helpful comment

@hyochan after a project cleaning and using 3.5.2 I made it work again. Thanks

All 8 comments

Without additional information, it feels pretty hard to help you out. Would you like to try out for example project and see the differences compared to yours?

Also, please use 3.5.2 or later because below versions had some typing issues #740.

I got similar issues, it seems to me that autolinking is broken for android starting version 3.5.x.

@benoitvallon Could you try example project? I've tested this before releasing and the build didn't matter.

Hi @hyochan, I just upgraded to 3.5.2, and getSubscriptions function is working fine now, thanks a lot!! However, because I migrated from the old version 2.4.1 to 3.5.2, so I need to migrate to the new flow of purchasing the subscriptions right?

Could you please help me to confirm several things about the new flow, I'll very appreciate:
Currently, my app is using subscriptions only (no item purchase), based on the example folder, is this one the new flow for subscriptions:

initConnection --> purchaseUpdatedListener --> purchaseErrorListener --> getSubscriptions to display price and info of subs --> user request a sub --> call requestSubscription with corresponding id --> if requestSubscription succeed, thepurchaseUpdatedListener receives purchase receipt --> send receipt to my backend to update the user's premium info --> If backend response succeed --> acknowledgePurchaseAndroid (for android), and finishTransactionIOS (for iOS) --> clear function subscriptions when component unmount

Error Cases:

  1. If for example, the requestSubscription failed, then purchaseErrorListener will receive an error, then the only thing I need to do in this case is displaying the error for user right?
  1. If the request to my server is having error, or app crashes at the time I receive the receipt in the purchaseUpdatedListener --> then the next time I go to the app, whereover I call the purchaseUpdatedListener, this listener will immediately receive the old receipt of my previous subscription request right? Then I need to re-request my API to finalize the sub purchase, is it correct?

Please correct me if I'm missing something, or I use the wrong functions for my flow, thanks a lot

@hyochan after a project cleaning and using 3.5.2 I made it work again. Thanks

Hi @hyochan, I just upgraded to 3.5.2, and getSubscriptions function is working fine now, thanks a lot!! However, because I migrated from the old version 2.4.1 to 3.5.2, so I need to migrate to the new flow of purchasing the subscriptions right?

Could you please help me to confirm several things about the new flow, I'll very appreciate:
Currently, my app is using subscriptions only (no item purchase), based on the example folder, is this one the new flow for subscriptions:

initConnection --> purchaseUpdatedListener --> purchaseErrorListener --> getSubscriptions to display price and info of subs --> user request a sub --> call requestSubscription with corresponding id --> if requestSubscription succeed, thepurchaseUpdatedListener receives purchase receipt --> send receipt to my backend to update the user's premium info --> If backend response succeed --> acknowledgePurchaseAndroid (for android), and finishTransactionIOS (for iOS) --> clear function subscriptions when component unmount

Error Cases:

  1. If for example, the requestSubscription failed, then purchaseErrorListener will receive an error, then the only thing I need to do in this case is displaying the error for user right?
  2. If the request to my server is having error, or app crashes at the time I receive the receipt in the purchaseUpdatedListener --> then the next time I go to the app, whereover I call the purchaseUpdatedListener, this listener will immediately receive the old receipt of my previous subscription request right? Then I need to re-request my API to finalize the sub purchase, is it correct?

Please correct me if I'm missing something, or I use the wrong functions for my flow, thanks a lot

  1. Right!
  2. If it crahsed, if you lost your receipt you can't retrieve in ios. Therefore, you should becareful with this. Also if you don't finishTransaction or acknowledgePurchase it won't get charged. I mean it will be refunded in 3 days.

@hyochan Thanks a lot for the info

Please see my updated sentence at the end which says that it will be refunded.

Was this page helpful?
0 / 5 - 0 ratings