j3k0 / cordova-plugin-purchase

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

Unable to get title, price... on Android #375

Closed CyrilleGuimezanes closed 6 years ago

CyrilleGuimezanes commented 8 years ago

Hello,

In my app, created with Cordova, I would like to do IAP and show prices with local currency.

On the documentation I have:

When you perform the initial refresh() call, the store's server will be contacted to load informations > about the registered products: human readable title and description, price, etc. But when I execute the following code I have the product but the price is set to "null"

And I wrote:

store.verbosity = store.DEBUG;
store.ready(function() {
      store.refresh();
      alert("Object:"+ store.get(PREMIUM_PACK_ID));
      alert("Price:"+ store.get(PREMIUM_PACK_ID).price);
 });
for (var i = 0; i < this.products.length; i++){
      var params = this.products[i];
      store.register({
         id:    params.id,
         alias: params.label,
         type:  params.type || store.CONSUMABLE
      });
}
store.refresh();

Some informations:

Did I miss something?

Regards,

arielfaur commented 8 years ago

Try calling refresh only after registering your products. Does that work?

CyrilleGuimezanes commented 8 years ago

I tried to remove refresh on ready event but no working...

arielfaur commented 8 years ago

Sorry, I re-read your code. You should get the product information from within a store.when callback:

store.when("product").loaded(function(product) {
      console.log(product);
});

store.when("product").updated(function(product) {
      console.log(product);
});

Try adding these two callbacks with the query "product" before calling store.refresh and see if your product is loaded.

CyrilleGuimezanes commented 8 years ago

I wrote this:

store.verbosity = store.DEBUG;
store.ready(function() {
    alert("Ready!");
});
  store.register({
      id:    PREMIUM_PACK1_ID,
      alias: "myalias",
      type:  store.NON_CONSUMABLE
  });

store.when(PREMIUM_PACK1_ID).loaded(function(product) {
      alert("Price1:"+ product.price);
});

store.when(PREMIUM_PACK1_ID).updated(function(product) {
      alert("Price2:"+ product.price);
});

store.refresh();

I get the alert("Ready!"); but I never get any of "loaded" or "updated" event

arielfaur commented 8 years ago

As a last resort you could try:

store.when("product")

or

store.when("myalias")
CyrilleGuimezanes commented 8 years ago

No luck :(

Any idea @j3k0 ?

CyrilleGuimezanes commented 8 years ago

Ok, after some debug I am able to get the product prices but only after a call to 'order(id)' method.

I would like to get prices at ready state to be able to show a button with labels like: "My great object - $5" or "Mon super objet - 5€ " according to the user language...

I'm open to call a method to force the refresh if needed...

CyrilleGuimezanes commented 8 years ago

I reopen because I have new inputs that tells me that there is a trouble on the plugin:

I have now 6 registred products, I bought 2 of them. I get these logs:

STEP1: I register products (These line repeat for each product)

store.queries !! 'bargainadv.pack.premium1 registered'" store.queries !! 'product_0 registered'" store.queries !! 'non consumable registered'" store.queries !! 'registered'" store.queries !! 'bargainadv.pack.premium1 updated'" store.queries !! 'product_0 updated'" store.queries !! 'non consumable updated'" store.queries !! 'updated'"

STEP 2: I register 3 callback foreach product

queries ++ 'bargainadv.pack.premium3 loaded'" queries ++ 'bargainadv.pack.premium3 updated'" queries ++ 'bargainadv.pack.premium3 owned'"

STEP3 : I call refresh method

store.trigger -> triggering action refreshed" queries !! 'refreshed'" refresh -> checking products state (6 products)" refresh -> product id bargainadv.pack.premium3 (product_0)" in state 'registered'"

STEP4: Re-reshesh is called internaly and get product as owned

store.trigger -> triggering action re-refreshed" queries !! 're-refreshed'" android -> product data for bargainadv.pack.building3" {"orderId":"GPA.1324-4427-2340-25831","packageName":"com.luditeam.nego","productId":"bargainadv.pack.building3","purchaseTime":1454099703901,"purchaseState":0,"purchaseToken":"....","receipt":"{\"orderId\":\"...\",\"packageName\":\"com.luditeam.nego\",\"productId\":\"bargainadv.pack.building3\",\"purchaseTime\":1454099703901,\"purchaseState\":0,\"purchaseToken\":\"..."}"}" store.queries !! 'bargainadv.pack.building3 approved'" store.queries !! 'product_0 approved'" store.queries !! 'bargainadv.pack.building3 updated'"

STEP5: I print the events recevied, here, only updated is called and I have no price and owned state is false (I bougth this product)

I/chromium( 7600): [INFO:CONSOLE(18)] "UPDATED: ProductId: bargainadv.pack.building3 price: null Owned:false"

Also, Good to know when I call: store.inappbilling.getAvailableProducts (internal function) I get the two product I owned with the prices.

Any idea?

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.