Bitpay card config external json

This commit is contained in:
Gustavo Maximiliano Cortez 2016-10-07 19:21:46 -03:00
commit 222fbe57ff
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
7 changed files with 73 additions and 8 deletions

View file

@ -1,5 +1,5 @@
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
var checkOtp = function(obj, cb) {
if (obj.otp) {
@ -48,7 +48,10 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
});
});
} else {
// TODO
// TEST TODO
bitpayCardService.testSession(function(err, session) {
if (err) $log.error(err);
});
}
/*

View file

@ -1,24 +1,29 @@
'use strict';
angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, lodash, storageService, bitauthService, platformInfo) {
angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, $window, lodash, storageService, bitauthService, platformInfo) {
var root = {};
var credentials = {};
var bpSession = {};
var pubkey, sin;
var _setCredentials = function() {
if (!$window.externalServices || !$window.externalServices.bitpayCard) {
return;
}
var bitpayCard = $window.externalServices.bitpayCard;
/*
* Development: 'testnet'
* Production: 'livenet'
*/
credentials.NETWORK = 'livenet';
if (credentials.NETWORK == 'testnet') {
credentials.BITPAY_PRIV_KEY = '';
credentials.BITPAY_API_URL = 'https://test.bitpay.com';
credentials.BITPAY_PRIV_KEY = bitpayCard.sandbox.secret;
credentials.BITPAY_API_URL = bitpayCard.sandbox.host;
}
else {
credentials.BITPAY_PRIV_KEY = '';
credentials.BITPAY_API_URL = 'https://bitpay.com';
credentials.BITPAY_PRIV_KEY = bitpayCard.production.secret;
credentials.BITPAY_API_URL = bitpayCard.production.host;
}
try {
pubkey = bitauthService.getPublicKeyFromPrivateKey(credentials.BITPAY_PRIV_KEY);
@ -87,6 +92,12 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
return credentials.BITPAY_API_URL;
};
root.testSession = function(cb) {
_getSession(function(err, session) {
return cb(err, session);
});
};
var _postBitAuth = function(endpoint, data) {
var dataToSign = credentials.BITPAY_API_URL + endpoint + JSON.stringify(data);
var signedData = bitauthService.sign(dataToSign, credentials.BITPAY_PRIV_KEY);

View file

@ -70,6 +70,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
// Plain URL
} else if (/^https?:\/\//.test(data)) {
if ($state.current.name == 'tabs.bitpayCardIntro' || $state.current.name == 'tabs.buyandsell.glidera') return false;
$state.go('tabs.send');
$timeout(function() {
$state.transitionTo('tabs.send.confirm', {paypro: data});