Browse Source

serialize payment request for signature

patch-2
Ryan X. Charles 11 years ago
parent
commit
71e226b782
  1. 9
      lib/PayPro.js
  2. 16
      test/test.PayPro.js

9
lib/PayPro.js

@ -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)

16
test/test.PayPro.js

@ -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() {

Loading…
Cancel
Save