cozycodegh / cordova-plugin-inapppurchases

2023-2024 cordova plugin to add in-app purchases and subscriptions into an iOS or Android app
MIT License
9 stars 4 forks source link

Consumable product does not finish #9

Closed Mercadomapsmm closed 11 months ago

Mercadomapsmm commented 11 months ago

Greetings. Could you help me with the problem I'm facing? I am unable to consume the product, so it is not available for new purchase. Here's the code:

                function buyPaidContent() {

                    var product_id_1 = localStorage.getItem("product_id_1");

                    inAppPurchases.purchase(product_id_1).then(function (purchase) {
                        if (purchase["pending"]) {
                            //            alert("waiting for payment to complete");
                            return; //not paid for yet
                        }

                        var creditos_app = localStorage.getItem("creditos_app");
                        creditos_app = parseInt(creditos_app)
                        var product_id_1 = localStorage.getItem("product_id_1");

                        return inAppPurchases.completePurchase(product_id_1);

                    }).then(function (purchase) {
                        app.views.main.router.navigate('/home/');
                    }).catch(function (err) {
                        alert("Assinatura não efetuada");
                        alert(JSON.stringify(err));
                        logError(err);
                    });

Thank you friends

cozycodegh commented 11 months ago

Hello, Was there any error message? Or was the purchase still pending and never ran the completePurchase function?

Mercadomapsmm commented 11 months ago

Hi, thanks for the plugin and response. It didn't generate an error message, I believe the purchase was not pending. Did not execute the complete. When I run it according to the examples, it works perfectly for subscriptions and non-consumable products. The problem is for a consumable product. Do not consume the product, freeing it for the next purchase. Thus, in the test environment, the purchase is returned by automatic cancellation with the following message on the receipt: "The test purchase was canceled because there was no confirmation. All purchases must be confirmed so they are not subject to to refunds." I don't know if I'm correctly executing the commands to consume the product.

cozycodegh commented 11 months ago

I see one problem, Android doesn’t specify if it is consumable in the play store, so it can become non-consumable by accident if the function is called: inAppPurchases.completePurchase(product_id_1)

To make it a consumable that you can buy again, call inAppPurchases.completePurchase(product_id_1,true) to consume it.

The completePurchase should be running from your code, but check if it was pending if this doesn’t fix it.

Mercadomapsmm commented 11 months ago

Right. I will adjust the code and upload it for testing. When I run it, I'll let you know if it's done correctly. Thank you very much!

Mercadomapsmm commented 11 months ago

Hello, I adjusted the code in the test environment and it worked perfectly. I also adjusted it in production, but Google is taking a while to upload the application. As soon as it goes into production I will let you know. I believe it will work too. Just to confirm. Thank you very much!!! Very efficient plugin.

cozycodegh commented 11 months ago

Super! No problem