Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Added browser platform support #270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const indexAndroid = 'index-android.js';
const polyfillsAndroid = 'polyfills-android.js';
const indexIos = 'index-ios.js';
const utils = 'utils.js';
const indexBrowser = 'index-browser.js';

const build = () => {
gulp
Expand All @@ -25,6 +26,13 @@ const build = () => {
.pipe(addsrc.prepend(src + polyfillsAndroid))
.pipe(concat(indexAndroid))
.pipe(gulp.dest(dist));
gulp
.src([ src + utils, src + indexBrowser ])
.pipe(plumber())
.pipe(babel())
.pipe(addsrc.prepend(src + polyfillsAndroid))
.pipe(concat(indexBrowser))
.pipe(gulp.dest(dist));
};

gulp.task('build', build);
Expand Down
6 changes: 6 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@
<source-file src="src/android/billing/IInAppBillingService.aidl" target-dir="src/com/android/vending/billing" />
</platform>

<platform name="browser">
<js-module src="www/index-browser.js" name="InAppPuchaseBrowser">
<clobbers target="inAppPurchase" />
</js-module>
</platform>

</plugin>
36 changes: 36 additions & 0 deletions src/js/index-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
*
* Author: Neil Rackett (mesmotronic.com)
* github.com/alexdisler/cordova-plugin-inapppurchase
*
* Licensed under the MIT license. Please see README for more information.
*
*/

const inAppPurchase = { utils };

inAppPurchase.getProducts = (productIds) => {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.buy = (productId) => {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.subscribe = (productId) => {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.consume = (type, receipt, signature) => {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.restorePurchases = () => {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.getReceipt = () => {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

module.exports = inAppPurchase;
1 change: 1 addition & 0 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ utils.errors = {
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',
106: 'platform not supported',
};

utils.validArrayOfStrings = (val) => {
Expand Down
5 changes: 3 additions & 2 deletions www/index-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ utils.errors = {
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'
105: 'invalid argument - signature must be a string',
106: 'platform not supported'
};

utils.validArrayOfStrings = function (val) {
Expand Down Expand Up @@ -139,7 +140,7 @@ inAppPurchase.getProducts = function (productIds) {
description: val.description,
price: val.price,
currency: val.currency,
priceAsDecimal: val.priceAsDecimal,
priceAsDecimal: val.priceAsDecimal
};
});
resolve(arr);
Expand Down
122 changes: 122 additions & 0 deletions www/index-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*!
* @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',
106: 'platform not supported'
};

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: Neil Rackett (mesmotronic.com)
* github.com/alexdisler/cordova-plugin-inapppurchase
*
* Licensed under the MIT license. Please see README for more information.
*
*/

var inAppPurchase = { utils: utils };

inAppPurchase.getProducts = function (productIds) {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.buy = function (productId) {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.subscribe = function (productId) {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.consume = function (type, receipt, signature) {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.restorePurchases = function () {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

inAppPurchase.getReceipt = function () {
return Promise.reject(new Error(inAppPurchase.utils.errors[106]));
};

module.exports = inAppPurchase;
7 changes: 4 additions & 3 deletions www/index-ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ utils.errors = {
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'
105: 'invalid argument - signature must be a string',
106: 'platform not supported'
};

utils.validArrayOfStrings = function (val) {
Expand Down Expand Up @@ -82,9 +83,9 @@ inAppPurchase.getProducts = function (productIds) {
productId: val.productId,
title: val.title,
description: val.description,
price: val.price,
currency: val.currency,
priceAsDecimal: val.priceAsDecimal,
price: val.price,
currency: val.currency
};
});
resolve(arr);
Expand Down