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

[IOS] ISSUE - CONSUMABLE SHOWING AS NON-CONSUMABLE #661

Closed sturrock closed 6 years ago

sturrock commented 6 years ago

system info

I've tried every combination to get it working, it was working at one point but has randomly stopped again and i cant get it going after 10+ hours of changing version numbers on all plugins and PGB version.

Expected behavior

It should simply allow you to purchase a product over and over

Observed behavior

It only allows you to purchase the product once because it thinks its a non-consumable when its actually a consumable

Steps to reproduce

Im using PGB, I've set the pgb-builder-version preference to 1 so it builds on their old engine (i've tried both). I've tried every single version of phonegap, your plugin, and all the other plugins im using and cant get it to go away now. So should be easy to reproduce.

Click to buy an IAP, and on the second time you try it will say you already own it and it will restore.

Config/Plugins

    <plugin name="cordova-plugin-code-push" source="npm"/>
    <plugin name="cc.fovea.cordova.purchase" source="npm" spec="7.0.2" version="7.0.2" />
    <plugin name="phonegap-plugin-push" source="npm" spec="2.0.0" />
    <plugin name="cordova-plugin-appinfo" source="npm" version="2.1.2" /> 
    <plugin name="cordova-plugin-console" source="npm" version="1.1.0" />
    <plugin name="cordova-plugin-device" source="npm" />
    <plugin name="cordova-plugin-device-orientation" source="npm" version="1.0.7" />
    <plugin name="cordova-plugin-dialogs" source="npm"/>
    <plugin name="cordova-plugin-inappbrowser" source="npm" version="1.7.2" />
    <plugin name="cordova-plugin-keyboard" source="npm" version="1.1.5" />
    <plugin name="cordova-plugin-network-information" source="npm"/>
    <plugin name="cordova-plugin-splashscreen" source="npm" version="4.1.0" />
    <plugin name="cordova-plugin-statusbar" source="npm" version="2.3.0" />
    <plugin name="cordova-plugin-whitelist" source="npm" version="1.3.3" />
    <plugin name="cordova-launch-review" source="npm" version="2.0.2" />
    <plugin name="cordova-plugin-admobpro" source="npm" version="2.29.27" />
sturrock commented 6 years ago

I've tried using the cli and still has the same issue, the problem has to be an updated apple code library because its happening with every IAP plugin for cordova.

Can someone help, this is pretty urgent as my app is losing thousands per day. I'm willing to donate/pay for time on this.

Dexus commented 6 years ago

Can you provide please your code of the integration? I think you have done it wrong.

If you need urgent help, mail me on my mail that is public.

Regards

Von meinem iPhone gesendet

Am 09.01.2018 um 02:09 schrieb sturrock notifications@github.com:

I've tried using the cli and still has the same issue, the problem has to be an updated apple code library because its happening with every IAP plugin for cordova.

Can someone help, this is pretty urgent as my app is losing thousands per day. I'm willing to donate/pay for time on this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

sturrock commented 6 years ago

I've been using this plugin for years now and have never had a problem, i done a rebuild two weeks ago which broke it, and didn't realize. Now its in the production app...

I've made a sample project using the similar code, which still doesn't work. I know this is the old way of doing it, but even the new way has the same problem.

CONFIG

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.swipa" version="1.2.6" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">

    <name>Test</name>

    <description>
        Get more likes on your photos.
    </description>

    <author email="admin@pswipa.me" href="https://swipa.me">
        App Studios
    </author>

    <preference name="phonegap-version" value="cli-7.0.1" />
    <preference name='pgb-builder-version' value='1' />

    <platform name="ios">
        <plugin name="cc.fovea.cordova.purchase" />
    </platform>s

</widget>

HTML/JS

<!doctype html>
<html>
<head>

    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />

    <meta charset="utf-8">
    <title>Test</title>

</head>
<body>

    <div style="padding: 20px; background: #ccc;" onclick="buy()">Buy Coins</div>

    <script type="text/javascript" src="cordova.js"></script>

    <script>
        document.addEventListener("deviceready", function(){

            window.storekit.init({

                debug: true, 

                purchase: function (transactionId, productId, receipt) {

                    window.storekit.loadReceipts(function (receipts) {

                        var receiptId = receipts.forTransaction(transactionId);
                        alert(productId+' Purchase');

                    });
                },
                restore: function (transactionId, productId) {
                    console.log('restored: ' + productId);
                    alert('restored: ' + productId);
                },
                restoreCompleted: function () {
                   console.log('all restore complete');
                   alert('all restore complete');
                },
                restoreFailed: function (errCode) {

                    alert('Code: '+errCode);

                },
                error: function (errno, errtext) {

                    alert('Error: '+errtext);

                },
                ready: function () {

                    var productIds = [
                        "com.swipa.coins.100"
                    ];

                    window.storekit.load(productIds, function(validProducts, invalidProductIds) {
                        alert(JSON.stringify(validProducts));
                    });
                }
            });

        }, false);

        function buy(){
            alert('Buy');
            storekit.purchase('com.swipa.coins.100');

        }

    </script>

</body>
</html>
sturrock commented 6 years ago

These are consumable products, but they're all showing as non-consumable.

26655013_10204046814526829_872357484_o 26544046_10204046814646832_1364345655_o

j3k0 commented 6 years ago

Hi,

You are using the long deprecated API for this plugin (I think it was deprecated around 3-4 years ago). It's not maintained anymore, so you have to update your code to the new API.

sturrock commented 6 years ago

I've tried the new code and it has the same problem, I've just left this code cause it was working 2 weeks again perfectly fine. You have to purchase the product twice, then on the third time it start showing the restore popup.

j3k0 commented 6 years ago

The new code requires you to register the product as a "consumable" explicitly, are you sure you did that? It could explain your problem.

j3k0 commented 6 years ago

It would be better if you share the actual code you are using. No need to share code using the deprecated API, it's not maintained and should not be considered functional anymore.

sturrock commented 6 years ago

Soon as i include the plugin in the config file, and run the project without calling in the JS, the restore dialog still pops up. I've been changing versions and plugins for 5 days now. I've tried the new code and set it as consumable and it still happens.

I use this code to register

store.register({
        id:    'com.swipa.coins.100',
        alias: '100 Coins',
        type:   store.CONSUMABLE
    });
j3k0 commented 6 years ago

The restore dialog means you have pending unfinished transactions on your device. Make you call finish() for all approved transactions... or check this: https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#random-tips

sturrock commented 6 years ago

Okay, I've updated the code, set store.autoFinishTransactions to true and its still doing the same thing.

<!doctype html>
<html>
<head>

    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />

    <meta charset="utf-8">
    <title>Test</title>

</head>
<body>

    <div style="padding: 20px; background: #ccc;" onclick="buy()">Buy Coins</div>

    <script type="text/javascript" src="cordova.js"></script>

    <script>
        document.addEventListener("deviceready", function(){

            store.autoFinishTransactions = true;

            store.register({
                id:    'com.swipa.coins.100',
                alias: '100 Coins',
                type:   store.CONSUMABLE
            });

            store.error(function(error) {
                alert('ERROR ' + error.code + ': ' + error.message);
            });

            store.when("product").updated(function (p) {
                //alert(JSON.stringify(p));
            });

            store.when("100 Coins").approved(function (order) {
                alert('100 Coins Purchased');
                order.finish();
            });

            store.ready(function() {
                alert('Ready to purchase');
            });

            store.refresh();

        }, false);

        function buy(){
            alert('Buy');
            store.order('com.swipa.coins.100');
        }

    </script>

</body>
</html>
sturrock commented 6 years ago

When you open the app it runs this code automatically

store.when("100 Coins").approved(function (order) {
        alert('100 Coins Purchased');
        order.finish();
});
sturrock commented 6 years ago

I think it could be the connection to the app store, sometimes its randomly working, and other times it doesn't :\ and im getting the error Error 6777010: Cannot connect to iTunes Store now.

Also what will happen if i leave the store.autoFinishTransactions set to true in the production app?

Dexus commented 6 years ago

Your app will be hacked and rejected from store

Von meinem iPhone gesendet

Am 09.01.2018 um 14:09 schrieb sturrock notifications@github.com:

I think it could be the connection to the app store, sometimes its randomly working, and other times it doesn't :\ and im getting the error Error 6777010: Cannot connect to iTunes Store now.

Also what will happen if i leave the store.autoFinishTransactions set to true in the production app?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

sturrock commented 6 years ago

Okay i think I've found the problem, soon as the "Sign-In required to Enable Touch ID" dialog pops up and you enter the password, that's when it stops working. If you just click cancel it continues working.

sturrock commented 6 years ago

So I've been testing it more because it randomly stopped again. It looks like when i have store.autoFinishTransactions = true it works, soon as i get rid of that, it stops. I think the order.finish(); isn't working.

Dexus commented 6 years ago

I would say it may also a security/fraud prevention maybe from apples side. AutoFinishTransaction is no production option!!!!!

Have now also checked one of my apps, and I become some results that let me think it's the anti fraud system that stops the "fast consume" of just buyed items. Please read also the Docs and ToS of Apple / Apple Developer.

2018-01-10 0:11 GMT+01:00 sturrock notifications@github.com:

So I've been testing it more because it randomly stopped again. It looks like when i have store.autoFinishTransactions = true it works, soon as i get rid of that, it stops. I think the order.finish(); isn't working.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/j3k0/cordova-plugin-purchase/issues/661#issuecomment-356444838, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmMMeT-QqvKOQP_WLkVzAK-jiedeDImks5tI_IxgaJpZM4RVdsb .