From 5d737abd4eec684de1c8ddaef7180387b680e96d Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 15 Sep 2015 15:43:11 -0300 Subject: [PATCH 1/4] Handle paypro verification error --- lib/paypro.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/paypro.js b/lib/paypro.js index 3d850c99..f1b121c9 100644 --- a/lib/paypro.js +++ b/lib/paypro.js @@ -91,22 +91,24 @@ PayPro.get = function(opts, cb) { 'Content-Type': 'application/octet-stream', }; + var verified; + http(opts, function(err, dataBuffer) { if (err) return cb(err); var request; try { var body = BitcorePayPro.PaymentRequest.decode(dataBuffer); request = (new BitcorePayPro()).makePaymentRequest(body); + + // Verify the signature + verified = request.verify(true); } catch (e) { - return cb('Could not parse payment protocol:' + e) + return cb('Could not parse payment protocol: ' + e) } var signature = request.get('signature'); var serializedDetails = request.get('serialized_payment_details'); - // Verify the signature - var verified = request.verify(true); - // Get the payment details var decodedDetails = BitcorePayPro.PaymentDetails.decode(serializedDetails); var pd = new BitcorePayPro(); From a681d3838aa7818e40cd27352c17a2888cc4ecfa Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 15 Sep 2015 15:45:42 -0300 Subject: [PATCH 2/4] Adds VIM and OSX to gitignore --- .gitignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index 731c3752..31a3a1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,16 @@ db/* docs +# VIM ignore +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ + +# OSX +.DS_Store +.AppleDouble +.LSOverride + From 1bbe05f5014a96814d0a9780813a6c6d72ca4d5f Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 15 Sep 2015 15:57:19 -0300 Subject: [PATCH 3/4] Handle errors --- lib/paypro.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/paypro.js b/lib/paypro.js index f1b121c9..bdf04b2e 100644 --- a/lib/paypro.js +++ b/lib/paypro.js @@ -91,24 +91,21 @@ PayPro.get = function(opts, cb) { 'Content-Type': 'application/octet-stream', }; - var verified; - http(opts, function(err, dataBuffer) { if (err) return cb(err); - var request; + var request, verified, signature, serializedDetails; try { var body = BitcorePayPro.PaymentRequest.decode(dataBuffer); request = (new BitcorePayPro()).makePaymentRequest(body); // Verify the signature verified = request.verify(true); + signature = request.get('signature'); + serializedDetails = request.get('serialized_payment_details'); } catch (e) { return cb('Could not parse payment protocol: ' + e) } - var signature = request.get('signature'); - var serializedDetails = request.get('serialized_payment_details'); - // Get the payment details var decodedDetails = BitcorePayPro.PaymentDetails.decode(serializedDetails); var pd = new BitcorePayPro(); From 1306b8da052b3f2dfeb44fef7c4d5393c558eb08 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 15 Sep 2015 16:00:27 -0300 Subject: [PATCH 4/4] Order --- lib/paypro.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/paypro.js b/lib/paypro.js index bdf04b2e..31005b98 100644 --- a/lib/paypro.js +++ b/lib/paypro.js @@ -97,11 +97,10 @@ PayPro.get = function(opts, cb) { try { var body = BitcorePayPro.PaymentRequest.decode(dataBuffer); request = (new BitcorePayPro()).makePaymentRequest(body); - - // Verify the signature - verified = request.verify(true); signature = request.get('signature'); serializedDetails = request.get('serialized_payment_details'); + // Verify the signature + verified = request.verify(true); } catch (e) { return cb('Could not parse payment protocol: ' + e) }