j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 535 forks source link

Not see products #558

Closed THE-KIPDEV closed 7 years ago

THE-KIPDEV commented 7 years ago

Hi,

I have a problem with the plugin, impossible to show products : ` IAP.JS var IAP = { list: [ 'produit_138' ], products: {} }; var localStorage = window.localStorage || {};

IAP.initialize = function () {
    // Check availability of the store plugin
    if (!window.store) {
        alert('In-App Purchases not available');
        return;
    }

    // Initialize
    store.init({
        debug:    true,
        noAutoFinish: true,
        ready:    IAP.onReady,
        purchase: IAP.onPurchase,
        finish:   IAP.onFinish,
        restore:  IAP.onRestore,
        error:    IAP.onError,
        restoreCompleted: IAP.onRestoreCompleted
    });
};

IAP.onReady = function () {
    // Once setup is done, load all product data.
    store.load(IAP.list, function (products, invalidIds) {
        alert('IAPs loading done:');
        for (var j = 0; j < products.length; ++j) {
            var p = products[j];
            alert('Loaded IAP(' + j + '). title:' + p.title +
                        ' description:' + p.description +
                        ' price:' + p.price +
                        ' id:' + p.id);
            IAP.products[p.id] = p;
        }
        IAP.loaded = true;
        for (var i = 0; i < invalidIds.length; ++i) {
            alert('Error: could not load ' + invalidIds[i]);
        }
        IAP.render();
    });

    // Also check the receipts
    // store.loadReceipts(function (receipts) {
    //     alert('appStoreReceipt: ' + receipts.appStoreReceipt);
    // });
};

IAP.onPurchase = function (transactionId, productId) {
    var n = (localStorage['store.' + productId]|0) + 1;
    localStorage['store.' + productId] = n;
    if (IAP.purchaseCallback) {
        IAP.purchaseCallback(productId);
        delete IAP.purchaseCallbackl;
    }

    store.finish(transactionId);

    store.loadReceipts(function (receipts) {
        alert('Receipt for appStore = ' + receipts.appStoreReceipt);
        alert('Receipt for ' + productId + ' = ' + receipts.forProduct(productId));
    });
};

IAP.onFinish = function (transactionId, productId) {
    alert('Finished transaction for ' + productId + ' : ' + transactionId);
};

IAP.onError = function (errorCode, errorMessage) {
    alert('Error: ' + errorMessage);
};

IAP.onRestore = function (transactionId, productId) {
    alert("Restored: " + productId);
    var n = (localStorage['store.' + productId]|0) + 1;
    localStorage['store.' + productId] = n;
};

IAP.onRestoreCompleted = function () {
    alert("Restore Completed");
};

IAP.buy = function (productId, callback) {
    IAP.purchaseCallback = callback;
    store.purchase(productId);
};

IAP.restore = function () {
    store.restore();
};

IAP.fullVersion = function () {
    return localStorage['store.produit_138'];
};`

ON MY INDEX.JS

`var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicity call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready');

    IAP.initialize();
    IAP.render = function () {
        var el = document.getElementById('in-app-purchase-list');
        if (IAP.loaded) {
            var html = "<ul>";
            alert(IAP.list);
            alert(IAP.products);
            var index = 0;
            var buttonStyle = "display:inline-block; padding: 5px 20px; border: 1px solid black";
            for (var id in IAP.products) {
                var p = IAP.products[id];
                html += "<li>" +
                    "<h3>" + p.title + "</h3>" +
                    "<p>" + p.description + "</p>" +
                    "<div style='" + buttonStyle + "' id='buy-" + index + "' productId='" + p.id + "' type='button'>" + p.price + "</div>" +
                    "</li>";
                ++index;
            }
            html += "</ul>";
            html += "<div style='" + buttonStyle + "' id='restore'>RESTORE ALL</div>"
            el.innerHTML = html;
            while (index > 0) {
                --index;
                document.getElementById("buy-" + index).onclick = function (event) {
                    var pid = this.getAttribute("productId");
                    IAP.buy(pid);
                };
            }
            document.getElementById("restore").onclick = function (event) {
                IAP.restore();
            };
        }
        else {
            el.innerHTML = "In-App Purchases not available";
        }
    };
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    alert('Received Event: ' + id);
}

};` and in my index.html

<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <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" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
</head>
<body>
    <br />
    <br />
    <div class="app">

        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
        <div id="in-app-purchase-list">
            Loading IAP...
        </div>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/iap.js"></script>
    <script type="text/javascript" src="js/index.js"></script>

    <script type="text/javascript">
        app.initialize();
    </script>
</body>

On Play Console i have create a product with the id "product_138"

Any one have a solution ?

Dexus commented 7 years ago

Please review your code self. We are have no time for reviewing customers codebase of implementing.