From: Steve Sutton Date: Tue, 9 Apr 2019 20:17:37 +0000 (-0400) Subject: Square payment update X-Git-Tag: v2.12.2^2~16 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=5692db26ce55c8a6e0c7d2f61e83baca1d6f7aa7;p=WP-Plugins%2Fglm-member-db.git Square payment update Return error if declined or card already processed. --- diff --git a/lib/paymentProcessors/Square/paymentGateway.php b/lib/paymentProcessors/Square/paymentGateway.php index 23a62b96..4f928610 100755 --- a/lib/paymentProcessors/Square/paymentGateway.php +++ b/lib/paymentProcessors/Square/paymentGateway.php @@ -276,11 +276,14 @@ class PaymentGateway ), ); + $amount = $payment['charge'] * 100; + // $amount = 403; // decline error + $paymentInfo = array( 'card_nonce' => $nonce, 'idempotency_key' => uniqid(), 'amount_money' => array( - 'amount' => $payment['charge'] * 100, + 'amount' => $amount, 'currency' => 'USD', ), ); @@ -300,9 +303,6 @@ class PaymentGateway # a 200-level HTTP code. This block catches any exceptions that occur from the request. try { $result = $transactionApi->charge( $locationId, $txRequest ); - echo "
";
-            print_r( $result );
-            echo "
"; $resp = array( 'gateway' => 'Square', 'status' => 1, @@ -314,6 +314,14 @@ class PaymentGateway ); return $resp; } catch ( \SquareConnect\ApiException $e ) { + // Check for nonce already used + $responseBody = $e->getResponseBody(); + if ( $responseBody->errors[0]->code == CARD_TOKEN_USED ) { + $description = 'Card already used!'; + } + if ( $responseBody->errors[0]->code == CARD_DECLINED ) { + $description = 'Card declined!'; + } $resp = array( 'gateway' => 'Square', 'status' => 7, @@ -321,8 +329,9 @@ class PaymentGateway 'authCode' => '', 'transId' => '', 'refId' => $refId, - 'description' => '
Bad response: ' . print_r( $e->getResponseBody(), true) . '
' - .'
$txRequest: ' . print_r( $txRequest, true ) . '
', + 'description' => $description, + // 'description' => '
Bad response: ' . print_r( $e->getResponseBody(), true) . '
' + // .'
$txRequest: ' . print_r( $txRequest, true ) . '
', ); return $resp; }