text: /*!
   * @overview es6-promise - a tiny implementation of Promises/A+.
   * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
   * @license   Licensed under MIT license
   *            See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
   * @version   4.0.5
   */
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ES6Promise=e()}(this,function(){"use strict";function t(t){return"function"==typeof t||"object"==typeof t&&null!==t}function e(t){return"function"==typeof t}function n(t){I=t}function r(t){J=t}function o(){return function(){return process.nextTick(a)}}function i(){return"undefined"!=typeof H?function(){H(a)}:c()}function s(){var t=0,e=new V(a),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}function u(){var t=new MessageChannel;return t.port1.onmessage=a,function(){return t.port2.postMessage(0)}}function c(){var t=setTimeout;return function(){return t(a,1)}}function a(){for(var t=0;t<G;t+=2){var e=$[t],n=$[t+1];e(n),$[t]=void 0,$[t+1]=void 0}G=0}function f(){try{var t=require,e=t("vertx");return H=e.runOnLoop||e.runOnContext,i()}catch(n){return c()}}function l(t,e){var n=arguments,r=this,o=new this.constructor(p);void 0===o[et]&&k(o);var i=r._state;return i?!function(){var t=n[i-1];J(function(){return x(i,o,t,r._result)})}():E(r,o,t,e),o}function h(t){var e=this;if(t&&"object"==typeof t&&t.constructor===e)return t;var n=new e(p);return g(n,t),n}function p(){}function v(){return new TypeError("You cannot resolve a promise with itself")}function d(){return new TypeError("A promises callback cannot return that same promise.")}function _(t){try{return t.then}catch(e){return it.error=e,it}}function y(t,e,n,r){try{t.call(e,n,r)}catch(o){return o}}function m(t,e,n){J(function(t){var r=!1,o=y(n,e,function(n){r||(r=!0,e!==n?g(t,n):S(t,n))},function(e){r||(r=!0,j(t,e))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,j(t,o))},t)}function b(t,e){e._state===rt?S(t,e._result):e._state===ot?j(t,e._result):E(e,void 0,function(e){return g(t,e)},function(e){return j(t,e)})}function w(t,n,r){n.constructor===t.constructor&&r===l&&n.constructor.resolve===h?b(t,n):r===it?j(t,it.error):void 0===r?S(t,n):e(r)?m(t,n,r):S(t,n)}function g(e,n){e===n?j(e,v()):t(n)?w(e,n,_(n)):S(e,n)}function A(t){t._onerror&&t._onerror(t._result),T(t)}function S(t,e){t._state===nt&&(t._result=e,t._state=rt,0!==t._subscribers.length&&J(T,t))}function j(t,e){t._state===nt&&(t._state=ot,t._result=e,J(A,t))}function E(t,e,n,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=e,o[i+rt]=n,o[i+ot]=r,0===i&&t._state&&J(T,t)}function T(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var r=void 0,o=void 0,i=t._result,s=0;s<e.length;s+=3)r=e[s],o=e[s+n],r?x(n,r,o,i):o(i);t._subscribers.length=0}}function M(){this.error=null}function P(t,e){try{return t(e)}catch(n){return st.error=n,st}}function x(t,n,r,o){var i=e(r),s=void 0,u=void 0,c=void 0,a=void 0;if(i){if(s=P(r,o),s===st?(a=!0,u=s.error,s=null):c=!0,n===s)return void j(n,d())}else s=o,c=!0;n._state!==nt||(i&&c?g(n,s):a?j(n,u):t===rt?S(n,s):t===ot&&j(n,s))}function C(t,e){try{e(function(e){g(t,e)},function(e){j(t,e)})}catch(n){j(t,n)}}function O(){return ut++}function k(t){t[et]=ut++,t._state=void 0,t._result=void 0,t._subscribers=[]}function Y(t,e){this._instanceConstructor=t,this.promise=new t(p),this.promise[et]||k(this.promise),B(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?S(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&S(this.promise,this._result))):j(this.promise,q())}function q(){return new Error("Array Methods must be provided an Array")}function F(t){return new Y(this,t).promise}function D(t){var e=this;return new e(B(t)?function(n,r){for(var o=t.length,i=0;i<o;i++)e.resolve(t[i]).then(n,r)}:function(t,e){return e(new TypeError("You must pass an array to race."))})}function K(t){var e=this,n=new e(p);return j(n,t),n}function L(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function N(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function U(t){this[et]=O(),this._result=this._state=void 0,this._subscribers=[],p!==t&&("function"!=typeof t&&L(),this instanceof U?C(this,t):N())}function W(){var t=void 0;if("undefined"!=typeof global)t=global;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(e){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=t.Promise;if(n){var r=null;try{r=Object.prototype.toString.call(n.resolve())}catch(e){}if("[object Promise]"===r&&!n.cast)return}t.Promise=U}var z=void 0;z=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var B=z,G=0,H=void 0,I=void 0,J=function(t,e){$[G]=t,$[G+1]=e,G+=2,2===G&&(I?I(a):tt())},Q="undefined"!=typeof window?window:void 0,R=Q||{},V=R.MutationObserver||R.WebKitMutationObserver,X="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),Z="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,$=new Array(1e3),tt=void 0;tt=X?o():V?s():Z?u():void 0===Q&&"function"==typeof require?f():c();var et=Math.random().toString(36).substring(16),nt=void 0,rt=1,ot=2,it=new M,st=new M,ut=0;return Y.prototype._enumerate=function(){for(var t=this.length,e=this._input,n=0;this._state===nt&&n<t;n++)this._eachEntry(e[n],n)},Y.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,r=n.resolve;if(r===h){var o=_(t);if(o===l&&t._state!==nt)this._settledAt(t._state,e,t._result);else if("function"!=typeof o)this._remaining--,this._result[e]=t;else if(n===U){var i=new n(p);w(i,t,o),this._willSettleAt(i,e)}else this._willSettleAt(new n(function(e){return e(t)}),e)}else this._willSettleAt(r(t),e)},Y.prototype._settledAt=function(t,e,n){var r=this.promise;r._state===nt&&(this._remaining--,t===ot?j(r,n):this._result[e]=n),0===this._remaining&&S(r,this._result)},Y.prototype._willSettleAt=function(t,e){var n=this;E(t,void 0,function(t){return n._settledAt(rt,e,t)},function(t){return n._settledAt(ot,e,t)})},U.all=F,U.race=D,U.resolve=h,U.reject=K,U._setScheduler=n,U._setAsap=r,U._asap=J,U.prototype={constructor:U,then:l,"catch":function(t){return this.then(null,t)}},U.polyfill=W,U.Promise=U,U});
  
  /**
   *
   * Array.find() Polyfill
   * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
   *
   */
  if (!Array.prototype.find) {
    Array.prototype.find = function(predicate) {
      if (this === null) {
        throw new TypeError('Array.prototype.find called on null or undefined');
      }
      if (typeof predicate !== 'function') {
        throw new TypeError('predicate must be a function');
      }
      var list = Object(this);
      var length = list.length >>> 0;
      var thisArg = arguments[1];
      var value;
  
      for (var i = 0; i < length; i++) {
        value = list[i];
        if (predicate.call(thisArg, value, i, list)) {
          return value;
        }
      }
      return undefined;
    };
  }
  
  'use strict';
  
  /*!
   *
   * Author: Alex Disler (alexdisler.com)
   * github.com/alexdisler/cordova-plugin-inapppurchase
   *
   * Licensed under the MIT license. Please see README for more information.
   *
   */
  
  var utils = {};
  
  utils.errors = {
    101: 'invalid argument - productIds must be an array of strings',
    102: 'invalid argument - productId must be a string',
    103: 'invalid argument - product type must be a string',
    104: 'invalid argument - receipt must be a string of a json',
    105: 'invalid argument - signature must be a string'
  };
  
  utils.validArrayOfStrings = function (val) {
    return val && Array.isArray(val) && val.length > 0 && !val.find(function (i) {
      return !i.length || typeof i !== 'string';
    });
  };
  
  utils.validString = function (val) {
    return val && val.length && typeof val === 'string';
  };
  
  utils.chunk = function (array, size) {
    if (!Array.isArray(array)) {
      throw new Error('Invalid array');
    }
  
    if (typeof size !== 'number' || size < 1) {
      throw new Error('Invalid size');
    }
  
    var times = Math.ceil(array.length / size);
    return Array.apply(null, Array(times)).reduce(function (result, val, i) {
      return result.concat([array.slice(i * size, (i + 1) * size)]);
    }, []);
  };
  'use strict';
  
  /*!
   *
   * Author: Alex Disler (alexdisler.com)
   * github.com/alexdisler/cordova-plugin-inapppurchase
   *
   * Licensed under the MIT license. Please see README for more information.
   *
   */
  
  var inAppPurchase = { utils: utils };
  
  var createIapError = function createIapError(reject) {
    return function () {
      var err = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  
      err.errorCode = err.code;
      return reject(err);
    };
  };
  
  var nativeCall = function nativeCall(name) {
    var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  
    return new Promise(function (resolve, reject) {
      window.cordova.exec(function (res) {
        resolve(res);
      }, createIapError(reject), 'InAppBillingV6', name, args);
    });
  };
  
  var chunkedGetSkuDetails = function chunkedGetSkuDetails(productIds) {
    // We need to chunk the getSkuDetails call cause it is only allowed to provide a maximum of 20 items per call
    return utils.chunk(productIds, 19).reduce(function (promise, productIds) {
      return promise.then(function (result) {
        return nativeCall('getSkuDetails', productIds).then(function (items) {
          return result.concat(items);
        });
      });
    }, Promise.resolve([]));
  };
  
  inAppPurchase.getProducts = function (productIds) {
    return new Promise(function (resolve, reject) {
      if (!inAppPurchase.utils.validArrayOfStrings(productIds)) {
        reject(new Error(inAppPurchase.utils.errors[101]));
      } else {
        nativeCall('init', []).then(function () {
          return chunkedGetSkuDetails(productIds);
        }).then(function (items) {
          var arr = items.map(function (val) {
            return {
              productId: val.productId,
              title: val.title,
              description: val.description,
              price: val.price,
              priceRaw: val.priceRaw,
              priceAsDecimal: val.priceAsDecimal,
              currency: val.currency,
              country: val.country
            };
          });
          resolve(arr);
        }).catch(reject);
      }
    });
  };
  
  var executePaymentOfType = function executePaymentOfType(type, productId, extraParams) {
    return new Promise(function (resolve, reject) {
      if (!inAppPurchase.utils.validString(productId)) {
        reject(new Error(inAppPurchase.utils.errors[102]));
      } else {
        nativeCall(type, [productId, extraParams]).then(function (res) {
          resolve({
            signature: res.signature,
            productId: res.productId,
            transactionId: res.purchaseToken,
            type: res.type,
            productType: res.type,
            receipt: res.receipt
          });
        }).catch(reject);
      }
    });
  };
  
  inAppPurchase.buy = function (productId, extraParams) {
    return executePaymentOfType('buy', productId, extraParams);
  };
  
  inAppPurchase.subscribe = function (productId, extraParams) {
    return executePaymentOfType('subscribe', productId, extraParams);
  };
  
  inAppPurchase.consume = function (type, receipt, signature) {
    return new Promise(function (resolve, reject) {
      if (!inAppPurchase.utils.validString(type)) {
        reject(new Error(inAppPurchase.utils.errors[103]));
      } else if (!inAppPurchase.utils.validString(receipt)) {
        reject(new Error(inAppPurchase.utils.errors[104]));
      } else if (!inAppPurchase.utils.validString(signature)) {
        reject(new Error(inAppPurchase.utils.errors[105]));
      } else {
        nativeCall('consumePurchase', [type, receipt, signature]).then(resolve).catch(reject);
      }
    });
  };
  
  inAppPurchase.restorePurchases = function () {
    return nativeCall('init', []).then(function () {
      return nativeCall('restorePurchases', []);
    }).then(function (purchases) {
      var arr = [];
      if (purchases) {
        arr = purchases.map(function (val) {
          return {
            productId: val.productId,
            state: val.purchaseState,
            transactionId: val.orderId,
            date: val.purchaseTime,
            type: val.type,
            productType: val.type,
            signature: val.signature,
            receipt: val.receipt
          };
        });
      }
      return Promise.resolve(arr);
    });
  };
  
  inAppPurchase.getReceipt = function () {
    return Promise.resolve('');
  };
  
  module.exports = inAppPurchase;
  