<commit_before>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var exec = require('cordova/exec'),
    iab = require('com.smartmobilesoftware.inappbilling.InAppBillingPlugin'),
    billingAvailable;

exports.inapp = {
    getSkuDetails: function(skus, success, failure) {
        if (!(skus instanceof Array)) {
            skus = [skus];
        }
        iab.getProductDetails(success, failure, skus);
    },

    getPurchases: function(success, failure) {
        iab.getPurchases(success, failure);
    },

    buy: function(options) {
        var success = function(productId) {
                var result = {
                };
                options.success(result);
            },
            failure = function(err) {
                var result = {
                    response: {
                        errorType: "INTERNAL_SERVER_ERROR"
                    }
                };
                options.failure(result);
            };
        if ('sku' in options) {
            iab.buy(success, failure, options.sku);
        }
    }
};

iab.init(function() {
    console.log("Billing initialized");
    billingAvailable = true;
}, function() {
    console.log("Error initializing billing");
    billingAvailable = false;
}, {showLog: true});
<commit_msg>Add more API to payments plugin; still using InAppBilling as a dependency<commit_after>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var exec = require('cordova/exec'),
    iab = require('com.smartmobilesoftware.inappbilling.InAppBillingPlugin'),
    Event = require('org.chromium.common.events'),
    billingAvailable;

exports.onBillingAvailable = new Event('onBillingAvailable');
exports.onBillingUnavailable = new Event('onBillingUnavailable');
exports.billingAvailable = false;
exports.inapp = {
    getSkuDetails: function(skus, success, failure) {
        if (!(skus instanceof Array)) {
            skus = [skus];
        }
        iab.getProductDetails(success, failure, skus);
    },

    getPurchases: function(success, failure) {
        iab.getPurchases(success, failure);
    },

    getAvailableProducts: function(success, failure) {
        iab.getAvailableProducts(success, failure);
    },

    buy: function(options) {
        var purchaseSuccess = function(purchaseDetails) {
                var result = {
                    request: {},
                    response: {
                        orderId: purchaseDetails.orderId
                    }
                };
                options.success(result);
            },
            purchaseConsumableSuccess = function(purchaseDetails) {
                    //iab.consumePurchase(purchaseSuccess, failure, purchaseDetails.purchaseToken);
                    iab.consumePurchase(purchaseSuccess, failure, purchaseDetails.sku);
            };

            failure = function(err) {
                var errorType = "INTERNAL_SERVER_ERROR";
                if (err.code === 7) {
                    errorType = "ITEM_ALREADY_OWNED";
                }
                if (err.code === -1005) {
                    errorType = "PURCHASE_CANCELLED";
                }
                var result = {
                    response: {
                        errorType: errorType
                    }
                };
                options.failure(result);
            };
        if ('sku' in options) {
            if (options.consume) {
                iab.buy(purchaseConsumableSuccess, failure, options.sku);
            } else {
                iab.buy(purchaseSuccess, failure, options.sku);
            }
        }
    }
};

iab.init(function() {
    console.log("Billing initialized");
    exports.billingAvailable = true;
    exports.onBillingAvailable.fire();
}, function() {
    console.log("Error initializing billing");
    exports.billingAvailable = false;
    exports.onBillingUnavailable.fire();
}, {showLog: true});

{'fraction_non_alphanumeric': 0.10711683264512994, 'fraction_numerical': 0.003157639057566189, 'mean_word_length': 1.8857743517869656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5321287', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1066, 'n_words': 239}