Check for fields
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 5 Apr 2019 17:58:41 +0000 (13:58 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 5 Apr 2019 17:58:41 +0000 (13:58 -0400)
Check for email address

lib/paymentProcessors/Square/paymentGateway.php

index fad1a53..23a62b9 100755 (executable)
@@ -166,6 +166,8 @@ class PaymentGateway
      *      Card postal code incorrect      Use 99999 as the postal code
      *      Card expiration date incorrect  Use 01/40 as the expiration date
      *
+     * Declined
+     *      You can also trigger a "Card declined" error by using 403 as the amount_money in the Charge request.
      */
     public function processPayment( $payment = false, $customer = false )
     {
@@ -232,6 +234,9 @@ class PaymentGateway
 
         $transactionApi = new \SquareConnect\Api\TransactionsApi();
 
+        if ( !isset( $customer['email'] ) || trim( $customer['email'] ) == '' ) {
+            $errorMsg[] = 'Required Customer Email Address not provided';
+        }
         if ( !isset( $customer['addr1'] ) || trim( $customer['addr1'] ) == '' ) {
             $errorMsg[] = 'Required Customer Address Line 1 not provided';
         }
@@ -244,7 +249,23 @@ class PaymentGateway
         if ( !isset( $customer['zip'] ) || trim( $customer['zip'] ) == '' ) {
             $errorMsg[] = 'Required Customer ZIP/Postal Code not provided';
         }
+        if (!isset($payment['charge']) || (trim($payment['charge'])-0) <= 0) {
+            $errorMsg[] = 'Required Charge Amount not provided';
+        }
 
+        // If there's a problem with submitted information
+        if ( count( $errorMsg ) > 0 ) {
+            $resp = array(
+                'gateway'     => 'Square',
+                'status'      => 2,
+                'statusText'  => 'Bad data supplied',
+                'authCode'    => '',
+                'transId'     => '',
+                'refId'       => $refId,
+                'description' => implode(', ', $errorMsg)
+            );
+            return $resp;
+        }
         $buyerInfo = array(
             'buyer_email_address' => $customer['email'],
             'billing_address'     => array(