Ionic-native/in-app-purchase-2 store.ready never fired

Problem:
I followed https://ionicframework.com/docs/native/in-app-purchase-2/ for installing this plugin in an ionic app which I believe is wrapped around for using in Typescript by ionic-native/in-app-purchase-2. I have a fairly basic example:

somewhere:
platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      purchaseService.initStore();
    });
and:
public initStore() {
    try {
      console.log('Starting Store initialization');
      // After Platform Ready
      this.store.verbosity = this.store.DEBUG;

      const productId = 'MY_PID';
      this.store.register({
        id: productId,
        alias: productId,
        type: this.store.NON_CONSUMABLE
      });

      // Track All Store Errors
      this.store.error((err) => {
        console.log('Caught error:' + JSON.stringify(err));
      });

      this.store.ready()
        .then(() => {
          console.log('\n\nSTORE IS READY: All Products: ' + JSON.stringify(this.store.products));
        })
        .catch(e => {
          console.error('\nSomething went wrong with store ready:', JSON.stringify(e));
        });

      // Refresh Starts Handlers
      this.store.refresh();
    } catch (e) {
      console.error('\n\n\nFailed to initiate store:', e);
  }

Expected behaviour:

I expect store.ready fire and I see the log message; however this never happens and I catch the error while the err object is also undefined! However, in the debug log line I see IAB actually does initialize fine and loads my product just fine:

10-15 11:52:59.834 15910-16025/? D/IabHelper: Querying owned items, item type: inapp
10-15 11:52:59.834 15910-16025/? D/IabHelper: Package name: com.ionicframework.***
10-15 11:52:59.834 15910-16025/? D/IabHelper: Calling getPurchases with continuation token: null
10-15 11:52:59.836 4379-4392/? I/Finsky: [9404] com.google.android.finsky.billing.iab.w.b(29): com.ionicframework.fitopedia341280: Account determined from installer data - [e5pJlgw0LpmBFL63YV-HwrjR8mg]
10-15 11:52:59.837 15910-16025/? D/IabHelper: Owned items response: 0
10-15 11:52:59.837 15910-16025/? D/IabHelper: Continuation token: null
10-15 11:52:59.838 15910-16025/? D/IabHelper: Querying SKU details.
10-15 11:52:59.838 15910-16025/? D/IabHelper: moreSkus: Building SKUs List
10-15 11:52:59.838 15910-16025/? D/IabHelper: moreSkus: ***
10-15 11:52:59.866 15910-16025/? D/IabHelper: Got sku details: SkuDetails:**{"productId":"**","type":"inapp","price":"$0.99","price_amount_micros":990000,"price_currency_code":"CAD","title":"title","description":"my description!"}**
10-15 11:52:59.866 15910-16025/? D/IabHelper: Querying owned items, item type: subs
10-15 11:52:59.866 15910-16025/? D/IabHelper: Package name: com.ionicframework.**
10-15 11:52:59.866 15910-16025/? D/IabHelper: Calling getPurchases with continuation token: null
10-15 11:52:59.869 15910-16025/? D/IabHelper: Owned items response: 0
10-15 11:52:59.869 15910-16025/? D/IabHelper: Continuation token: null
10-15 11:52:59.869 15910-16025/? D/IabHelper: Querying SKU details.
10-15 11:52:59.869 15910-16025/? D/IabHelper: moreSkus: Building SKUs List
10-15 11:52:59.869 15910-16025/? D/IabHelper: moreSkus: fitopedia.test.*
10-15 11:52:59.881 15910-16025/? D/IabHelper: Ending async operation: refresh inventory
10-15 11:52:59.881 15910-15910/? D/CordovaPurchase: Inside mGotInventoryListener
10-15 11:52:59.881 15910-15910/? D/CordovaPurchase: **Query inventory was successful**.

So my guess is the wrapper probably doesn’t detect the change and doesn’t fire the ready event while it actually does happen. It might be the way the callbacks are wrapped around with promises.

SYSTEM INFO

Node version: v8.4.0
Cordova version: 7.0.1
Config.xml file:
<plugin name=“cc.fovea.cordova.purchase” spec="^7.0.2">


Ionic info:
cli packages: (/.nvm/versions/node/v8.4.0/lib/node_modules)

@ionic/cli-utils  : 1.13.0
ionic (Ionic CLI) : 3.13.0

global packages:

cordova (Cordova CLI) : 7.0.1 

local packages:

@ionic/app-scripts : 3.0.0
Cordova Platforms  : android 6.2.3 ios 4.5.1
Ionic Framework    : ionic-angular 3.7.1
"@ionic-native/in-app-purchase-2": "^4.3.1",

System:

ios-deploy : 1.9.2 
Node       : v8.4.0
npm        : 5.4.2 
OS         : macOS Sierra
Xcode      : Xcode 9.0 Build version 9A235

It seems like this is a known bug:

Created a pull request to fix this issue:

1 Like

Hi,

This is issue is resolved…?
I am also facing same issue…

On android, this.store.products; is giving products but price is coming null.

On Ios, its working fine.

Can you please help me. Thanks in Advance

Can you share your IOS code, my Android works smoothly.
I am stuck here on IOS.