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,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);