j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

Store.products is empty array after initialize #1547

Closed TerrorCards closed 1 month ago

TerrorCards commented 1 month ago

Observed behavior

Installed version 13

"cordova-plugin-purchase": "^13.10.0",

Ran npx cap sync as well.

Imported into the app file

import "cordova-plugin-purchase";

Code in called in the component Did Mount of react app

  componentDidMount() {
    this.pullPacks();
    setTimeout(() => {
      this.pullInApp();
    }, 2000);
  }

Tried to use

    document.addEventListener(
      "deviceready",
      () => {
        this.pullInApp();
      },
      false
    );

But the call back in react doesn't ever seem to be called.

Function pulls listed of coins available, and then registers the product for them. Store.registeredProducts shows the items, but Store.Products is an empty array.

  pullInApp = () => {
    callServer("loadInAppItems", "", this.props.user.ID)
      ?.then((resp) => {
        return resp.json();
      })
      .then((json) => {
        if (json.length > 0) {
          const { store, ProductType, Platform } = CdvPurchase;
          const items = json;
          const productList: any[] = [];
          items.forEach((item: any) => {
            productList.push({
              id: item.ID,
              platform: Platform.TEST,
              type: ProductType.CONSUMABLE,
            });
          });
          store.register(productList);
          store
            .when()
            .approved((p: any) => p.verify())
            .verified((p: any) => {
              //do something
              p.finish();
            });
          store.initialize([Platform.TEST]).then(() => {
            store.ready(() => {
              store.update().then(() => {
                //alert(store.registeredProducts);
                alert(store.products);
              });
            });
          });
        }
      })
      .catch((err: any) => {
        console.log(err);
      });
  };

registeredProducts has the items Screen Shot 2024-03-13 at 10 29 41 AM

Products is empty Screen Shot 2024-03-13 at 10 29 49 AM

Include logs with CdvPurchase.store.verbosity = CdvPurchase.LogLevel.DEBUG

Expected behavior

Use to work when I installed awesome plugin, but when the appstores request an update to the billing apk, I upgraded to 13 and made the changes, now the store no longer works.

System Info

Output of cordova info.

TerrorCards commented 1 month ago

Also tried this import

import "cordova-plugin-purchase/www/store";

and calling CdvPurchase from window

const { store, ProductType, Platform } = window.CdvPurchase;

Same thing, store.products is an empty array.

j3k0 commented 1 month ago
          store.initialize([Platform.TEST]).then(() => {
            store.ready(() => {
              store.update().then(() => {

1st remark, calling "update" right after "initialize" is a mistake, the initial "update" is done by initialize (among other things).

Then, you error is that the "TEST" platform only accepts a set of predefined product IDs. Cf https://github.com/j3k0/cordova-plugin-purchase/wiki/v13-reference:-Test-Adapter

If you want to use an Apple or Android product, defined them on the store an initialize the appropriate platform.

mvaljento commented 1 month ago

For me the ready callback is never called and now products found. Running on Android emulator and I have logged into the Google Play Store.