class ErrorHelper in Commerce Square Connect 8
Translates Square exceptions and errors into Commerce exceptions.
Hierarchy
- class \Drupal\commerce_square\ErrorHelper
Expanded class hierarchy of ErrorHelper
See also
https://docs.connect.squareup.com/api/connect/v2/#type-errorcategory
https://docs.connect.squareup.com/api/connect/v2/#type-errorcode
1 file declares its use of ErrorHelper
- Square.php in src/
Plugin/ Commerce/ PaymentGateway/ Square.php
File
- src/
ErrorHelper.php, line 16
Namespace
Drupal\commerce_squareView source
class ErrorHelper {
/**
* Translates Square exceptions into Commerce exceptions.
*
* @param \SquareConnect\ApiException $exception
* The Square exception.
*
* @return \Drupal\commerce_payment\Exception\PaymentGatewayException
* The Commerce exception.
*/
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);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ErrorHelper:: |
public static | function | Translates Square exceptions into Commerce exceptions. |