Buy gift card. Limits
This commit is contained in:
parent
ef650aff86
commit
3e78971446
7 changed files with 221 additions and 193 deletions
|
|
@ -1,27 +1,36 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('buyMercadoLibreController', function($scope, $log, $state, $timeout, $filter, $ionicHistory, lodash, mercadoLibreService, popupService, profileService, ongoingProcess, configService, walletService, payproService, bwcError, externalLinkService, platformInfo) {
|
angular.module('copayApp.controllers').controller('buyMercadoLibreController', function($scope, $log, $state, $timeout, $filter, $ionicHistory, $ionicConfig, lodash, mercadoLibreService, popupService, profileService, ongoingProcess, configService, walletService, payproService, bwcError, externalLinkService, platformInfo, txFormatService, gettextCatalog) {
|
||||||
|
|
||||||
var amount;
|
var amount;
|
||||||
var currency;
|
var currency;
|
||||||
|
var createdTx;
|
||||||
|
var message;
|
||||||
|
var invoiceId;
|
||||||
|
var configWallet = configService.getSync().wallet;
|
||||||
$scope.isCordova = platformInfo.isCordova;
|
$scope.isCordova = platformInfo.isCordova;
|
||||||
|
|
||||||
$scope.openExternalLink = function(url) {
|
$scope.openExternalLink = function(url) {
|
||||||
externalLinkService.open(url);
|
externalLinkService.open(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
var showErrorAndBack = function(msg, err) {
|
var showErrorAndBack = function(title, msg) {
|
||||||
|
title = title || gettextCatalog.getString('Error');
|
||||||
$scope.sendStatus = '';
|
$scope.sendStatus = '';
|
||||||
err = err && err.errors ? err.errors[0].message : err;
|
$log.error(msg);
|
||||||
popupService.showAlert(msg, err, function() {
|
msg = (msg && msg.errors) ? msg.errors[0].message : msg;
|
||||||
|
popupService.showAlert(title, msg, function() {
|
||||||
$ionicHistory.goBack();
|
$ionicHistory.goBack();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var showError = function(msg, err) {
|
var showError = function(title, msg, cb) {
|
||||||
|
cb = cb || function() {};
|
||||||
|
title = title || gettextCatalog.getString('Error');
|
||||||
$scope.sendStatus = '';
|
$scope.sendStatus = '';
|
||||||
err = err && err.errors ? err.errors[0].message : (err || '');
|
$log.error(msg);
|
||||||
popupService.showAlert(msg, err);
|
msg = (msg && msg.errors) ? msg.errors[0].message : msg;
|
||||||
|
popupService.showAlert(title, msg, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
var publishAndSign = function(wallet, txp, onSendStatusChange, cb) {
|
var publishAndSign = function(wallet, txp, onSendStatusChange, cb) {
|
||||||
|
|
@ -49,15 +58,95 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var createInvoice = function(data, cb) {
|
||||||
|
mercadoLibreService.createBitPayInvoice(data, function(err, dataInvoice) {
|
||||||
|
if (err) {
|
||||||
|
var err_title = gettextCatalog.getString('Error creating the invoice');
|
||||||
|
var err_msg;
|
||||||
|
if (err && err.message && err.message.match(/suspended/i)) {
|
||||||
|
err_title = gettextCatalog.getString('Service not available');
|
||||||
|
err_msg = gettextCatalog.getString('Mercadolibre Gift Card Service is not available at this moment. Please try back later.');
|
||||||
|
} else if (err && err.message) {
|
||||||
|
err_msg = err.message;
|
||||||
|
} else {
|
||||||
|
err_msg = gettextCatalog.getString('Could not access Gift Card Service');
|
||||||
|
};
|
||||||
|
|
||||||
|
return cb({
|
||||||
|
title: err_title,
|
||||||
|
message: err_msg
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var accessKey = dataInvoice ? dataInvoice.accessKey : null;
|
||||||
|
|
||||||
|
if (!accessKey) {
|
||||||
|
return cb({
|
||||||
|
message: gettextCatalog.getString('No access key defined')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mercadoLibreService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) {
|
||||||
|
if (err) {
|
||||||
|
return cb({
|
||||||
|
message: gettextCatalog.getString('Could not get the invoice')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb(null, invoice, accessKey);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var createTx = function(wallet, invoice, message, cb) {
|
||||||
|
var payProUrl = (invoice && invoice.paymentUrls) ? invoice.paymentUrls.BIP73 : null;
|
||||||
|
|
||||||
|
if (!payProUrl) {
|
||||||
|
return cb({
|
||||||
|
title: gettextCatalog.getString('Error in Payment Protocol'),
|
||||||
|
message: gettextCatalog.getString('Invalid URL')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var outputs = [];
|
||||||
|
var toAddress = invoice.bitcoinAddress;
|
||||||
|
var amountSat = parseInt(invoice.btcDue * 100000000); // BTC to Satoshi
|
||||||
|
|
||||||
|
outputs.push({
|
||||||
|
'toAddress': toAddress,
|
||||||
|
'amount': amountSat,
|
||||||
|
'message': message
|
||||||
|
});
|
||||||
|
|
||||||
|
var txp = {
|
||||||
|
toAddress: toAddress,
|
||||||
|
amount: amountSat,
|
||||||
|
outputs: outputs,
|
||||||
|
message: message,
|
||||||
|
payProUrl: payProUrl,
|
||||||
|
excludeUnconfirmedUtxos: configWallet.spendUnconfirmed ? false : true,
|
||||||
|
feeLevel: configWallet.settings.feeLevel || 'normal'
|
||||||
|
};
|
||||||
|
|
||||||
|
walletService.createTx(wallet, txp, function(err, ctxp) {
|
||||||
|
if (err) {
|
||||||
|
return cb({
|
||||||
|
title: gettextCatalog.getString('Could not create transaction'),
|
||||||
|
message: bwcError.msg(err)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cb(null, ctxp);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var checkTransaction = lodash.throttle(function(count, dataSrc) {
|
var checkTransaction = lodash.throttle(function(count, dataSrc) {
|
||||||
mercadoLibreService.createGiftCard(dataSrc, function(err, giftCard) {
|
mercadoLibreService.createGiftCard(dataSrc, function(err, giftCard) {
|
||||||
console.log('[buyMercadoLibre.js:53]',giftCard); //TODO
|
|
||||||
$log.debug("creating gift card " + count);
|
$log.debug("creating gift card " + count);
|
||||||
if (err) {
|
if (err || !giftCard.pin) {
|
||||||
|
$scope.sendStatus = '';
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
||||||
giftCard = {};
|
giftCard = {};
|
||||||
giftCard.status = 'FAILURE';
|
giftCard.status = 'FAILURE';
|
||||||
showError('Error creating gift card', err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (giftCard.status == 'PENDING' && count < 3) {
|
if (giftCard.status == 'PENDING' && count < 3) {
|
||||||
|
|
@ -77,17 +166,6 @@ console.log('[buyMercadoLibre.js:53]',giftCard); //TODO
|
||||||
newData['date'] = dataSrc.invoiceTime || now;
|
newData['date'] = dataSrc.invoiceTime || now;
|
||||||
newData['uuid'] = dataSrc.uuid;
|
newData['uuid'] = dataSrc.uuid;
|
||||||
|
|
||||||
if (newData.status == 'expired') {
|
|
||||||
mercadoLibreService.savePendingGiftCard(newData, {
|
|
||||||
remove: true
|
|
||||||
}, function(err) {
|
|
||||||
$log.error(err);
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('Invoice expired');
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
mercadoLibreService.savePendingGiftCard(newData, null, function(err) {
|
mercadoLibreService.savePendingGiftCard(newData, null, function(err) {
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
||||||
$log.debug("Saving new gift card with status: " + newData.status);
|
$log.debug("Saving new gift card with status: " + newData.status);
|
||||||
|
|
@ -98,144 +176,106 @@ console.log('[buyMercadoLibre.js:53]',giftCard); //TODO
|
||||||
'leading': true
|
'leading': true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var initialize = function(wallet, parsedAmount) {
|
||||||
|
$scope.amountUnitStr = parsedAmount.amountUnitStr;
|
||||||
|
var dataSrc = {
|
||||||
|
amount: parsedAmount.amount,
|
||||||
|
currency: parsedAmount.currency,
|
||||||
|
uuid: wallet.id
|
||||||
|
};
|
||||||
|
ongoingProcess.set('loadingTxInfo', true);
|
||||||
|
createInvoice(dataSrc, function(err, invoice, accessKey) {
|
||||||
|
if (err) {
|
||||||
|
ongoingProcess.set('loadingTxInfo', false);
|
||||||
|
showErrorAndBack(err.title, err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
message = gettextCatalog.getString("Mercado Libre Gift Card {{amountStr}}", {
|
||||||
|
amountStr: $scope.amountUnitStr
|
||||||
|
});
|
||||||
|
|
||||||
|
createTx(wallet, invoice, message, function(err, ctxp) {
|
||||||
|
ongoingProcess.set('loadingTxInfo', false);
|
||||||
|
if (err) {
|
||||||
|
// Clear variables
|
||||||
|
createdTx = message = $scope.totalFeeStr = $scope.totalAmountStr = $scope.wallet = null;
|
||||||
|
showError(err.title, err.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save in memory
|
||||||
|
createdTx = ctxp;
|
||||||
|
invoiceId = invoice.id;
|
||||||
|
|
||||||
|
createdTx['giftData'] = {
|
||||||
|
currency: dataSrc.currency,
|
||||||
|
amount: dataSrc.amount,
|
||||||
|
uuid: dataSrc.uuid,
|
||||||
|
accessKey: accessKey,
|
||||||
|
invoiceId: invoice.id,
|
||||||
|
invoiceUrl: invoice.url,
|
||||||
|
invoiceTime: invoice.invoiceTime
|
||||||
|
};
|
||||||
|
$scope.totalFeeStr = txFormatService.formatAmountStr(ctxp.fee);
|
||||||
|
$scope.totalAmountStr = txFormatService.formatAmountStr(ctxp.amount + ctxp.fee);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.$on("$ionicView.beforeLeave", function(event, data) {
|
||||||
|
$ionicConfig.views.swipeBackEnabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.$on("$ionicView.enter", function(event, data) {
|
||||||
|
$ionicConfig.views.swipeBackEnabled(false);
|
||||||
|
});
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
amount = data.stateParams.amount;
|
amount = data.stateParams.amount;
|
||||||
currency = data.stateParams.currency;
|
currency = data.stateParams.currency;
|
||||||
|
|
||||||
/* TODO
|
|
||||||
if (amount > 2000 || amount < 50) {
|
if (amount > 2000 || amount < 50) {
|
||||||
showErrorAndBack('Purchase amount must be a value between 50 and 2000');
|
showErrorAndBack(null, gettextCatalog.getString('Purchase amount must be a value between 50 and 2000'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
$scope.amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
|
|
||||||
|
|
||||||
$scope.network = mercadoLibreService.getNetwork();
|
$scope.network = mercadoLibreService.getNetwork();
|
||||||
$scope.wallets = profileService.getWallets({
|
$scope.wallets = profileService.getWallets({
|
||||||
onlyComplete: true,
|
onlyComplete: true,
|
||||||
network: $scope.network,
|
network: $scope.network
|
||||||
hasFunds: true
|
|
||||||
});
|
});
|
||||||
if (lodash.isEmpty($scope.wallets)) {
|
if (lodash.isEmpty($scope.wallets)) {
|
||||||
showErrorAndBack('No wallets with funds');
|
showErrorAndBack(null, gettextCatalog.getString('No wallets available'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$scope.wallet = $scope.wallets[0]; // Default first wallet
|
$scope.onWalletSelect($scope.wallets[0]); // Default first wallet
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.buyConfirm = function() {
|
$scope.buyConfirm = function() {
|
||||||
|
|
||||||
var message = 'Buy gift card for ' + amount + ' ' + currency;
|
if (!createdTx) {
|
||||||
var okText = 'Confirm';
|
showError(null, gettextCatalog.getString('Transaction has not been created'));
|
||||||
var cancelText = 'Cancel';
|
return;
|
||||||
popupService.showConfirm(null, message, okText, cancelText, function(ok) {
|
}
|
||||||
if (!ok) return;
|
|
||||||
|
|
||||||
var config = configService.getSync();
|
var title = gettextCatalog.getString('Confirm');
|
||||||
var configWallet = config.wallet;
|
var okText = gettextCatalog.getString('Ok');
|
||||||
var walletSettings = configWallet.settings;
|
var cancelText = gettextCatalog.getString('Cancel');
|
||||||
// Selected WalletID as UUID
|
popupService.showConfirm(title, message, okText, cancelText, function(ok) {
|
||||||
var uuid = $scope.wallet.id;
|
if (!ok) {
|
||||||
var dataSrc = {
|
$scope.sendStatus = '';
|
||||||
currency: currency,
|
return;
|
||||||
amount: amount,
|
}
|
||||||
uuid: uuid
|
|
||||||
};
|
|
||||||
|
|
||||||
ongoingProcess.set('buyingGiftCard', true, statusChangeHandler);
|
ongoingProcess.set('buyingGiftCard', true, statusChangeHandler);
|
||||||
mercadoLibreService.createBitPayInvoice(dataSrc, function(err, dataInvoice) {
|
publishAndSign($scope.wallet, createdTx, function() {}, function(err, txSent) {
|
||||||
if (err) {
|
if (err) {
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
||||||
|
showError(gettextCatalog.getString('Could not send transaction'), err);
|
||||||
if (err && err.message && err.message.match(/suspended/i)) {
|
|
||||||
showError('Service not available', 'Mercadolibre Gift Card Service is not available at this moment. Please try back later.');
|
|
||||||
} else {
|
|
||||||
showError('Could not access Gift Card Service', err);
|
|
||||||
};
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
checkTransaction(1, createdTx.giftData);
|
||||||
var accessKey = dataInvoice ? dataInvoice.accessKey : null;
|
|
||||||
|
|
||||||
if (!accessKey) {
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('No access key defined');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mercadoLibreService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) {
|
|
||||||
if (err) {
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('Error getting BitPay invoice', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var payProUrl = (invoice && invoice.paymentUrls) ? invoice.paymentUrls.BIP73 : null;
|
|
||||||
|
|
||||||
if (!payProUrl) {
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('Error fetching invoice');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
payproService.getPayProDetails(payProUrl, function(err, payProDetails) {
|
|
||||||
if (err) {
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('Error fetching payment info', bwcError.msg(err));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var outputs = [];
|
|
||||||
var toAddress = payProDetails.toAddress;
|
|
||||||
var amountSat = payProDetails.amount;
|
|
||||||
var comment = amount + ' ' + currency + ' Mercadolibre Gift Card';
|
|
||||||
|
|
||||||
outputs.push({
|
|
||||||
'toAddress': toAddress,
|
|
||||||
'amount': amountSat,
|
|
||||||
'message': comment
|
|
||||||
});
|
|
||||||
|
|
||||||
var txp = {
|
|
||||||
toAddress: toAddress,
|
|
||||||
amount: amountSat,
|
|
||||||
outputs: outputs,
|
|
||||||
message: comment,
|
|
||||||
payProUrl: payProUrl,
|
|
||||||
excludeUnconfirmedUtxos: configWallet.spendUnconfirmed ? false : true,
|
|
||||||
feeLevel: walletSettings.feeLevel || 'normal'
|
|
||||||
};
|
|
||||||
|
|
||||||
walletService.createTx($scope.wallet, txp, function(err, ctxp) {
|
|
||||||
if (err) {
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('Could not create transaction', bwcError.msg(err));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
publishAndSign($scope.wallet, ctxp, function() {}, function(err, txSent) {
|
|
||||||
if (err) {
|
|
||||||
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
|
|
||||||
showError('Could not send transaction', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$log.debug('Transaction broadcasted. Waiting for confirmation...');
|
|
||||||
var invoiceId = JSON.parse(payProDetails.merchant_data).invoiceId;
|
|
||||||
var dataSrc = {
|
|
||||||
currency: currency,
|
|
||||||
amount: amount,
|
|
||||||
uuid: uuid,
|
|
||||||
accessKey: accessKey,
|
|
||||||
invoiceId: invoice.id,
|
|
||||||
invoiceUrl: payProUrl,
|
|
||||||
invoiceTime: invoice.invoiceTime
|
|
||||||
};
|
|
||||||
checkTransaction(1, dataSrc);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, true); // Disable loader
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -247,6 +287,8 @@ console.log('[buyMercadoLibre.js:53]',giftCard); //TODO
|
||||||
|
|
||||||
$scope.onWalletSelect = function(wallet) {
|
$scope.onWalletSelect = function(wallet) {
|
||||||
$scope.wallet = wallet;
|
$scope.wallet = wallet;
|
||||||
|
var parsedAmount = txFormatService.parseAmount(amount, currency);
|
||||||
|
initialize(wallet, parsedAmount);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.goBackHome = function() {
|
$scope.goBackHome = function() {
|
||||||
|
|
@ -256,14 +298,13 @@ console.log('[buyMercadoLibre.js:53]',giftCard); //TODO
|
||||||
historyRoot: true
|
historyRoot: true
|
||||||
});
|
});
|
||||||
$ionicHistory.clearHistory();
|
$ionicHistory.clearHistory();
|
||||||
var claimCode = $scope.mlGiftCard ? $scope.mlGiftCard.pin : null;
|
|
||||||
$state.go('tabs.home').then(function() {
|
$state.go('tabs.home').then(function() {
|
||||||
$ionicHistory.nextViewOptions({
|
$ionicHistory.nextViewOptions({
|
||||||
disableAnimate: true
|
disableAnimate: true
|
||||||
});
|
});
|
||||||
$state.transitionTo('tabs.giftcards.mercadoLibre').then(function() {
|
$state.transitionTo('tabs.giftcards.mercadoLibre').then(function() {
|
||||||
$state.transitionTo('tabs.giftcards.mercadoLibre.cards', {
|
$state.transitionTo('tabs.giftcards.mercadoLibre.cards', {
|
||||||
cardClaimCode: claimCode
|
invoiceId: invoiceId
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -46,15 +46,6 @@ angular.module('copayApp.controllers').controller('mercadoLibreCardsController',
|
||||||
|
|
||||||
lodash.merge(newData, dataFromStorage, giftCard);
|
lodash.merge(newData, dataFromStorage, giftCard);
|
||||||
|
|
||||||
if (newData.status == 'expired') {
|
|
||||||
mercadoLibreService.savePendingGiftCard(newData, {
|
|
||||||
remove: true
|
|
||||||
}, function(err) {
|
|
||||||
updateGiftCards();
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
mercadoLibreService.savePendingGiftCard(newData, null, function(err) {
|
mercadoLibreService.savePendingGiftCard(newData, null, function(err) {
|
||||||
$log.debug("Saving new gift card");
|
$log.debug("Saving new gift card");
|
||||||
updateGiftCards();
|
updateGiftCards();
|
||||||
|
|
@ -85,11 +76,11 @@ angular.module('copayApp.controllers').controller('mercadoLibreCardsController',
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
$scope.cardClaimCode = data.stateParams.cardClaimCode;
|
$scope.invoiceId = data.stateParams.invoiceId;
|
||||||
updateGiftCards(function() {
|
updateGiftCards(function() {
|
||||||
if ($scope.cardClaimCode) {
|
if ($scope.invoiceId) {
|
||||||
var card = lodash.find($scope.giftCards, {
|
var card = lodash.find($scope.giftCards, {
|
||||||
claimCode: $scope.cardClaimCode
|
invoiceId: $scope.invoiceId
|
||||||
});
|
});
|
||||||
if (lodash.isEmpty(card)) {
|
if (lodash.isEmpty(card)) {
|
||||||
popupService.showAlert(null, 'Card not found');
|
popupService.showAlert(null, 'Card not found');
|
||||||
|
|
|
||||||
|
|
@ -1050,7 +1050,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
cardClaimCode: null
|
invoiceId: null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.giftcards.mercadoLibre.amount', {
|
.state('tabs.giftcards.mercadoLibre.amount', {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ angular.module('copayApp.services').factory('mercadoLibreService', function($htt
|
||||||
credentials.NETWORK = 'testnet';
|
credentials.NETWORK = 'testnet';
|
||||||
|
|
||||||
if (credentials.NETWORK == 'testnet') {
|
if (credentials.NETWORK == 'testnet') {
|
||||||
credentials.BITPAY_API_URL = "https://test.bitpay.com";
|
credentials.BITPAY_API_URL = "https://gustavo.bp:8088";
|
||||||
} else {
|
} else {
|
||||||
credentials.BITPAY_API_URL = "https://bitpay.com";
|
credentials.BITPAY_API_URL = "https://bitpay.com";
|
||||||
};
|
};
|
||||||
|
|
@ -102,16 +102,13 @@ angular.module('copayApp.services').factory('mercadoLibreService', function($htt
|
||||||
};
|
};
|
||||||
|
|
||||||
root.createBitPayInvoice = function(data, cb) {
|
root.createBitPayInvoice = function(data, cb) {
|
||||||
|
|
||||||
// TODO
|
|
||||||
var dataSrc = {
|
var dataSrc = {
|
||||||
currency: 'USD' || data.currency,
|
currency: data.currency,
|
||||||
amount: data.amount,
|
amount: data.amount,
|
||||||
clientId: data.uuid
|
clientId: data.uuid
|
||||||
};
|
};
|
||||||
console.log('[mercadoLibreService.js:106]',dataSrc); //TODO
|
|
||||||
|
|
||||||
$http(_postBitPay('/amazon-gift/pay', dataSrc)).then(function(data) {
|
$http(_postBitPay('/mercado-libre-gift/pay', dataSrc)).then(function(data) {
|
||||||
$log.info('BitPay Create Invoice: SUCCESS');
|
$log.info('BitPay Create Invoice: SUCCESS');
|
||||||
return cb(null, data.data);
|
return cb(null, data.data);
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
|
|
@ -131,22 +128,6 @@ console.log('[mercadoLibreService.js:106]',dataSrc); //TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
root.createGiftCard = function(data, cb) {
|
root.createGiftCard = function(data, cb) {
|
||||||
console.log('[mercadoLibreService.js:132]',data); //TODO
|
|
||||||
|
|
||||||
return cb(null, {
|
|
||||||
"id": "f2bd6204fc49661a56057d33e37e32f2518ae92eea2f5457c379434712e35537",
|
|
||||||
"currency_id": data.currency,
|
|
||||||
"external_reference": "external_id_123456",
|
|
||||||
"initial_amount": data.amount,
|
|
||||||
"balance": 59.99,
|
|
||||||
"status": "active",
|
|
||||||
"date_creation": "20170314T10:39:14.82603:00",
|
|
||||||
"date_activation": "20170314T10:39:15.31603:00",
|
|
||||||
"date_expiration": "20180914T10:39:15.31603:00",
|
|
||||||
"date_last_updated": "20170314T10:39:15.32103:00",
|
|
||||||
"pin": "UYNHSIONUY"
|
|
||||||
});
|
|
||||||
|
|
||||||
var dataSrc = {
|
var dataSrc = {
|
||||||
"clientId": data.uuid,
|
"clientId": data.uuid,
|
||||||
"invoiceId": data.invoiceId,
|
"invoiceId": data.invoiceId,
|
||||||
|
|
@ -164,6 +145,10 @@ console.log('[mercadoLibreService.js:132]',data); //TODO
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Disabled for now *
|
||||||
|
*/
|
||||||
|
/*
|
||||||
root.cancelGiftCard = function(data, cb) {
|
root.cancelGiftCard = function(data, cb) {
|
||||||
|
|
||||||
var dataSrc = {
|
var dataSrc = {
|
||||||
|
|
@ -180,6 +165,7 @@ console.log('[mercadoLibreService.js:132]',data); //TODO
|
||||||
return cb(data.data);
|
return cb(data.data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
var register = function() {
|
var register = function() {
|
||||||
storageService.getMercadoLibreGiftCards(root.getNetwork(), function(err, giftCards) {
|
storageService.getMercadoLibreGiftCards(root.getNetwork(), function(err, giftCards) {
|
||||||
|
|
|
||||||
|
|
@ -767,12 +767,14 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
if (opts.hasFunds) {
|
if (opts.hasFunds) {
|
||||||
ret = lodash.filter(ret, function(w) {
|
ret = lodash.filter(ret, function(w) {
|
||||||
|
if (!w.status) return;
|
||||||
return (w.status.availableBalanceSat > 0);
|
return (w.status.availableBalanceSat > 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.minAmount) {
|
if (opts.minAmount) {
|
||||||
ret = lodash.filter(ret, function(w) {
|
ret = lodash.filter(ret, function(w) {
|
||||||
|
if (!w.status) return;
|
||||||
return (w.status.availableBalanceSat > opts.minAmount);
|
return (w.status.availableBalanceSat > opts.minAmount);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,29 +32,40 @@
|
||||||
</div>
|
</div>
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div ng-show="totalAmountStr">
|
||||||
|
<div class="item item-divider" translate>
|
||||||
|
Details
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<span translate>Network fee</span>
|
||||||
|
<span class="item-note">
|
||||||
|
{{totalFeeStr}}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<span translate>Total to pay</span>
|
||||||
|
<span class="item-note">
|
||||||
|
{{totalAmountStr}}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
|
||||||
<click-to-accept
|
<click-to-accept
|
||||||
ng-disabled="!wallet"
|
is-disabled="!wallet || !totalAmountStr"
|
||||||
ng-click="buyConfirm()"
|
ng-click="buyConfirm()"
|
||||||
ng-if="!isCordova"
|
ng-if="!isCordova"
|
||||||
click-send-status="sendStatus"
|
click-send-status="sendStatus">
|
||||||
has-wallet-chosen="wallet"
|
|
||||||
insufficient-funds="false"
|
|
||||||
no-matching-wallet="false">
|
|
||||||
Confirm purchase
|
Confirm purchase
|
||||||
</click-to-accept>
|
</click-to-accept>
|
||||||
<slide-to-accept
|
<slide-to-accept
|
||||||
ng-disabled="!wallet"
|
ng-if="isCordova && wallet && totalAmountStr"
|
||||||
ng-if="isCordova"
|
|
||||||
slide-on-confirm="buyConfirm()"
|
slide-on-confirm="buyConfirm()"
|
||||||
slide-send-status="sendStatus"
|
slide-send-status="sendStatus">
|
||||||
has-wallet-chosen="wallet"
|
|
||||||
insufficient-funds="false"
|
|
||||||
no-matching-wallet="false">
|
|
||||||
Slide to buy
|
Slide to buy
|
||||||
</slide-to-accept>
|
</slide-to-accept>
|
||||||
<slide-to-accept-success
|
<slide-to-accept-success
|
||||||
|
|
@ -70,7 +81,7 @@
|
||||||
<span ng-show="mlGiftCard.status == 'SUCCESS' || mlGiftCard.status == 'active'">
|
<span ng-show="mlGiftCard.status == 'SUCCESS' || mlGiftCard.status == 'active'">
|
||||||
Bought {{mlGiftCard.amount}} {{mlGiftCard.currency}}
|
Bought {{mlGiftCard.amount}} {{mlGiftCard.currency}}
|
||||||
</span>
|
</span>
|
||||||
<div class="m10 size-14" ng-show="mlGiftCard.status == 'SUCCESS' || mlGiftCard.status == 'active'">
|
<div class="m10 size-14" ng-show="mlGiftCard.status == 'SUCCESS' || mlGiftCard.cardStatus == 'active'">
|
||||||
Gift card generated and ready to use.
|
Gift card generated and ready to use.
|
||||||
</div>
|
</div>
|
||||||
</slide-to-accept-success>
|
</slide-to-accept-success>
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,13 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="m10t">
|
<div class="m10t">
|
||||||
Created
|
<span translate>Created</span>
|
||||||
{{card.date | amTimeAgo}}
|
{{card.date | amTimeAgo}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div ng-show="card.claimCode">
|
<div ng-show="card.pin">
|
||||||
<div ng-show="card.cardStatus !== 'Canceled'">
|
<div ng-show="card.cardStatus !== 'inactive' && card.cardStatus !== 'expired'">
|
||||||
Claim code: <span class="text-bold" copy-to-clipboard="card.pin">{{card.pin}}</span>
|
Claim code: <span class="text-bold" copy-to-clipboard="card.pin">{{card.pin}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="m10t" ng-show="card.status == 'active'">
|
<div class="m10t" ng-show="card.status == 'active'">
|
||||||
|
|
@ -35,16 +35,16 @@
|
||||||
Redeem Now
|
Redeem Now
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="m10t" ng-show="card.cardStatus == 'Canceled'">
|
<div class="m10t" ng-show="card.cardStatus == 'inactive'">
|
||||||
<div class="m10t">
|
<div class="m10t">
|
||||||
Status:
|
Status:
|
||||||
<span class="text-bold">
|
<span class="text-bold">
|
||||||
CANCELED
|
Inactive
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="!card.claimCode">
|
<div ng-show="!card.pin">
|
||||||
<div class="m10t">
|
<div class="m10t">
|
||||||
Status:
|
Status:
|
||||||
<span class="text-bold" ng-show="card.status == 'PENDING'">
|
<span class="text-bold" ng-show="card.status == 'PENDING'">
|
||||||
|
|
@ -72,9 +72,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="list text-center">
|
<div class="list text-center">
|
||||||
<a class="item" ng-show="card.status == 'SUCCESS' && card.cardStatus == 'Fulfilled'" ng-click="cancelGiftCard()">
|
|
||||||
<span class="assertive">Cancel</span>
|
|
||||||
</a>
|
|
||||||
<a class="item" ng-show="card.status == 'FAILURE' || card.cardStatus == 'Canceled'
|
<a class="item" ng-show="card.status == 'FAILURE' || card.cardStatus == 'Canceled'
|
||||||
|| card.cardStatus == 'Expired' || card.status == 'expired'" ng-click="remove()">
|
|| card.cardStatus == 'Expired' || card.status == 'expired'" ng-click="remove()">
|
||||||
<span class="assertive">Remove</span>
|
<span class="assertive">Remove</span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue