From c27dcfa61fba15082e313620327594c1861eefae Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 5 Apr 2019 13:58:41 -0400 Subject: [PATCH] Check for fields Check for email address --- .../Square/paymentGateway.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/paymentProcessors/Square/paymentGateway.php b/lib/paymentProcessors/Square/paymentGateway.php index fad1a53c..23a62b96 100755 --- a/lib/paymentProcessors/Square/paymentGateway.php +++ b/lib/paymentProcessors/Square/paymentGateway.php @@ -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( -- 2.17.1