From 71e226b7820dbcfb352719582ad9e79f575d5bc4 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Wed, 2 Jul 2014 17:40:56 -0700 Subject: [PATCH] serialize payment request for signature --- lib/PayPro.js | 9 +++++++++ test/test.PayPro.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/PayPro.js b/lib/PayPro.js index 237a57c..f827cf6 100644 --- a/lib/PayPro.js +++ b/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) diff --git a/test/test.PayPro.js b/test/test.PayPro.js index 4b654f6..c56eb20 100644 --- a/test/test.PayPro.js +++ b/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() {