Adds sandbox message. Adds uuid from device
This commit is contained in:
parent
6db2d13b7d
commit
cd87d9628d
5 changed files with 78 additions and 59 deletions
|
|
@ -40,6 +40,11 @@
|
||||||
|
|
||||||
<div ng-init="amazon.init()">
|
<div ng-init="amazon.init()">
|
||||||
|
|
||||||
|
<div class="box-notification text-center size-12 text-warning m10t" ng-show="amazon.sandbox">
|
||||||
|
<i class="fi-info"></i>
|
||||||
|
Sandbox version. Only for testing purpose
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="m20t text-center" ng-click="amazon.init()">
|
<div class="m20t text-center" ng-click="amazon.init()">
|
||||||
<img src="img/GCs-logo-cllb.png" alt="Amazon.com Gift Card" width="200">
|
<img src="img/GCs-logo-cllb.png" alt="Amazon.com Gift Card" width="200">
|
||||||
<div class="size-10 m5t text-gray"><b>Only</b> redeemable on www.amazon.com (USA website)</div>
|
<div class="size-10 m5t text-gray"><b>Only</b> redeemable on www.amazon.com (USA website)</div>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('amazonController',
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
|
self.sandbox = network == 'testnet' ? true : false;
|
||||||
amazonService.setCredentials(network);
|
amazonService.setCredentials(network);
|
||||||
amazonService.getGiftCards(function(err, gcds) {
|
amazonService.getGiftCards(function(err, gcds) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
$scope.fiat = minimumAmount;
|
$scope.fiat = minimumAmount;
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
amazonService.setCredentials(network);
|
amazonService.setCredentials(network);
|
||||||
|
amazonService.healthCheckRequest();
|
||||||
|
amazonService.initUuid();
|
||||||
self.otherWallets = otherWallets(network);
|
self.otherWallets = otherWallets(network);
|
||||||
// Choose focused wallet
|
// Choose focused wallet
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService) {
|
angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo) {
|
||||||
var root = {};
|
var root = {};
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
var LIMIT = 500;
|
var LIMIT = 500;
|
||||||
|
|
@ -27,29 +27,43 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
credentials.AMAZON_REGION = window.amazon_region;
|
credentials.AMAZON_REGION = window.amazon_region;
|
||||||
credentials.AMAZON_ENDPOINT = window.amazon_endpoint;
|
credentials.AMAZON_ENDPOINT = window.amazon_endpoint;
|
||||||
};
|
};
|
||||||
_healthCheckRequest();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getUuid = function(cb) {
|
var _getUuid = function(cb) {
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var isCordova = platformInfo.isCordova;
|
||||||
storageService.getAmazonUuid(network, function(err, uuid) {
|
|
||||||
if (err) {
|
if (isCordova) {
|
||||||
|
window.plugins.uniqueDeviceID.get(function(uuid) {
|
||||||
|
return cb(uuid);
|
||||||
|
}, function(err) {
|
||||||
$log.error(err);
|
$log.error(err);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
|
||||||
if (!lodash.isEmpty(uuid)) return cb(uuid);
|
|
||||||
uuid = 'Copay-' + moment().unix();
|
|
||||||
storageService.setAmazonUuid(network, uuid, function(err) {
|
|
||||||
if (err) {
|
|
||||||
$log.error(err);
|
|
||||||
return cb();
|
|
||||||
}
|
|
||||||
return cb(uuid);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return cb('XXX'); // Test purpose
|
||||||
|
};
|
||||||
|
|
||||||
|
var _checkLimits = function(amount, cb) {
|
||||||
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
|
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
||||||
|
|
||||||
|
storageService.getAmazon(network, function(err, amazon) {
|
||||||
|
if (err) $log.error(err);
|
||||||
|
|
||||||
|
if (lodash.isEmpty(amazon)) return cb('CAN_NOT_GET_DATA_FROM_STORAGE');
|
||||||
|
|
||||||
|
if (lodash.isString(amazon)) {
|
||||||
|
amazon = JSON.parse(amazon);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amazon.date == dateStamp && (amazon.amount + amount) > LIMIT)
|
||||||
|
return cb('EXCEEDED_DAYLY_LIMIT');
|
||||||
|
|
||||||
|
return cb();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var _healthCheckRequest = function() {
|
root.healthCheckRequest = function() {
|
||||||
$http({
|
$http({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: credentials.AMAZON_ENDPOINT + '/sping',
|
url: credentials.AMAZON_ENDPOINT + '/sping',
|
||||||
|
|
@ -63,45 +77,54 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var _checkLimit = function(amount, cb) {
|
root.initUuid = function() {
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
||||||
storageService.getAmazonLimits(network, function(err, limits) {
|
_getUuid(function(uuid) {
|
||||||
if (err) $log.error(err);
|
storageService.getAmazon(network, function(err, amazon) {
|
||||||
|
if (err) $log.error(err);
|
||||||
if (lodash.isEmpty(limits) && amount <= LIMIT) return cb();
|
if (lodash.isEmpty(amazon))
|
||||||
if (lodash.isEmpty(limits) || amount > LIMIT) return cb('EXCEEDED_DAYLY_LIMIT');
|
amazon = {
|
||||||
|
uuid: uuid,
|
||||||
if (lodash.isString(limits)) {
|
date: dateStamp,
|
||||||
limits = JSON.parse(limits);
|
amount: 0
|
||||||
}
|
};
|
||||||
|
|
||||||
if (limits.date == dateStamp && (limits.amount + amount) > LIMIT)
|
if (lodash.isString(amazon)) {
|
||||||
return cb('EXCEEDED_DAYLY_LIMIT');
|
amazon = JSON.parse(amazon);
|
||||||
|
}
|
||||||
|
|
||||||
return cb();
|
amazon.uuid = uuid;
|
||||||
|
if (amazon.date != dateStamp) {
|
||||||
|
amazon.date = dateStamp;
|
||||||
|
amazon.amount = 0;
|
||||||
|
}
|
||||||
|
amazon = JSON.stringify(amazon);
|
||||||
|
storageService.setAmazon(network, amazon, function(err) {
|
||||||
|
if (err) $log.error(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setAmountByDay = function(amount) {
|
root.setAmountByDay = function(amount) {
|
||||||
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
||||||
storageService.getAmazonLimits(network, function(err, limits) {
|
storageService.getAmazon(network, function(err, amazon) {
|
||||||
if (err) $log.error(err);
|
if (err) $log.error(err);
|
||||||
|
|
||||||
if (lodash.isEmpty(limits)) limits = { date: dateStamp, amount: 0 };
|
if (lodash.isString(amazon)) {
|
||||||
|
amazon = JSON.parse(amazon);
|
||||||
if (lodash.isString(limits)) {
|
|
||||||
limits = JSON.parse(limits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (limits.date == dateStamp) {
|
if (amazon.date == dateStamp) {
|
||||||
limits.amount = limits.amount + amount;
|
amazon.amount = amazon.amount + amount;
|
||||||
} else {
|
} else {
|
||||||
limits = { date: dateStamp, amount: amount };
|
amazon.date = dateStamp;
|
||||||
|
amazon.amount = amount;
|
||||||
}
|
}
|
||||||
limits = JSON.stringify(limits);
|
amazon = JSON.stringify(amazon);
|
||||||
storageService.setAmazonLimits(network, limits, function(err) {
|
storageService.setAmazon(network, amazon, function(err) {
|
||||||
if (err) $log.error(err);
|
if (err) $log.error(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -199,7 +222,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
orderId: data.orderId,
|
orderId: data.orderId,
|
||||||
posData: '{uuid:' + uuid + '}'
|
posData: '{uuid:' + uuid + '}'
|
||||||
};
|
};
|
||||||
_checkLimit(data.price, function(err) {
|
_checkLimits(data.price, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
$http(_postBitPay('/invoices', dataSrc)).then(function(data) {
|
$http(_postBitPay('/invoices', dataSrc)).then(function(data) {
|
||||||
$log.info('BitPay Create Invoice: SUCCESS');
|
$log.info('BitPay Create Invoice: SUCCESS');
|
||||||
|
|
|
||||||
|
|
@ -330,28 +330,16 @@ angular.module('copayApp.services')
|
||||||
storage.remove('amazonGiftCards-' + network, cb);
|
storage.remove('amazonGiftCards-' + network, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setAmazonLimits = function(network, limits, cb) {
|
root.setAmazon = function(network, data, cb) {
|
||||||
storage.set('amazonLimits-' + network, limits, cb);
|
storage.set('amazon-' + network, data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getAmazonLimits = function(network, cb) {
|
root.getAmazon = function(network, cb) {
|
||||||
storage.get('amazonLimits-' + network, cb);
|
storage.get('amazon-' + network, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeAmazonLimits = function(network, cb) {
|
root.removeAmazon = function(network, cb) {
|
||||||
storage.remove('amazonLimits-' + network, cb);
|
storage.remove('amazon-' + network, cb);
|
||||||
};
|
|
||||||
|
|
||||||
root.setAmazonUuid = function(network, uuid, cb) {
|
|
||||||
storage.set('amazonUuid-' + network, uuid, cb);
|
|
||||||
};
|
|
||||||
|
|
||||||
root.getAmazonUuid = function(network, cb) {
|
|
||||||
storage.get('amazonUuid-' + network, cb);
|
|
||||||
};
|
|
||||||
|
|
||||||
root.removeAmazonUuid = function(network, cb) {
|
|
||||||
storage.remove('amazonUuid-' + network, cb);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue