paypro: deal with cached payment requests properly.
This commit is contained in:
parent
af12b56678
commit
decd981bce
3 changed files with 16 additions and 15 deletions
|
|
@ -94,8 +94,12 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
&& copay.HDPath.parseBitcoinURI(address);
|
&& copay.HDPath.parseBitcoinURI(address);
|
||||||
|
|
||||||
if (uri && uri.merchant) {
|
if (uri && uri.merchant) {
|
||||||
var data = w.paymentRequests[uri.merchant];
|
var req = w.paymentRequests[uri.merchant];
|
||||||
if (data) {
|
if (req) {
|
||||||
|
if (commentText) {
|
||||||
|
req.options.memo = commentText;
|
||||||
|
}
|
||||||
|
w.receivePaymentRequest(req.options, req.pr, done);
|
||||||
} else {
|
} else {
|
||||||
w.createPaymentTx({
|
w.createPaymentTx({
|
||||||
uri: uri.merchant,
|
uri: uri.merchant,
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ angular.module('copayApp.directives')
|
||||||
var uri = copay.HDPath.parseBitcoinURI(value);
|
var uri = copay.HDPath.parseBitcoinURI(value);
|
||||||
|
|
||||||
if (uri && uri.merchant) {
|
if (uri && uri.merchant) {
|
||||||
// XXX This might be unwise, it might be better to
|
|
||||||
// create a tentative TX proposal here.
|
|
||||||
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
||||||
var txp = { merchant: merchantData };
|
var txp = { merchant: merchantData };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -870,6 +870,7 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = { uri: options };
|
options = { uri: options };
|
||||||
}
|
}
|
||||||
|
options.uri = options.uri || options.url;
|
||||||
|
|
||||||
if (options.uri.indexOf('bitcoin:') === 0) {
|
if (options.uri.indexOf('bitcoin:') === 0) {
|
||||||
options.uri = parseBitcoinURI(options.uri).merchant;
|
options.uri = parseBitcoinURI(options.uri).merchant;
|
||||||
|
|
@ -906,11 +907,13 @@ Wallet.prototype.fetchPaymentTx = function(options, cb) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = { uri: options };
|
options = { uri: options };
|
||||||
}
|
}
|
||||||
|
options.uri = options.uri || options.url;
|
||||||
options.fetch = true;
|
options.fetch = true;
|
||||||
|
if (this.paymentRequests[options.uri]) {
|
||||||
|
return cb(null, this.paymentRequests[options.uri].merchantData);
|
||||||
|
}
|
||||||
return this.createPaymentTx(options, function(err, merchantData, options, pr) {
|
return this.createPaymentTx(options, function(err, merchantData, options, pr) {
|
||||||
var id = self.hashMerchantData(merchantData);
|
self.paymentRequests[options.uri] = {
|
||||||
self.paymentRequests[id] = {
|
|
||||||
id: id,
|
|
||||||
merchantData: merchantData,
|
merchantData: merchantData,
|
||||||
options: options,
|
options: options,
|
||||||
pr: pr
|
pr: pr
|
||||||
|
|
@ -919,17 +922,13 @@ Wallet.prototype.fetchPaymentTx = function(options, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.hashMerchantData =
|
|
||||||
Wallet.prototype.hashMerchantData = function(merchantData) {
|
|
||||||
return merchantData.request_url
|
|
||||||
+ ':' + merchantData.pr.payment_url
|
|
||||||
+ ':' + merchantData.total
|
|
||||||
+ ':' + merchantData.pr.pd.merchant_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if (this.paymentRequests[options.uri]) {
|
||||||
|
delete this.paymentRequests[options.uri];
|
||||||
|
}
|
||||||
|
|
||||||
var ver = pr.get('payment_details_version');
|
var ver = pr.get('payment_details_version');
|
||||||
var pki_type = pr.get('pki_type');
|
var pki_type = pr.get('pki_type');
|
||||||
var pki_data = pr.get('pki_data');
|
var pki_data = pr.get('pki_data');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue