Merge pull request #4235 from cmgustavo/feat/amazon-gc-integration

Integration with AGCOD
This commit is contained in:
Matias Alejo Garcia 2016-08-09 12:27:45 -03:00 committed by GitHub
commit 0fb41843f6
23 changed files with 1044 additions and 13 deletions

View file

@ -52,7 +52,7 @@ module.exports = function(grunt) {
},
},
css: {
files: ['src/css/*.css'],
files: ['src/sass/*.css', 'src/css/*.css'],
tasks: ['concat:css']
},
sass: {

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
public/img/a_generic.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

88
public/views/amazon.html Normal file
View file

@ -0,0 +1,88 @@
<div class="topbar-container">
<nav ng-controller="topbarController as topbar"
class="tab-bar">
<section class="left-small">
<a class="p10"
ng-click="topbar.goHome()">
<span class="text-close">Close</span>
</a>
</section>
<section class="middle tab-bar-section">
<h1 class="title ellipsis">
Gift cards
</h1>
</section>
</nav>
</div>
<div class="content amazon p20b" ng-controller="amazonController as amazon">
<div ng-init="amazon.init()">
<div class="box-notification text-center size-12 text-warning" ng-show="amazon.sandbox">
<i class="fi-info"></i>
Sandbox version. Only for testing purpose
</div>
<div class="m20t text-center" ng-click="amazon.updatePendingGiftCards()">
<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>
<div ng-if="!giftCards" class="m20t text-center size-12">
<div class="row">
<div class="columns">
<button class="m20t button black round expand"
ui-sref="buyAmazon">
Buy now
</button>
</div>
</div>
<div class="text-left p10h m30v">
Amazon.com Gift Cards never expire and can be redeemed towards millions of items at
<a ng-click="$root.openExternalLink('https://www.amazon.com')">www.amazon.com</a>
</div>
</div>
<div class="p20t" ng-if="giftCards">
<ul class="no-bullet m0 size-14">
<li class="line-b line-t p10 pointer" href ui-sref="buyAmazon">
<i class="fi-shopping-cart size-24 m5l vm dib"></i>
<span class="m10l text-normal text-bold">Buy Gift Card</span>
<span class="right text-gray m5t">
<i class="icon-arrow-right3 size-24 right"></i>
</span>
</li>
</ul>
<h4 class="title">Your cards</h4>
<div ng-repeat="(id, item) in giftCards | orderObjectBy:'date':true track by $index"
ng-click="amazon.openCardModal(item)"
class="row collapse last-transactions-content size-12">
<div class="large-2 medium-2 small-2 columns">
<img src="img/a-smile_color_btn.png" alt="{{id}}" width="40">
</div>
<div class="large-4 medium-4 small-4 columns m5t size-18" ng-if="item.claimCode">
{{item.amount | currency : '$ ' : 2}}
</div>
<div class="large-4 medium-4 small-4 columns m5t size-18" ng-if="!item.claimCode">
-
</div>
<div class="large-5 medium-5 small-5 columns text-right m10t">
<span class="text-warning" ng-if="item.status == 'FAILURE' || item.status == 'RESEND'">Error</span>
<span class="text-gray" ng-if="item.status == 'PENDING'">Pending to confirmation</span>
<span class="text-gray" ng-if="item.status == 'SUCCESS' && item.cardStatus == 'Canceled'">Canceled</span>
<span class="text-gray" ng-if="item.status == 'SUCCESS' && item.cardStatus == 'Fulfilled'">{{item.date | amTimeAgo}}</span>
</div>
<div class="large-1 medium-1 small-1 columns text-right m10t">
<i class="icon-arrow-right3 size-18"></i>
</div>
</div>
</div>
</div>
<div class="extra-margin-bottom"></div>
</div>

166
public/views/buyAmazon.html Normal file
View file

@ -0,0 +1,166 @@
<div
class="topbar-container"
ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Buy'; goBackToState = 'amazon'; noColor = true">
</div>
<div class="content amazon" ng-controller="buyAmazonController as buy">
<div class="row m10t" ng-show="!buy.giftCard" ng-init="buy.init()">
<div class="columns">
<div class="box-notification m20b" ng-show="buy.error" ng-click="buy.error = null">
<span class="text-warning">
{{buy.error}}
</span>
<div class="m10t size-12" ng-show="buy.errorInfo">
There was an error when trying to buy gift card, but the funds were sent to BitPay Invoice. Please, contact
BitPay to refund your bitcoin
<div class="p10 m10t">
Amount: {{buy.errorInfo.amount}} {{buy.errorInfo.currency}}<br>
BitPay Invoice ID: {{buy.errorInfo.invoiceId}}.
</div>
<div class="text-center">
<a ng-click="$root.openExternalLink(buy.errorInfo.invoiceUrl)">Open invoice</a>
</div>
</div>
</div>
<div class="text-center">
<img src="img/a_generic.jpg" alt="Amazon.com Gift Card" width="180">
<div class="text-left size-10 m10t">
Use your Amazon.com Gift Card* to shop from a huge selection of books, electronics, music, movies, software, apparel, toys, and more.
</div>
</div>
<form
class="m30v"
name="buyAmazonForm"
ng-submit="buy.createTx()"
novalidate>
<label>
Amount
</label>
<div class="input">
<input type="number" id="fiat"
name="fiat" ng-attr-placeholder="{{'Amount in USD'}}"
min="0.01" max="500"
ng-model="fiat" autocomplete="off" required>
<a class="postfix button black">USD</a>
</div>
<div class="m10b">
<label>Pay From Copay Wallet</label>
<div class="input">
<input type="text" id="address" name="address" ng-disabled="buy.selectedWalletId"
ng-attr-placeholder="{{'Choose your source wallet'}}"
ng-model="buy.selectedWalletName" required>
<a ng-click="openWalletsModal(buy.allWallets)" class="postfix size-12 m0 text-gray">
<i class="icon-wallet size-18"></i>
</a>
</div>
</div>
<div class="input m20t">
<input class="button black round expand"
ng-disabled="!buy.selectedWalletId || !fiat"
type="submit" value="Buy now">
<div class="size-10 text-gray text-center">
Purchase Amount is limited to USD 500 per day
</div>
</div>
</form>
</div>
</div>
<div class="m10t" ng-show="buy.giftCard">
<div class="m10h" ng-show="buy.giftCard.status != 'SUCCESS' && buy.giftCard.status != 'PENDING'">
<h1 class="text-center">Gift card could not be created</h1>
<div class="box-notification m20b">
<span class="text-warning">
There was an error when trying to create the Amazon.com Gift Card. Status: {{buy.giftCard.status}}
</span>
</div>
<div class="text-gray size-12 m20t">
<span ng-show="buy.giftCard.status == 'RESEND'">
This is a temporary/recoverable system failure that can be
resolved retrying the request from your list of cards
</span>
<span ng-show="buy.giftCard.status == 'FAILURE'">
This failure could not be recoverable. Request your refund from your list of cards
</span>
<button class="m20t button outline round dark-gray expand" ng-click="$root.go('amazon')">
Back
</button>
</div>
</div>
<div ng-show="buy.giftCard.status == 'SUCCESS'">
<div class="size-12 p15h">
Thank you for participating in the BitPay offer. It is our pleasure to send
you this Amazon.com Gift Card* that can be redeemed towards millions of items at
<a ng-click="$root.openExternalLink('https://www.amazon.com')">www.amazon.com</a>.
You may want to print this screen for easy reference later you will need the gift card claim code below.
</div>
<div class="oh m20t p15 white size-12 text-center">
<img class="m10h" src="img/a_generic.jpg" alt="Amazon.com Gift Cards" width="200">
<div class="m10t size-14">
Gift Card Amount:
<span class="text-bold">
{{buy.giftCard.amount | currency : '$ ' : 2 }}
</span>
</div>
<div class="size-14">
Claim code: <span class="text-bold enable_text_select">{{buy.giftCard.claimCode}}</span>
</div>
<div class="m10t">
<button class="button black round tiny"
ng-click="$root.openExternalLink('https://www.amazon.com/gc/redeem?claimCode=' + buy.giftCard.claimCode, '_system')">
Redeem Now
</button>
</div>
<div class="size-12 m10t text-center">
<a ng-click="$root.openExternalLink(buy.giftCard.invoiceUrl)">See invoice</a>
</div>
</div>
<div class="oh m20t p15h size-12">
To redeem your gift card, follow these steps:
<ol class="m10t size-12">
<li>1. Visit <a ng-click="$root.openExternalLink('https://www.amazon.com/gc')">www.amazon.com/gc</a>
<li>2. Click Apply to Account and enter the Claim Code when prompted.
<li>3. Gift card funds will be applied automatically to eligible orders during the checkout process.
<li>4. You must pay for any remaining balance on your order with another payment method.
</ol>
<p class="size-12">
Your gift card claim code may also be entered when prompted during checkout. To redeem your gift card using
the Amazon.com 1-Click&reg; service, first add the gift card funds to Your Account.
</p>
<p class="size-12">
If you have questions about redeeming your gift card, please visit
<a ng-click="$root.openExternalLink('https://www.amazon.com/gc-redeem')">www.amazon.com/gc-redeem</a>.
If you have questions regarding the BitPay Introductory offer, please contact BitPay.
</p>
</div>
</div>
</div>
<div class="size-12 white p15 m20t">
* <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a> is not a sponsor of this promotion.
Except as required by law, <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a>
Gift Cards ("GCs") cannot be transferred for value or redeemed for cash. GCs may be used only for purchases of
eligible goods at <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a> or certain of its
affiliated websites. For complete terms and conditions, see
<a ng-click="$root.openExternalLink('https://www.amazon.com/gc-legal')">www.amazon.com/gc-legal</a>.
GCs are issued by ACI Gift Cards, Inc., a Washington corporation. All Amazon &reg;, &trade; &amp; &copy; are IP
of <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a>, Inc. or its affiliates.
No expiration date or service fees.
</div>
</div>
<div class="extra-margin-bottom"></div>

View file

@ -31,7 +31,7 @@
</button>
</div>
<div class="half-row left">
<button ng-click="accept()" class="round expand" ng-style="{'background-color':index.backgroundColor}" autofocus>
<button ng-click="accept()" class="round expand" ng-style="{'background-color': color}" autofocus>
<span class="size-12" translate>Confirm</span>
</button>
</div>

View file

@ -30,6 +30,13 @@
<span class="size-12" translate>Buy and Sell</span>
</div>
</li>
<li menu-toggle href ui-sref="amazon" ng-show="index.isComplete">
<i class="icon-arrow-right3 size-18 right m10t vm"></i>
<i class="fi-shopping-bag size-24 icon vm"></i>
<div class="tu text-bold m10t">
<span class="size-12" translate>Gift Cards</span>
</div>
</li>
<li ng-show="!index.noFocusedWallet" menu-toggle href ui-sref="preferencesGlobal">
<i class="icon-arrow-right3 size-18 right m10t vm"></i>
<i class="fi-widget size-24 icon vm"></i>

View file

@ -0,0 +1,119 @@
<ion-modal-view ng-controller="amazonCardDetailsController">
<ion-header-bar align-title="center" class="tab-bar">
<div class="left-small">
<a ng-click="cancel()" class="p10">
<span class="text-close">Close</span>
</a>
</div>
<h1 class="title ellipsis">
Details
</h1>
</ion-header-bar>
<ion-content>
<div class="modal-content">
<div class="header-modal text-center">
<img src="img/a_generic.jpg" alt="Amazon.com Gift Card" width="230" ng-click="refreshGiftCard()">
<div ng-show="card.claimCode">
<div class="m10t">
Gift Card Amount:
<span class="text-bold">
{{card.amount | currency : '$ ' : 2}}
</span>
</div>
<div ng-show="card.cardStatus !== 'Canceled'">
Claim code: <span class="text-bold enable_text_select">{{card.claimCode}}</span>
</div>
<div class="m10t" ng-show="card.cardStatus == 'Fulfilled'">
<button class="button black round tiny"
ng-click="$root.openExternalLink('https://www.amazon.com/gc/redeem?claimCode=' + card.claimCode, '_system')">
Redeem Now
</button>
</div>
<div class="m10t" ng-show="card.cardStatus == 'Canceled'">
<div class="m10t">
Status:
<span class="text-bold">
CANCELED
</span>
</div>
</div>
</div>
<div ng-show="!card.claimCode">
<div class="m10t">
Status:
<span class="text-bold" ng-show="card.status == 'PENDING'">
PENDING
</span>
<span class="text-bold" ng-show="card.status == 'FAILURE' || card.status == 'RESEND'">
FAILURE
</span>
</div>
</div>
<div class="size-12 m10t text-center">
<a ng-click="$root.openExternalLink(card.invoiceUrl)">See invoice</a>
</div>
</div>
<div class="box-notification m20b" ng-show="error" ng-click="error = null">
<span class="text-warning">
{{error}}
</span>
</div>
<div class="text-center size-12 text-warning m10" ng-show="card.status == 'FAILURE' || card.status == 'RESEND'">
There was a failure to the create gift card. Please, contact BitPay support.
</div>
<div class="oh m20t size-12 p15h" ng-show="card.claimCode && card.cardStatus == 'Fulfilled'">
To redeem your gift card, follow these steps:
<ol class="m10t size-12">
<li>1. Visit <a ng-click="$root.openExternalLink('https://www.amazon.com/gc')">www.amazon.com/gc</a>
<li>2. Click Apply to Account and enter the Claim Code when prompted.
<li>3. Gift card funds will be applied automatically to eligible orders during the checkout process.
<li>4. You must pay for any remaining balance on your order with another payment method.
</ol>
<p class="size-12">
Your gift card claim code may also be entered when prompted during checkout. To redeem your gift card using
the Amazon.com 1-Click&reg; service, first add the gift card funds to Your Account.
</p>
<p class="size-12">
If you have questions about redeeming your gift card, please visit
<a ng-click="$root.openExternalLink('https://www.amazon.com/gc-redeem')">www.amazon.com/gc-redeem</a>.
If you have questions regarding the BitPay Introductory offer, please contact BitPay.
</p>
</div>
<div class="size-12 white p15 m30v">
* <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a> is not a sponsor of this promotion.
Except as required by law, <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a>
Gift Cards ("GCs") cannot be transferred for value or redeemed for cash. GCs may be used only for purchases of
eligible goods at <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a> or certain of its
affiliated websites. For complete terms and conditions, see
<a ng-click="$root.openExternalLink('https://www.amazon.com/gc-legal')">www.amazon.com/gc-legal</a>.
GCs are issued by ACI Gift Cards, Inc., a Washington corporation. All Amazon &reg;, &trade; &amp; &copy; are IP
of <a ng-click="$root.openExternalLink('http://amazon.com')">Amazon.com</a>, Inc. or its affiliates.
No expiration date or service fees.
</div>
<ul class="no-bullet size-14 m30v text-center">
<li class="line-b p10 oh pointer" ng-show="card.status == 'SUCCESS' && card.cardStatus == 'Fulfilled'" ng-click="cancelGiftCard()">
<span class="text-warning">Cancel</span>
</li>
<li class="line-b p10 oh pointer" ng-show="card.status == 'FAILURE' || card.cardStatus == 'Canceled'
|| card.cardStatus == 'Expired'" ng-click="remove()">
<span class="text-warning">Remove</span>
</li>
</ul>
<div class="extra-margin-bottom"></div>
</div>
</ion-content>
</ion-modal-view>

View file

@ -11,7 +11,8 @@
</h1>
</ion-header-bar>
<ion-content>
<ion-content ng-style="{'background-color': '#F6F7F9'}">
<div class="modal-content">
<div class="box-notification text-center size-12 text-warning m10t" ng-show="error">
<i class="fi-error"></i> {{error}}

View file

@ -25,7 +25,6 @@
</div>
</div>
<div class="oh" ng-show="!index.noFocusedWallet">
<!--

View file

@ -0,0 +1,83 @@
'use strict';
angular.module('copayApp.controllers').controller('amazonController',
function($scope, $timeout, $ionicModal, $log, lodash, bwcError, amazonService) {
this.init = function() {
var self = this;
self.sandbox = amazonService.getEnvironment() == 'testnet' ? true : false;
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
self.error = err;
return;
}
$scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
$timeout(function() {
$scope.$digest();
});
});
this.updatePendingGiftCards();
}
this.updatePendingGiftCards = lodash.debounce(function() {
var self = this;
amazonService.getPendingGiftCards(function(err, gcds) {
lodash.forEach(gcds, function(dataFromStorage) {
if (dataFromStorage.status == 'PENDING') {
$log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) {
$log.debug(bwcError.msg(err));
return;
}
if (giftCard.status != 'PENDING') {
var newData = {};
lodash.merge(newData, dataFromStorage, giftCard);
if (newData.status == 'expired') {
amazonService.savePendingGiftCard(newData, {
remove: true
}, function(err) {
return;
});
}
amazonService.savePendingGiftCard(newData, null, function(err) {
$log.debug("Saving new gift card");
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
self.error = err;
return;
}
$scope.giftCards = gcds;
$timeout(function() {
$scope.$digest();
});
});
});
} else $log.debug("pending gift card not available yet");
});
}
});
});
}, 1000);
this.openCardModal = function(card) {
var self = this;
$scope.card = card;
$ionicModal.fromTemplateUrl('views/modals/amazon-card-details.html', {
scope: $scope
}).then(function(modal) {
$scope.amazonCardDetailsModal = modal;
$scope.amazonCardDetailsModal.show();
});
$scope.$on('UpdateAmazonList', function(event) {
self.init();
});
};
});

View file

@ -0,0 +1,296 @@
'use strict';
angular.module('copayApp.controllers').controller('buyAmazonController',
function($rootScope, $scope, $ionicModal, $log, $timeout, $state, lodash, profileService, bwcError, gettext, configService, walletService, fingerprintService, amazonService, ongoingProcess) {
var self = this;
var client;
var handleEncryptedWallet = function(client, cb) {
if (!walletService.isEncrypted(client)) return cb();
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
if (err) return cb(err);
return cb(walletService.unlock(client, password));
});
};
this.init = function() {
var network = amazonService.getEnvironment();
self.allWallets = profileService.getWallets(network, 1);
client = profileService.focusedClient;
if (!client) return;
if (lodash.isEmpty(self.allWallets)) return;
if (client.credentials.network != network) return;
$timeout(function() {
self.selectedWalletId = client.credentials.walletId;
self.selectedWalletName = client.credentials.walletName;
$scope.$apply();
}, 100);
};
$scope.openWalletsModal = function(wallets) {
self.error = null;
$scope.type = 'SELL';
$scope.wallets = wallets;
$scope.self = self;
$ionicModal.fromTemplateUrl('views/modals/wallets.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.walletsModal = modal;
$scope.walletsModal.show();
});
$scope.$on('walletSelected', function(ev, walletId) {
$timeout(function() {
client = profileService.getClient(walletId);
self.selectedWalletId = walletId;
self.selectedWalletName = client.credentials.walletName;
$scope.$apply();
}, 100);
$scope.walletsModal.hide();
});
};
this.createTx = function() {
self.error = null;
self.errorInfo = null;
var dataSrc = {
currency: 'USD',
amount: $scope.fiat,
uuid: self.selectedWalletId
};
var outputs = [];
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
ongoingProcess.set('Processing Transaction...', true);
$timeout(function() {
amazonService.createBitPayInvoice(dataSrc, function(err, dataInvoice) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
return;
}
amazonService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
return;
}
$log.debug('Fetch PayPro Request...', invoice.paymentUrls.BIP73);
client.fetchPayPro({
payProUrl: invoice.paymentUrls.BIP73,
}, function(err, paypro) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
$log.warn('Could not fetch payment request:', err);
var msg = err.toString();
if (msg.match('HTTP')) {
msg = gettext('Could not fetch payment information');
}
self.error = msg;
$timeout(function() {
$scope.$digest();
});
return;
}
if (!paypro.verified) {
ongoingProcess.set('Processing Transaction...', false);
$log.warn('Failed to verify payment protocol signatures');
self.error = gettext('Payment Protocol Invalid');
$timeout(function() {
$scope.$digest();
});
return;
}
var address, comment, amount, url;
address = paypro.toAddress;
amount = paypro.amount;
url = paypro.url;
comment = 'Amazon.com Gift Card';
outputs.push({
'toAddress': address,
'amount': amount,
'message': comment
});
var txp = {
toAddress: address,
amount: amount,
outputs: outputs,
message: comment,
payProUrl: url,
excludeUnconfirmedUtxos: configWallet.spendUnconfirmed ? false : true,
feeLevel: walletSettings.feeLevel || 'normal'
};
walletService.createTx(client, txp, function(err, createdTxp) {
ongoingProcess.set('Processing Transaction...', false);
if (err) {
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
return;
}
$scope.$emit('Local/NeedsConfirmation', createdTxp, function(accept) {
if (accept) {
self.confirmTx(createdTxp, function(err, tx) {
if (err) {
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
$timeout(function() {
$scope.$digest();
});
return;
}
var count = 0;
ongoingProcess.set('Processing Transaction...', true);
dataSrc.accessKey = dataInvoice.accessKey;
dataSrc.invoiceId = invoice.id;
dataSrc.invoiceUrl = invoice.url;
dataSrc.invoiceTime = invoice.invoiceTime;
self.debounceCreate(count, dataSrc);
});
}
});
});
});
});
});
}, 100);
};
self.debounceCreate = lodash.throttle(function(count, dataSrc) {
self.debounceCreateGiftCard(count, dataSrc);
}, 8000, {
'leading': true
});
self.debounceCreateGiftCard = function(count, dataSrc) {
amazonService.createGiftCard(dataSrc, function(err, giftCard) {
$log.debug("creating gift card " + count);
if (err) {
giftCard = {};
giftCard.status = 'FAILURE';
ongoingProcess.set('Processing Transaction...', false);
self.error = bwcError.msg(err);
self.errorInfo = dataSrc;
$timeout(function() {
$scope.$digest();
});
}
if (giftCard.status == 'PENDING' && count < 3) {
$log.debug("pending gift card not available yet");
self.debounceCreate(count + 1, dataSrc, dataSrc);
return;
}
var now = moment().unix() * 1000;
var newData = giftCard;
newData['invoiceId'] = dataSrc.invoiceId;
newData['accessKey'] = dataSrc.accessKey;
newData['invoiceUrl'] = dataSrc.invoiceUrl;
newData['amount'] = dataSrc.amount;
newData['date'] = dataSrc.invoiceTime || now;
newData['uuid'] = dataSrc.uuid;
if (newData.status == 'expired') {
amazonService.savePendingGiftCard(newData, {
remove: true
}, function(err) {
return;
});
}
amazonService.savePendingGiftCard(newData, null, function(err) {
ongoingProcess.set('Processing Transaction...', false);
$log.debug("Saving new gift card with status: " + newData.status);
self.giftCard = newData;
if (newData.status == 'PENDING') $state.transitionTo('amazon');
$timeout(function() {
$scope.$digest();
});
});
});
}
this.confirmTx = function(txp, cb) {
fingerprintService.check(client, function(err) {
if (err) {
$log.debug(err);
return cb(err);
}
handleEncryptedWallet(client, function(err) {
if (err) {
$log.debug(err);
return bwcError.cb(err, null, cb);
}
ongoingProcess.set('Processing Transaction...', true);
walletService.publishTx(client, txp, function(err, publishedTxp) {
if (err) {
$log.debug(err);
return bwcError.cb(err, null, cb);
}
walletService.signTx(client, publishedTxp, function(err, signedTxp) {
walletService.lock(client);
if (err) {
$log.debug(err);
walletService.removeTx(client, signedTxp, function(err) {
if (err) $log.debug(err);
});
return bwcError.cb(err, null, cb);
}
walletService.broadcastTx(client, signedTxp, function(err, broadcastedTxp) {
if (err) {
$log.debug(err);
walletService.removeTx(client, broadcastedTxp, function(err) {
if (err) $log.debug(err);
});
return bwcError.cb(err, null, cb);
}
$timeout(function() {
return cb(null, broadcastedTxp);
}, 5000);
});
});
});
});
});
};
});

View file

@ -1,6 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, $ionicSideMenuDelegate, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwcError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService, ongoingProcess) {
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, $ionicSideMenuDelegate, $httpBackend, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwcError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService, ongoingProcess) {
var self = this;
var SOFT_CONFIRMATION_LIMIT = 12;
var errors = bwcService.getErrors();
@ -1688,6 +1689,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
function openConfirmationPopup(txp, cb) {
var config = configService.getSync();
$scope.color = config.colorFor[txp.walletId] || '#4A90E2';
$scope.tx = txFormatService.processTx(txp);
self.confirmationPopup = $ionicPopup.show({

View file

@ -132,9 +132,6 @@ angular.module('copayApp.controllers').controller('addressbookController', funct
else {
$scope.gettingAddress = true;
$scope.selectedWalletName = walletName;
$timeout(function() {
$scope.$apply();
});
addressService.getAddress(walletId, false, function(err, addr) {
$scope.gettingAddress = false;
@ -148,6 +145,9 @@ angular.module('copayApp.controllers').controller('addressbookController', funct
$scope.cancel();
});
}
$timeout(function() {
$scope.$apply();
});
});
};

View file

@ -0,0 +1,66 @@
'use strict';
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, bwcError, amazonService, lodash, ongoingProcess) {
$scope.cancelGiftCard = function() {
ongoingProcess.set('Canceling gift card...', true);
amazonService.cancelGiftCard($scope.card, function(err, data) {
ongoingProcess.set('Canceling gift card...', false);
if (err) {
$scope.error = bwcError.msg(err);
return;
}
$scope.card.cardStatus = data.cardStatus;
amazonService.savePendingGiftCard($scope.card, null, function(err) {
$scope.$emit('UpdateAmazonList');
});
});
};
$scope.remove = function() {
amazonService.savePendingGiftCard($scope.card, {
remove: true
}, function(err) {
$scope.$emit('UpdateAmazonList');
$scope.cancel();
});
};
$scope.refreshGiftCard = function() {
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
self.error = err;
return;
}
lodash.forEach(gcds, function(dataFromStorage) {
if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) {
$log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) {
self.error = bwcError.msg(err);
$log.debug(bwcError.msg(err));
return;
}
if (!lodash.isEmpty(giftCard)) {
var newData = {};
lodash.merge(newData, dataFromStorage, giftCard);
amazonService.savePendingGiftCard(newData, null, function(err) {
$log.debug("Saving new gift card");
$scope.card = newData;
$scope.$emit('UpdateAmazonList');
$timeout(function() {
$scope.$digest();
});
});
} else $log.debug("pending gift card not available yet");
});
}
});
});
};
$scope.cancel = function() {
$scope.amazonCardDetailsModal.hide();
};
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletsController', function($scope, bwcError, profileService) {
angular.module('copayApp.controllers').controller('walletsController', function($scope, $timeout, bwcError, profileService) {
$scope.selectWallet = function(walletId) {
@ -10,6 +10,9 @@ angular.module('copayApp.controllers').controller('walletsController', function(
profileService.isReady(client, function(err) {
if (err) {
$scope.errorSelectedWallet[walletId] = bwcError.msg(err);
$timeout(function() {
$scope.$apply();
});
return;
}

View file

@ -27,6 +27,8 @@ angular.element(document).ready(function() {
document.addEventListener('deviceready', function() {
window.open = cordova.InAppBrowser.open;
// Create a sticky event for handling the app being opened via a custom URL
cordova.addStickyDocumentEventHandler('handleopenurl');
startAngular();

View file

@ -315,6 +315,26 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
},
}
})
.state('amazon', {
url: '/amazon',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/amazon.html'
},
}
})
.state('buyAmazon', {
url: '/buyamazon',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/buyAmazon.html'
},
}
})
.state('preferencesAdvanced', {
url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html',

View file

@ -0,0 +1,146 @@
'use strict';
angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo) {
var root = {};
var credentials = {};
var _setCredentials = function() {
/*
* Development: 'testnet'
* Production: 'livenet'
*/
credentials.NETWORK = 'livenet';
if (credentials.NETWORK == 'testnet') {
credentials.BITPAY_API_URL = "https://test.bitpay.com";
} else {
credentials.BITPAY_API_URL = "https://bitpay.com";
};
};
var _getBitPay = function(endpoint) {
_setCredentials();
return {
method: 'GET',
url: credentials.BITPAY_API_URL + endpoint,
headers: {
'content-type': 'application/json'
}
};
};
var _postBitPay = function(endpoint, data) {
_setCredentials();
return {
method: 'POST',
url: credentials.BITPAY_API_URL + endpoint,
headers: {
'content-type': 'application/json'
},
data: data
};
};
root.getEnvironment = function() {
_setCredentials();
return credentials.NETWORK;
};
root.savePendingGiftCard = function(gc, opts, cb) {
var network = root.getEnvironment();
storageService.getAmazonGiftCards(network, function(err, oldGiftCards) {
if (lodash.isString(oldGiftCards)) {
oldGiftCards = JSON.parse(oldGiftCards);
}
if (lodash.isString(gc)) {
gc = JSON.parse(gc);
}
var inv = oldGiftCards || {};
inv[gc.invoiceId] = gc;
if (opts && (opts.error || opts.status)) {
inv[gc.invoiceId] = lodash.assign(inv[gc.invoiceId], opts);
}
if (opts && opts.remove) {
delete(inv[gc.invoiceId]);
}
inv = JSON.stringify(inv);
storageService.setAmazonGiftCards(network, inv, function(err) {
return cb(err);
});
});
};
root.getPendingGiftCards = function(cb) {
var network = root.getEnvironment();
storageService.getAmazonGiftCards(network, function(err, giftCards) {
var _gcds = giftCards ? JSON.parse(giftCards) : null;
return cb(err, _gcds);
});
};
root.createBitPayInvoice = function(data, cb) {
var dataSrc = {
currency: data.currency,
amount: data.amount,
clientId: data.uuid
};
$http(_postBitPay('/amazon-gift/pay', dataSrc)).then(function(data) {
$log.info('BitPay Create Invoice: SUCCESS');
return cb(null, data.data);
}, function(data) {
$log.error('BitPay Create Invoice: ERROR ' + data.data.message);
return cb(data.data);
});
};
root.getBitPayInvoice = function(id, cb) {
$http(_getBitPay('/invoices/' + id)).then(function(data) {
$log.info('BitPay Get Invoice: SUCCESS');
return cb(null, data.data.data);
}, function(data) {
$log.error('BitPay Get Invoice: ERROR ' + data.data.error);
return cb(data.data.error);
});
};
root.createGiftCard = function(data, cb) {
var dataSrc = {
"clientId": data.uuid,
"invoiceId": data.invoiceId,
"accessKey": data.accessKey
};
$http(_postBitPay('/amazon-gift/redeem', dataSrc)).then(function(data) {
var status = data.data.status == 'new' ? 'PENDING' : (data.data.status == 'paid') ? 'PENDING' : data.data.status;
data.data.status = status;
$log.info('Amazon.com Gift Card Create/Update: ' + status);
return cb(null, data.data);
}, function(data) {
$log.error('Amazon.com Gift Card Create/Update: ' + data.data.message);
return cb(data.data);
});
};
root.cancelGiftCard = function(data, cb) {
var dataSrc = {
"clientId": data.uuid,
"invoiceId": data.invoiceId,
"accessKey": data.accessKey
};
$http(_postBitPay('/amazon-gift/cancel', dataSrc)).then(function(data) {
$log.info('Amazon.com Gift Card Cancel: SUCCESS');
return cb(null, data.data);
}, function(data) {
$log.error('Amazon.com Gift Card Cancel: ' + data.data.message);
return cb(data.data);
});
};
return root;
});

View file

@ -139,6 +139,9 @@ angular.module('copayApp.services')
case 'PASSWORD_INCORRECT':
body = gettextCatalog.getString('Wrong spending password');
break;
case 'EXCEEDED_DAILY_LIMIT':
body = gettextCatalog.getString('Exceeded daily limit of $500 per user');
break;
case 'ERROR':
body = (err.message || err.error);
break;

View file

@ -268,11 +268,11 @@ angular.module('copayApp.services')
root.checkQuota = function() {
var block = '';
// 50MB
for (var i = 0; i < 1024*1024; ++ i){
for (var i = 0; i < 1024 * 1024; ++i) {
block += '12345678901234567890123456789012345678901234567890';
}
storage.set('test', block, function(err) {
$log.error('CheckQuota Return:'+ err);
$log.error('CheckQuota Return:' + err);
});
};
@ -318,5 +318,17 @@ angular.module('copayApp.services')
});
};
root.setAmazonGiftCards = function(network, gcs, cb) {
storage.set('amazonGiftCards-' + network, gcs, cb);
};
root.getAmazonGiftCards = function(network, cb) {
storage.get('amazonGiftCards-' + network, cb);
};
root.removeAmazonGiftCards = function(network, cb) {
storage.remove('amazonGiftCards-' + network, cb);
};
return root;
});

View file

@ -99,7 +99,7 @@ h4.title a {
}
}
.modal-content h4, .glidera h4, .coinbase h4 {
.modal-content h4, .glidera h4, .coinbase h4, .amazon h4 {
background: #F6F7F9;
padding: 25px 0px 5px 10px;
text-transform: uppercase;
@ -536,6 +536,10 @@ ul.manage li {
font-size: 24px;
}
.size-28 {
font-size: 28px;
}
.size-36 {
font-size: 36px;
}
@ -677,6 +681,10 @@ ul.manage li {
padding-left: 10px;
}
.p15h {
padding: 0 15px;
}
.p0r {
padding-right: 0;
}
@ -725,6 +733,10 @@ ul.manage li {
padding: 20px;
}
.p15t {
padding-top: 15px;
}
.p20t {
padding-top: 20px;
}
@ -781,6 +793,10 @@ ul.manage li {
margin: 20px 0;
}
.m30v {
margin: 30px 0;
}
.m30a {
margin: 30px auto;
}
@ -1655,7 +1671,7 @@ a.missing-copayers {
.sidebar {
background: #2C3E50;
.icon {
width: 39px;
width: 35px;
text-align: center;
margin-right: 15px;
float: left;