public static function ErrorHelper::convertException in Commerce Square Connect 8
Translates Square exceptions into Commerce exceptions.
Parameters
\SquareConnect\ApiException $exception: The Square exception.
Return value
\Drupal\commerce_payment\Exception\PaymentGatewayException The Commerce exception.
4 calls to ErrorHelper::convertException()
- Square::capturePayment in src/
Plugin/ Commerce/ PaymentGateway/ Square.php - Captures the given authorized payment.
- Square::createPayment in src/
Plugin/ Commerce/ PaymentGateway/ Square.php - Creates a payment.
- Square::refundPayment in src/
Plugin/ Commerce/ PaymentGateway/ Square.php - Refunds the given payment.
- Square::voidPayment in src/
Plugin/ Commerce/ PaymentGateway/ Square.php - Voids the given payment.
File
- src/
ErrorHelper.php, line 27
Class
- ErrorHelper
- Translates Square exceptions and errors into Commerce exceptions.
Namespace
Drupal\commerce_squareCode
public static function convertException(ApiException $exception) {
$response_body = $exception
->getResponseBody();
$error = reset($response_body->errors);
switch ($error->category) {
case 'PAYMENT_METHOD_ERROR':
return new SoftDeclineException($error->detail);
case 'REFUND_ERROR':
return new HardDeclineException($error->detail);
default:
// All other error categories are API request related.
return new InvalidResponseException($exception
->getMessage(), $exception
->getCode(), $exception);
}
}