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

Get list of purchased products #420

Closed gfragioud closed 8 years ago

gfragioud commented 8 years ago

Hello and thank you for this great plugin.

I need help with ownership of products in iOS. Products are being purchased and finished properly. I checked that .owned is true after the finished transaction. I also checked that .owned remains true after kill+reopen the app. All perfect until this point.

The problem occurs when user changes device or reinstalls the app. I sell books inside my app separately and in bundles. So before purchase a book I want to check if user already owns the bundle that contains this book, and if yes cancel the purchase. And the opposite. BUT in this initial state all products seem as not owned.

I don't want to force user to perform a "restore purchases" after app installation, so I am looking a better solution to handle this.

Any suggestion?

AbuHani commented 8 years ago

this will return the product state to OWNED

store.when("product").updated(function(product) {
            if(product.loaded && product.valid && product.state === store.APPROVED) {
               product.finish();
            }
}); 
gfragioud commented 8 years ago

Thanks for your reply but I can't get how this would help.

My products are apple hosted, so I call product.finish() inside when().downloaded(). The state changes to owned as it should but when user reinstalls the app or install it in a new device, all products are valid and not owned.

AbuHani commented 8 years ago

in this case you need to change products state that already purchased from approved to owned in the update query.

AbuHani commented 8 years ago
        var products = ['p0','p1','p2'];
        for (var i = 0; i < products.length; i++) {

            pro = {
                id:    products[i],
                type:  store.NON_CONSUMABLE
            };

            store.register(pro);
        } 

        store.refresh();

        store.when("product").updated(function(product) {
            if(product.loaded && product.valid && product.state === store.APPROVED) {
               product.finish();
            }
        });

        $scope.buy = function(product_id) {

          store.once(product_id).approved(function (product) {

            console.log("You've purchased the content for " + product.id + " - it will now download to your device!");

          });

          store.when(product_id).downloading(function(product) {

          }); 

          store.when(product_id).downloaded(function (product) {

            product.finish();

          });

          store.order(product_id);

 }
gfragioud commented 8 years ago

Thank you for your suggestion but unfortunately it didn't make the magic. After app installation, all products (both purchased & not purchased) are loaded as not owned.

Is there any chance this happens only in debugging mode and not in production?

AbuHani commented 8 years ago

that what i did on android ! . what the product state for purchased products after installation ?

gfragioud commented 8 years ago

All are in state "valid"...

AbuHani commented 8 years ago

and transaction ?

gfragioud commented 8 years ago

What do you mean? There is no transaction. I want to check the ownership of the product before proceed to purchase (order)...

AbuHani commented 8 years ago

the transaction for purchased products should not be null.

AbuHani commented 8 years ago

transactions

gfragioud commented 8 years ago

I just checked it and it is null for all products...

AbuHani commented 8 years ago

hi @gfragioud , could you help me on ios ?

gfragioud commented 8 years ago

Probably... What's your problem exactly?

AbuHani commented 8 years ago

my app got rejected by apple because in app purchase not working.

I have created NON_CONSUMABLE products in iTunes Connect, but when use store.register({id:'p4', store.NON_CONSUMABLE}) and store.get('p4'); all details are null.

should submit the app with in-app purchase products to get products details ? or just create them and do store.register() and store.get() to get detail of product(price, title, ...) ? .

AbuHani commented 8 years ago

all invalid ! {"id":"p11","alias":"p11","type":"non consumable","state":"invalid","title":null,"description":null,"price":null,"currency":null,"loaded":true,"canPurchase":false,"owned":false,"downloading":false,"downloaded":false,"transaction":null,"valid":false}

AbuHani commented 8 years ago

Does it matter if the "In-App Purchase" hasn't been submitted for review? Does it have to be accepted even during the testing stage?

ghost commented 8 years ago

Apparently the IAP only has to be entered into iTunes Connect and afterwards the testing API from Apple is supposed to return the proper data to this plugin (there used to be a 24 hour delay or something) but I have not been able to get a product to return a "ready for purchase" or whatever the status it has to be in for this plugin to work. There are no actual working examples that I can find of this plugin.

j3k0 commented 8 years ago

@AbuHani @Createstandard Thousands of apps use this plugin successfully, be assured that it does work on iOS.

Here's a partial checklist:

j3k0 commented 8 years ago

https://github.com/j3k0/cordova-plugin-purchase/wiki/F.A.Q.#products-wont-load-invalid-product-id

AbuHani commented 8 years ago

@j3k0 Thank you, the problem was no Paid Apps contract in effect.