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

Approved and product.id #192

Closed chrisschaub closed 5 years ago

chrisschaub commented 9 years ago

So, it looks like when the product moves to APPROVED, the product id is no longer intact, it becomes 'application data' -- but from the doc, it seems that the info is stored in product.transaction.product_id ? But that field of transaction does not exist. The purchase is going through, it's a restore. One other question, should I just use a global "when" to catch updates and switch on status? Or should I use "once" since I'm selling NON_CONSUMABLE?

butlimous commented 9 years ago

What do you get when you log "product"? not product.transaction . In my case the product ID and everything is intact but the receipt is missing so I can't verify that authenticity of the purchase

chrisschaub commented 9 years ago

My product is very funky -- all the data is wiped. The product id is swapped for "application data". I'm trying to figure out if it's because i'm using WHEN with NON_CONSUMABLE.

On Mon, May 18, 2015 at 6:13 PM, butlimous notifications@github.com wrote:

What do you get when you log "product"? not product.transaction . In my case the product ID and everything is intact but the receipt is missing so I can't verify that authenticity of the purchase

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103249418 .

Christopher Schaub http://chris.schaub.com

butlimous commented 9 years ago

No I'm using "when" with nonconsumable and it's not a problem

chrisschaub commented 9 years ago

Do you wait to call store.refresh() untill all products are registered?

On Mon, May 18, 2015 at 6:19 PM, butlimous notifications@github.com wrote:

No I'm using "when" with nonconsumable and it's not a problem

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103254743 .

Christopher Schaub http://chris.schaub.com

butlimous commented 9 years ago

Yes the correct sequence is like this:

store.register({id: 'first', type: store.xxxx}); store.register({id: 'second', type: store.xxxx}); store.refresh();

store.when('first', 'updated', function(product) { }); store.when('second', 'updated', function(product) { });

This is the sequence I'm using and It works well.

butlimous commented 9 years ago

Are you sure you have setup the WHOLE environment in iOS correctly? It's more tricky than that of Android.

chrisschaub commented 9 years ago

I think so. If I've registered products and have a store ready, should I re-register and declare when's every time the page is drawn? It's an app, so the store object is just around. Wondering if store.off on leaving the view is a good idea since it's an angular / ionic app.

On Mon, May 18, 2015 at 7:12 PM, butlimous notifications@github.com wrote:

Are you sure you have setup the WHOLE environment in iOS correctly? It's more tricky than that of Android.

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103277325 .

Christopher Schaub http://chris.schaub.com

butlimous commented 9 years ago

Is the state of the product(s) valid or invalid?

chrisschaub commented 9 years ago

Valid.

On Mon, May 18, 2015 at 8:19 PM, butlimous notifications@github.com wrote:

Is the state of the product(s) valid or invalid?

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103291980 .

Christopher Schaub http://chris.schaub.com

butlimous commented 9 years ago

In this case I don't really know what's wrong...As long as the product is valid and the confirm purchase is showing the correct price, the approve state should also show the same info. May it's a bug in ionic as I use phonegap

chrisschaub commented 9 years ago

Thanks, I got it working much better by messing with bundle ids. Is it calling store.finish() that moves it from APPROVED back to VALID?

On Tue, May 19, 2015 at 5:48 AM, butlimous notifications@github.com wrote:

In this case I don't really know what's wrong...As long as the product is valid and the confirm purchase is showing the correct price, the approve state should also show the same info. May it's a bug in ionic as I use phonegap

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103434828 .

Christopher Schaub http://chris.schaub.com

chrisschaub commented 9 years ago

sorry, calling product.finish()

On Tue, May 19, 2015 at 5:55 AM, Christopher Schaub chris@schaub.com wrote:

Thanks, I got it working much better by messing with bundle ids. Is it calling store.finish() that moves it from APPROVED back to VALID?

On Tue, May 19, 2015 at 5:48 AM, butlimous notifications@github.com wrote:

In this case I don't really know what's wrong...As long as the product is valid and the confirm purchase is showing the correct price, the approve state should also show the same info. May it's a bug in ionic as I use phonegap

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103434828 .

Christopher Schaub http://chris.schaub.com

Christopher Schaub http://chris.schaub.com

chrisschaub commented 9 years ago

So maybe it's this. On Android, do I need to use MANAGED instead of NON_CONSUMABLE for type?

On Tue, May 19, 2015 at 5:56 AM, Christopher Schaub chris@schaub.com wrote:

sorry, calling product.finish()

On Tue, May 19, 2015 at 5:55 AM, Christopher Schaub chris@schaub.com wrote:

Thanks, I got it working much better by messing with bundle ids. Is it calling store.finish() that moves it from APPROVED back to VALID?

On Tue, May 19, 2015 at 5:48 AM, butlimous notifications@github.com wrote:

In this case I don't really know what's wrong...As long as the product is valid and the confirm purchase is showing the correct price, the approve state should also show the same info. May it's a bug in ionic as I use phonegap

— Reply to this email directly or view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/192#issuecomment-103434828 .

Christopher Schaub http://chris.schaub.com

Christopher Schaub http://chris.schaub.com

Christopher Schaub http://chris.schaub.com

butlimous commented 9 years ago

No when creating a product in your Google Play developer account, always shows managed, whether It's consumable or not. Then in your code, write it as usual either CONSUMABLE or NON_CONSUMABLE

chrisschaub commented 9 years ago

It's weird, iOS is working fine for the most part. But I can't get products in google to register as valid. I have the same bundle id's, BILLING_ID set during plugin install, store object because register works. But products just stay invalid on android. Is there anything special to registering android product I might be missing? My app is in "alpha" and the build is for release, not debug. I've also made sure the uploaded APK matches the one I'm testing with. Any suggestions are apprciated, and thanks for the previous help as well!

butlimous commented 9 years ago

Have you published the app? Remember that the app MUST be published to test the purchase. You can publish the alpha version so that It's not available to public

chrisschaub commented 8 years ago

Ok, I've got the plugin working much more smoothly now with my app. But, on ios, sometimes after logging in, I get an approved product with a very strange product id, the id is "application data". And it's weird because the product is somehow registered, valid and then approved -- but I'm not passing any product with that id. So, this reply directly relates to my initial comment. Is it possible that the plugin is somethow adding a pseudo product via a bug into store.products?

RouR commented 8 years ago

How to publish publish the alpha version? I uploaded app, turn-on TestFligh, add tester acc, open in device app via TestFligh. I got:

{"id":"application data","alias":"application data","type":"non consumable","state":"approved","title":null,"description":null,"price":null,"currency":null,"loaded":true,"canPurchase":false,"owned":false,"transaction":{"type":"ios-appstore"},"valid":true}

I think follow is mistakes:

MauriceButler commented 8 years ago

Was there ever a resolution to the "application data" id issue?

I am having the same problem.

gsfioravanti commented 8 years ago

Is there any update to this issue? I'm also getting this.

vinceoralim commented 8 years ago

I'm experiencing the same issue. Details:

This is not a big issue, I end up to prevent further .refresh() calls on iOS.

alexdrel commented 8 years ago

+1 I am getting "application data" non consumable of second refresh.

acoard commented 8 years ago

I'm also suffering from this problem. I believe it's because of this code:

https://github.com/j3k0/cordova-plugin-purchase/blob/b9ab6a7a4e7354b9302f1f4fe7ca20acaea07a0e/www/store-ios.js#L1360-L1368

Here's the relevant bit:

if (data) {
    var p = data.bundleIdentifier ? store.get(data.bundleIdentifier) : null;
    if (!p) {
        p = new store.Product({
            id: data.bundleIdentifier || "application data",
            alias: "application data",
            type: store.NON_CONSUMABLE
        });
        store.register(p);
    }
    p.version = data.bundleShortVersion;
    p.transaction = {
        type: "ios-appstore",
        appStoreReceipt: data.appStoreReceipt,
        signature: data.signature
    };
    p.trigger("loaded");
    p.set("state", store.APPROVED);
}

Basically it says, 'if we can't get the bundleIdentifier' (presumably the IAP's name), then create a new one with "application data" as the id, and then register it.

This callback is in the storekit re-refresh event, which is called everytime that refresh() is called. So, that explains why it's adding a new one each time.

edit: In case anyone is wondering, at this time data is a string around ~6,000 characters long. I believe it's base64 encoded, but I'm not positive.

milhad commented 8 years ago

I'm having the same issue. On the first run, everything runs OK, but on subsequent runs a lot of "fake" products with id "application data" are getting generated and being pushed into the purchase flow because their state is forced to "approved". This is causing the validator to run, posting the imaginary transaction to my API for validation, which obviously fails.

I will try to circumvent this by checking for "fake" ids in "approved" event handler, but it is still unknown to me as why it happens in the first place.

acoard commented 8 years ago

@milhad I just wanted to help point you in the right direction

I will try to circumvent this by checking for "fake" ids in "approved" event handler, but it is still unknown to me as why it happens in the first place.

I tried this, but wound up having lots of trouble.

Instead what worked for me was writing my event handlers like so:

store.when(SINGLE_REPORT).approved(handleSingleReportApproved);

Essentially, always use store.when("INDIVIDUAL_PRODUCT"). Do NOT get all products. You'll just have to filter them and wind up with headaches. At least that's what happened in my case.

Best of luck!

isayeter commented 8 years ago

any update ? the same issue here. why plugin registering a new item as @acoard wrote ?

xgat commented 7 years ago

Hi, it seems the workaround from @acoard is working for me: for each product register callbacks with store.when(<single product id>), do not register callbacks with store.when("product").

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.