PeterStaev / nativescript-purchase

:moneybag: A NativeScript plugin for making in-app purchases!
Apache License 2.0
83 stars 28 forks source link

Products list is empty #98

Closed vahidvdn closed 4 years ago

vahidvdn commented 4 years ago

Hi. I have the following implementation. But the products list is empty. (I've submitted my app as a beta release at Google Play and added a product id)

main.ts

...
platformNativeScriptDynamic().bootstrapModule(AppModule);
purchase.init(['prod_purchase']);

items.componet.ts

purchase.getProducts().then((products: Array<Product>) => {
    // result: []
    alert("Products: "+ JSON.stringify(products));
}

Any idea?

PeterStaev commented 4 years ago

Hey @vahidvdn , from what I see from your code you are not waiting for the plugin to be initialized. Per the Usage it is recommended (if not required) you surround your getProducts with the wait for the init promise. Also for NG, I'm not sure if in the main.ts isn't a bit early in the lifecycle. You can as well try to call init in your AppComponent instead.

vahidvdn commented 4 years ago

@PeterStaev I use getProducts in a button click event. But I will try what you mentioned to see if it's working or not. Thanks.

vahidvdn commented 4 years ago

@PeterStaev I tested it but still the same problem. (I'm not sure that I can run the project from the cli or I should submit a new version in Google Play. Can I just run the app or I should build a production version and submit it in Google Play?)

vahidvdn commented 4 years ago

There was a problem with Google Play console. It's working now. Thanks.