Advertisement
linccce

New Exception Klarna Woocommerce

May 8th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1.     /**
  2.      * Throw an exception if the server responds with an error code.
  3.      *
  4.      * @param Klarna_Checkout_HTTP_Response $result HTTP Response object
  5.      *
  6.      * @throws Klarna_Checkout_ApiErrorException
  7.      * @return void
  8.      */
  9.     protected function verifyResponse(Klarna_Checkout_HTTP_Response $result)
  10.     {
  11.         // Error Status Code recieved. Throw an exception.
  12.         if ($result->getStatus() >= 400 && $result->getStatus() <= 599) {
  13.  
  14.             $json = json_decode($result->getData(), true);
  15.             $payload = ($json && is_array($json)) ? $json : array();
  16.  
  17.             try {
  18.                 throw new Klarna_Checkout_ApiErrorException(
  19.                     "API Error: ", $result->getStatus(), $payload
  20.                 );
  21.             } catch(Klarna_Checkout_ApiErrorException $e) {
  22.                 foreach($e->getPayload() as $error){
  23.                     echo "<span style='padding-left: 12px'>".$error."</span><br/>";
  24.                 }
  25.             }
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement