Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

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

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...