Merge pull request #1410 from chjj/fix_paypro_sent
paypro: fix signature error. fix merchant_data. see #1409.
This commit is contained in:
commit
97af7c2fbc
3 changed files with 82 additions and 39 deletions
3
app.js
3
app.js
|
|
@ -20,6 +20,9 @@ app.start = function(port, callback) {
|
||||||
|
|
||||||
pserver.removeListener('request', pserver.app);
|
pserver.removeListener('request', pserver.app);
|
||||||
|
|
||||||
|
// pserver.options['no-tx'] = true;
|
||||||
|
// pserver.options['discovery'] = true;
|
||||||
|
|
||||||
pserver.on('request', function(req, res) {
|
pserver.on('request', function(req, res) {
|
||||||
if (req.url.indexOf('/-/') === 0) {
|
if (req.url.indexOf('/-/') === 0) {
|
||||||
return pserver.app(req, res);
|
return pserver.app(req, res);
|
||||||
|
|
|
||||||
|
|
@ -1303,7 +1303,14 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
||||||
return self.receivePaymentRequest(options, pr, cb);
|
return self.receivePaymentRequest(options, pr, cb);
|
||||||
})
|
})
|
||||||
.error(function(data, status, headers, config) {
|
.error(function(data, status, headers, config) {
|
||||||
return cb(new Error('Status: ' + status));
|
log.debug('Server was did not return PaymentRequest.');
|
||||||
|
log.debug('XHR status: ' + status);
|
||||||
|
if (options.fetch) {
|
||||||
|
return cb(new Error('Status: ' + status));
|
||||||
|
} else {
|
||||||
|
// Should never happen:
|
||||||
|
return cb(null, null, null);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1416,9 +1423,9 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
expires: expires,
|
expires: expires,
|
||||||
memo: memo || 'This server would like some BTC from you.',
|
memo: memo || 'This server would like some BTC from you.',
|
||||||
payment_url: payment_url,
|
payment_url: payment_url,
|
||||||
merchant_data: merchant_data ? merchant_data.toString('hex')
|
merchant_data: merchant_data
|
||||||
// : new Buffer('none', 'utf8').toString('hex')
|
? merchant_data.toString('hex')
|
||||||
: '00'
|
: null
|
||||||
},
|
},
|
||||||
signature: sig.toString('hex'),
|
signature: sig.toString('hex'),
|
||||||
ca: trust.caName,
|
ca: trust.caName,
|
||||||
|
|
@ -1462,7 +1469,7 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
log.debug('You are currently on this BTC network:', network);
|
log.debug('You are currently on this BTC network:', network);
|
||||||
log.debug('The server sent you a message:', memo);
|
log.debug('The server sent you a message:', memo);
|
||||||
|
|
||||||
return cb(ntxid, merchantData);
|
return cb(null, ntxid, merchantData);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1540,8 +1547,10 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) {
|
||||||
var pay = new PayPro();
|
var pay = new PayPro();
|
||||||
pay = pay.makePayment();
|
pay = pay.makePayment();
|
||||||
var merchant_data = txp.merchant.pr.pd.merchant_data;
|
var merchant_data = txp.merchant.pr.pd.merchant_data;
|
||||||
merchant_data = new Buffer(merchant_data, 'hex');
|
if (merchant_data) {
|
||||||
pay.set('merchant_data', merchant_data);
|
merchant_data = new Buffer(merchant_data, 'hex');
|
||||||
|
pay.set('merchant_data', merchant_data);
|
||||||
|
}
|
||||||
pay.set('transactions', [tx.serialize()]);
|
pay.set('transactions', [tx.serialize()]);
|
||||||
pay.set('refund_to', refund_outputs);
|
pay.set('refund_to', refund_outputs);
|
||||||
|
|
||||||
|
|
@ -1582,7 +1591,13 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) {
|
||||||
return self.receivePaymentRequestACK(ntxid, tx, txp, ack, cb);
|
return self.receivePaymentRequestACK(ntxid, tx, txp, ack, cb);
|
||||||
})
|
})
|
||||||
.error(function(data, status, headers, config) {
|
.error(function(data, status, headers, config) {
|
||||||
return cb(new Error('Status: ' + status));
|
log.debug('Sending to server was not met with a returned tx.');
|
||||||
|
log.debug('XHR status: ' + status);
|
||||||
|
return self._checkSentTx(ntxid, function(txid) {
|
||||||
|
log.debug('[Wallet.js.1581:txid:%s]', txid);
|
||||||
|
if (txid) self.store();
|
||||||
|
return cb(txid, txp.merchant);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1606,34 +1621,51 @@ Wallet.prototype.receivePaymentRequestACK = function(ntxid, tx, txp, ack, cb) {
|
||||||
memo: memo
|
memo: memo
|
||||||
};
|
};
|
||||||
|
|
||||||
var tx = payment.message.transactions[0];
|
if (payment.message.transactions && payment.message.transactions.length) {
|
||||||
|
tx = payment.message.transactions[0];
|
||||||
if (!tx) {
|
if (!tx) {
|
||||||
log.debug('Sending to server was not met with a returned tx.');
|
log.debug('Sending to server was not met with a returned tx.');
|
||||||
return this._checkSentTx(ntxid, function(txid) {
|
return this._checkSentTx(ntxid, function(txid) {
|
||||||
self.log('[Wallet.js.1048:txid:%s]', txid);
|
log.debug('[Wallet.js.1613:txid:%s]', txid);
|
||||||
if (txid) self.store();
|
if (txid) self.store();
|
||||||
return cb(txid, txp.merchant);
|
return cb(txid, txp.merchant);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (tx.buffer) {
|
||||||
if (tx.buffer) {
|
tx.buffer = new Buffer(new Uint8Array(tx.buffer));
|
||||||
tx.buffer = new Buffer(new Uint8Array(tx.buffer));
|
tx.buffer = tx.buffer.slice(tx.offset, tx.limit);
|
||||||
tx.buffer = tx.buffer.slice(tx.offset, tx.limit);
|
var ptx = new bitcore.Transaction();
|
||||||
var ptx = new bitcore.Transaction();
|
ptx.parse(tx.buffer);
|
||||||
ptx.parse(tx.buffer);
|
tx = ptx;
|
||||||
tx = ptx;
|
}
|
||||||
|
} else {
|
||||||
|
log.debug('WARNING: This server does not comply by standards.');
|
||||||
|
log.debug('It is not returning a copy of the transaction.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var txid = tx.getHash().toString('hex');
|
var txid = tx.getHash().toString('hex');
|
||||||
var txHex = tx.serialize().toString('hex');
|
var txHex = tx.serialize().toString('hex');
|
||||||
log.debug('Raw transaction: ', txHex);
|
log.debug('Raw transaction: ', txHex);
|
||||||
log.debug('BITCOIND txid:', txid);
|
|
||||||
this.txProposals.get(ntxid).setSent(txid);
|
|
||||||
this.sendTxProposal(ntxid);
|
|
||||||
this.store();
|
|
||||||
|
|
||||||
return cb(txid, txp.merchant);
|
// XXX This fixes the invalid signature error:
|
||||||
|
// we might as well broadcast it ourselves anyway.
|
||||||
|
this.blockchain.broadcast(txHex, function(err, txid) {
|
||||||
|
log.debug('BITCOIND txid:', txid);
|
||||||
|
if (txid) {
|
||||||
|
self.txProposals.get(ntxid).setSent(txid);
|
||||||
|
self.sendTxProposal(ntxid);
|
||||||
|
self.store();
|
||||||
|
return cb(txid, txp.merchant);
|
||||||
|
} else {
|
||||||
|
log.debug('Sent failed. Checking if the TX was sent already');
|
||||||
|
self._checkSentTx(ntxid, function(txid) {
|
||||||
|
if (txid)
|
||||||
|
self.store();
|
||||||
|
|
||||||
|
return cb(txid, txp.merchant);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -684,7 +684,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
var req = w.paymentRequests[options.uri];
|
var req = w.paymentRequests[options.uri];
|
||||||
should.exist(req);
|
should.exist(req);
|
||||||
delete w.paymentRequests[options.uri];
|
delete w.paymentRequests[options.uri];
|
||||||
w.receivePaymentRequest(options, req.pr, function(ntxid, merchantData) {
|
w.receivePaymentRequest(options, req.pr, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
w._ntxid = ntxid;
|
w._ntxid = ntxid;
|
||||||
|
|
@ -713,7 +714,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
w.createPaymentTx({
|
w.createPaymentTx({
|
||||||
uri: uri,
|
uri: uri,
|
||||||
memo: memo
|
memo: memo
|
||||||
}, function(ntxid, merchantData) {
|
}, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
if (w.isShared()) {
|
if (w.isShared()) {
|
||||||
|
|
@ -744,7 +746,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
uri = address.split(/\s+/)[1];
|
uri = address.split(/\s+/)[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
w.createPaymentTx({ uri: uri, memo: commentText }, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: uri, memo: commentText }, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
if (w.isShared()) {
|
if (w.isShared()) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
@ -765,7 +768,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
if (w.isShared()) {
|
if (w.isShared()) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
@ -785,7 +789,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
@ -821,7 +826,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
@ -848,7 +854,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
@ -874,7 +881,8 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
|
||||||
|
should.equal(err, null);
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue