Update payment gateway.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Apr 2019 15:36:00 +0000 (11:36 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 10 Apr 2019 15:36:00 +0000 (11:36 -0400)
Working with errors codes.

lib/paymentProcessors/Square/paymentGateway.php

index 4f92861..07c2967 100755 (executable)
@@ -316,11 +316,16 @@ class PaymentGateway
         } catch ( \SquareConnect\ApiException $e ) {
             // Check for nonce already used
             $responseBody = $e->getResponseBody();
-            if ( $responseBody->errors[0]->code == CARD_TOKEN_USED ) {
+            switch ( $responseBody->errors[0]->code ) {
+                case CARD_TOKEN_USED:
                 $description = 'Card already used!';
-            }
-            if ( $responseBody->errors[0]->code == CARD_DECLINED ) {
+                    break;
+                case CARD_DECLINED:
                 $description = 'Card declined!';
+                    break;
+                default:
+                $description = 'There was an error processing your Card!';
+                    break;
             }
             $resp = array(
                 'gateway'     => 'Square',
@@ -330,8 +335,6 @@ class PaymentGateway
                 'transId'     => '',
                 'refId'       => $refId,
                 'description' => $description,
-                // 'description' => '<pre>Bad response: ' . print_r( $e->getResponseBody(), true) . '</pre>'
-                //     .'<pre>$txRequest: ' . print_r( $txRequest, true ) . '</pre>',
             );
             return $resp;
         }
@@ -489,8 +492,6 @@ class PaymentGateway
 
         }
 
-        // echo "Response before profile<br><pre>".print_r($resp,1)."</pre>";
-
         // Check if request to create a customer profile using this transaction
         if (isset($payment['transOpt']) && $payment['transOpt'] == 1) {