chirag04 / react-native-in-app-utils

A react-native wrapper for handling in-app payments
MIT License
890 stars 185 forks source link

`purchaseProduct` returns `invalid_product` unless you call `loadProducts` first. #39

Closed joshuapinter closed 8 years ago

joshuapinter commented 8 years ago

You need to call loadProducts first and then call purchaseProduct either at a later time or in the callback for loadProducts.

At the very least the README should reflect this.

But, ideally, purchaseProduct should work without having to call loadProducts first.

Let me know your thoughts on this to make sure we're on the same page before I do a PR.

chirag04 commented 8 years ago

that's just how apple designed their sdk. I don't know if we can do anything here.

joshuapinter commented 8 years ago

@chirag04 Not really, though, right? Can't we just remove that cache you've created involving the products variable and just call the purchase method with the specified product identifier?

Why do we need to load the products as a requirement for purchasing a product?

chirag04 commented 8 years ago

unless i'm mistaken there is no api for purchasing a product directly with a product identifier. you need to make a request to load it first.

loading product first can be useful in cases where you want to show the product price in local currency first.

joshuapinter commented 8 years ago

Okay, I gotcha! Thanks again for all your help and creating this library. I'm well on my way now. :)

joshuapinter commented 8 years ago

Just as a final thought, you could trigger a load of the products when somebody calls the purchaseProduct and just use the product identifier that they supplied.

chirag04 commented 8 years ago

i would rather prefer that to be in the userland. if users want to load products automatically, they just write a wrapper function on top of purchase product that does it for them.

joshuapinter commented 8 years ago

Fair enough man. Well, with the additional README hints, this should help clear things up for others. 👍

dwilt commented 7 years ago

To @joshuapinter 's point, here's what we're doing:

export async function purchase(identifier) {
    await loadProducts(identifier);
    return purchaseProduct(identifier);
}
chirag04 commented 7 years ago

Be careful to check for loadProduct failures.

wilbyang commented 7 years ago

I have created a product with type being 'Non-consumable' and status 'Waiting for review'. I am trying to load the product, with the right indentifier, but the repsonse contains no products and just something like _invalidindentifers staff (get it from debugging windows). Does I mis-understanding some staff. I have been in this trap/trouble for one week.