[interchange: 1/2] Prevent the function to crash when the response is unparsable

Jon Jensen interchange-cvs at icdevgroup.org
Thu Mar 22 15:20:55 UTC 2018


commit 526513bd12760f8f5d8fd9c69cf4062413dddf84
Author: Marco Pessotto <melmothx at gmail.com>
Date:   Thu Apr 3 15:06:43 2014 +0200

    Prevent the function to crash when the response is unparsable
    
    Background: it looks like SOAP::Lite sometimes (or always?) fails to escape
    some entities (notably &). In this case the charging route crashes, because
    $response->valueof('//SetExpressCheckoutResponse') just returns undef.
    
    This patch basically prevent the charge action to complete and set the
    redirection to the checkout, the same way as it would have failed for
    other reasons.

 lib/Vend/Payment/PaypalExpress.pm |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/lib/Vend/Payment/PaypalExpress.pm b/lib/Vend/Payment/PaypalExpress.pm
index 6a0ff48..1a892fa 100644
--- a/lib/Vend/Payment/PaypalExpress.pm
+++ b/lib/Vend/Payment/PaypalExpress.pm
@@ -911,7 +911,13 @@ sub paypalexpress {
 
  	    $method = SOAP::Data->name('SetExpressCheckoutReq')->attr({xmlns=>$xmlns});
 	    $response = $service->call($header, $method => $request);
-	    %result = %{$response->valueof('//SetExpressCheckoutResponse')};
+
+      my $result_hashref = $response->valueof('//SetExpressCheckoutResponse');
+      unless ($result_hashref) {
+          $Tag->error({ name => 'paypal_failure', set => errmsg('Unable to parse the PayPal response') });
+          return $Tag->deliver({ location => $checkouturl });
+      }
+	    %result = %$result_hashref;
 		$::Scratch->{'token'} = $result{'Token'};
  
    if (!$result{'Token'}) {



More information about the interchange-cvs mailing list