Chrome extension in app purchase always returns PURCHASE_CANCELED, even if the purchase worked

谁说我不能喝 提交于 2019-12-18 08:25:23

问题


This question is related to the one at Chrome Webstore Extension In App Purchase INTERNAL_SERVER_ERROR. I first posted my question there in the form of a comment, but received feedback that this was more appropriate as a separate question.

Like the OP, I am using buy.js and following the recommended workflow for in-app purchases in the Chrome extension. But my results are somewhat different: when I complete the IAP buy dialog, I get back a PURCHASE_CANCELED, even though I bought the IAP. If I then list the purchases SKUs through the api, it shows up as having been purchased and active. I also get a receipt from the Chrome store.

Does anyone know how to do the IAP buy and get an accurate status message back?

I put together a test extension, and marked it as free with a in-app purchase of "sku1". Here's the relevant code. The entire extension is up at https://github.com/so-codemonkey/testIAP/tree/master.

var testiap = (function() {
  return {
    onload: function () {

        var logResults = function( results ) {
                var str = 'Result: ' + JSON.stringify(results);
                console.log(str);
                $('<p>' + str + '</p>').appendTo('#log');
        };

        $(document).on("click","#getskus", function() {
                var str = "getting skus";
                console.log(str);
                $('<p>' + str + '</p>').appendTo('#log');
                google.payments.inapp.getSkuDetails({
                                'parameters': {'env': 'prod'},
                                'success': logResults,
                                'failure': logResults
                                });
        });

        $(document).on("click","#buysku1", function() {
                var str = "buying sku1";
                console.log(str);
                $('<p>' + str + '</p>').appendTo('#log');
                google.payments.inapp.buy({
                                'parameters': {'env': 'prod'},
                                'sku': 'sku1',
                                'success': logResults,
                                'failure': logResults
                                });
        });             

        $(document).on("click","#getpurchases", function() {
                var str = "getting purchased skus";
                console.log(str);
                $('<p>' + str + '</p>').appendTo('#log');
                google.payments.inapp.getPurchases({
                                'parameters': {'env': 'prod'},
                                'success': logResults,
                                'failure': logResults
                                });
        });

        $(document).on("click","#consumesku1", function() {
                var str = "consuming sku1";
                console.log(str);
                $('<p>' + str + '</p>').appendTo('#log');
                google.payments.inapp.consumePurchase({
                                'parameters': {'env': 'prod'},
                                'sku': 'sku1',
                                'success': logResults,
                                'failure': logResults
                                });
        });             

   }
  }
})();
window.onload = testiap.onload;

TIA!

来源:https://stackoverflow.com/questions/37667802/chrome-extension-in-app-purchase-always-returns-purchase-canceled-even-if-the-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!