serialize payment request for signature

This commit is contained in:
Ryan X. Charles 2014-07-02 17:40:56 -07:00
parent e48561302b
commit 71e226b782
2 changed files with 25 additions and 0 deletions

View File

@ -167,6 +167,15 @@ PayPro.prototype.setObj = function(obj) {
return this;
};
PayPro.prototype.serializeForSig = function() {
if (this.messageType !== 'PaymentRequest')
throw new Error('serializeForSig is only for PaymentRequest');
this.message.set('signature', new Buffer([]));
var buf = this.serialize();
return buf;
};
PayPro.prototype.serialize = function() {
//protobufjs returns either a Buffer or an ArrayBuffer
//but we always want a Buffer (which browserify understands, browser or no)

View File

@ -177,6 +177,22 @@ describe('PayPro', function() {
});
describe('#serializeForSig', function() {
it('should serialize a PaymentRequest and not fail', function() {
var pd = new PayPro.PaymentDetails();
pd.set('time', 0);
var pdbuf = pd.toBuffer();
var paypro = new PayPro();
paypro.makePaymentRequest();
paypro.set('serialized_payment_details', pdbuf);
var buf = paypro.serializeForSig();
buf.length.should.be.greaterThan(0);
});
});
describe('#serialize', function() {
it('should serialize', function() {