Adds limits 500usd per day per user
This commit is contained in:
parent
39c3a85bd3
commit
d25cb3d02e
4 changed files with 76 additions and 12 deletions
|
|
@ -6,10 +6,10 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
window.ignoreMobilePause = true;
|
window.ignoreMobilePause = true;
|
||||||
var self = this;
|
var self = this;
|
||||||
var fc;
|
var fc;
|
||||||
var minimumAmount = 1;
|
var minimumAmount = 5;
|
||||||
var stepAmount = 1;
|
var stepAmount = 1;
|
||||||
var multiplierAmount = 2;
|
var multiplierAmount = 5;
|
||||||
var maximumAmount = 10;
|
var maximumAmount = 500;
|
||||||
|
|
||||||
var otherWallets = function(network) {
|
var otherWallets = function(network) {
|
||||||
return lodash.filter(profileService.getWallets(network), function(w) {
|
return lodash.filter(profileService.getWallets(network), function(w) {
|
||||||
|
|
@ -26,7 +26,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
};
|
};
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
$scope.fiat = minimumAmount * multiplierAmount;
|
$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);
|
||||||
self.otherWallets = otherWallets(network);
|
self.otherWallets = otherWallets(network);
|
||||||
|
|
@ -99,7 +99,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
if (plus && $scope.fiat < maximumAmount ) {
|
if (plus && $scope.fiat < maximumAmount ) {
|
||||||
stepAmount = stepAmount + 1;
|
stepAmount = stepAmount + 1;
|
||||||
$scope.fiat = stepAmount * multiplierAmount;
|
$scope.fiat = stepAmount * multiplierAmount;
|
||||||
} else if (!plus && $scope.fiat > minimumAmount * multiplierAmount) {
|
} else if (!plus && $scope.fiat > minimumAmount) {
|
||||||
stepAmount = stepAmount - 1;
|
stepAmount = stepAmount - 1;
|
||||||
$scope.fiat = stepAmount * multiplierAmount;
|
$scope.fiat = stepAmount * multiplierAmount;
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
amazonService.createBitPayInvoice(dataSrc, function(err, data) {
|
amazonService.createBitPayInvoice(dataSrc, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.loading = null;
|
self.loading = null;
|
||||||
self.error = err;
|
self.error = bwsError.msg(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,6 +185,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
|
||||||
self.errorInfo = gift;
|
self.errorInfo = gift;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
amazonService.setAmountByDay(dataSrc.price);
|
||||||
self.giftCard = giftCard;
|
self.giftCard = giftCard;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
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) {
|
||||||
var root = {};
|
var root = {};
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
|
var LIMIT = 500;
|
||||||
|
|
||||||
root.setCredentials = function(network) {
|
root.setCredentials = function(network) {
|
||||||
credentials.AMAZON_SANDBOX = network == 'testnet' ? true : false;
|
credentials.AMAZON_SANDBOX = network == 'testnet' ? true : false;
|
||||||
|
|
@ -28,6 +29,50 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var _checkLimit = function(amount, cb) {
|
||||||
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
|
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
||||||
|
storageService.getAmazonLimits(network, function(err, limits) {
|
||||||
|
if (err) $log.error(err);
|
||||||
|
|
||||||
|
if (lodash.isEmpty(limits) && amount <= LIMIT) return cb();
|
||||||
|
if (lodash.isEmpty(limits) || amount > LIMIT) return cb('EXCEEDED_DAYLY_LIMIT');
|
||||||
|
|
||||||
|
if (lodash.isString(limits)) {
|
||||||
|
limits = JSON.parse(limits);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (limits.date == dateStamp && (limits.amount + amount) > LIMIT)
|
||||||
|
return cb('EXCEEDED_DAYLY_LIMIT');
|
||||||
|
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.setAmountByDay = function(amount) {
|
||||||
|
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
|
||||||
|
var dateStamp = moment.utc().format('YYYY-MM-DD');
|
||||||
|
storageService.getAmazonLimits(network, function(err, limits) {
|
||||||
|
if (err) $log.error(err);
|
||||||
|
|
||||||
|
if (lodash.isEmpty(limits)) limits = { date: dateStamp, amount: 0 };
|
||||||
|
|
||||||
|
if (lodash.isString(limits)) {
|
||||||
|
limits = JSON.parse(limits);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (limits.date == dateStamp) {
|
||||||
|
limits.amount = limits.amount + amount;
|
||||||
|
} else {
|
||||||
|
limits = { date: dateStamp, amount: amount };
|
||||||
|
}
|
||||||
|
limits = JSON.stringify(limits);
|
||||||
|
storageService.setAmazonLimits(network, limits, function(err) {
|
||||||
|
if (err) $log.error(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var _getSignatureKey = function() {
|
var _getSignatureKey = function() {
|
||||||
|
|
||||||
var key = credentials.AMAZON_SECRET_KEY;
|
var key = credentials.AMAZON_SECRET_KEY;
|
||||||
|
|
@ -116,12 +161,15 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
|
||||||
price: data.price,
|
price: data.price,
|
||||||
currency: data.currency
|
currency: data.currency
|
||||||
};
|
};
|
||||||
$http(_postBitPay('/invoices', data)).then(function(data) {
|
_checkLimit(data.price, function(err) {
|
||||||
$log.info('BitPay Create Invoice: SUCCESS');
|
if (err) return cb(err);
|
||||||
return cb(null, data.data);
|
$http(_postBitPay('/invoices', data)).then(function(data) {
|
||||||
}, function(data) {
|
$log.info('BitPay Create Invoice: SUCCESS');
|
||||||
$log.error('BitPay Create Invoice: ERROR ' + data.data.error);
|
return cb(null, data.data);
|
||||||
return cb(data.data.error);
|
}, function(data) {
|
||||||
|
$log.error('BitPay Create Invoice: ERROR ' + data.data.error);
|
||||||
|
return cb(data.data.error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,9 @@ angular.module('copayApp.services')
|
||||||
case 'PASSWORD_INCORRECT':
|
case 'PASSWORD_INCORRECT':
|
||||||
body = gettextCatalog.getString('Wrong spending password');
|
body = gettextCatalog.getString('Wrong spending password');
|
||||||
break;
|
break;
|
||||||
|
case 'EXCEEDED_DAYLY_LIMIT':
|
||||||
|
body = gettextCatalog.getString('Exceeded dayly limit of $500 per user');
|
||||||
|
break;
|
||||||
case 'ERROR':
|
case 'ERROR':
|
||||||
body = (err.message || err.error);
|
body = (err.message || err.error);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -330,5 +330,17 @@ angular.module('copayApp.services')
|
||||||
storage.remove('amazonGiftCards-' + network, cb);
|
storage.remove('amazonGiftCards-' + network, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.setAmazonLimits = function(network, limits, cb) {
|
||||||
|
storage.set('amazonLimits-' + network, limits, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getAmazonLimits = function(network, cb) {
|
||||||
|
storage.get('amazonLimits-' + network, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.removeAmazonLimits = function(network, cb) {
|
||||||
|
storage.remove('amazonLimits-' + network, cb);
|
||||||
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue