From cb553f43bda1ea7738490825976f65a713ff30b4 Mon Sep 17 00:00:00 2001 From: Neil Rackett Date: Tue, 30 Apr 2019 12:26:59 +0100 Subject: [PATCH] Implemented API methods for browser platform (hard coded to reject) --- gulpfile.babel.js | 8 +++ plugin.xml | 6 ++ src/js/index-browser.js | 36 ++++++++++++ src/js/utils.js | 1 + www/index-android.js | 5 +- www/index-browser.js | 122 ++++++++++++++++++++++++++++++++++++++++ www/index-ios.js | 7 ++- 7 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 src/js/index-browser.js create mode 100644 www/index-browser.js diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 1eabf85..6569e7d 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -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 @@ -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); diff --git a/plugin.xml b/plugin.xml index 210a8be..84673bc 100644 --- a/plugin.xml +++ b/plugin.xml @@ -63,4 +63,10 @@ + + + + + + diff --git a/src/js/index-browser.js b/src/js/index-browser.js new file mode 100644 index 0000000..2633050 --- /dev/null +++ b/src/js/index-browser.js @@ -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; diff --git a/src/js/utils.js b/src/js/utils.js index a705ac5..eef2c2c 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -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) => { diff --git a/www/index-android.js b/www/index-android.js index 38ec66a..82ddb21 100644 --- a/www/index-android.js +++ b/www/index-android.js @@ -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) { @@ -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); diff --git a/www/index-browser.js b/www/index-browser.js new file mode 100644 index 0000000..d4c21c9 --- /dev/null +++ b/www/index-browser.js @@ -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>> 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; \ No newline at end of file diff --git a/www/index-ios.js b/www/index-ios.js index 91d71d0..4fa8bbd 100644 --- a/www/index-ios.js +++ b/www/index-ios.js @@ -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) { @@ -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);