Loading src/ErrorHelper.phpdeleted 100644 → 0 +0 −44 Original line number Diff line number Diff line <?php namespace Drupal\commerce_omise; use Drupal\commerce_payment\Exception\AuthenticationException; use Drupal\commerce_payment\Exception\DeclineException; use Drupal\commerce_payment\Exception\InvalidRequestException; use Drupal\commerce_payment\Exception\InvalidResponseException; use OmiseException; use OmiseInvalidCardException; use OmiseBadRequestException; use OmiseAuthenticationFailureException; /** * Translates Omise exceptions and errors into Commerce exceptions. */ class ErrorHelper { /** * Translates Omise exceptions into Commerce exceptions. * * @param \OmiseException $exception * The Omise exception. * * @throws \Drupal\commerce_payment\Exception\PaymentGatewayException * The Commerce exception. */ public static function handleException(OmiseException $exception) { if ($exception instanceof OmiseInvalidCardException) { throw new DeclineException('We encountered an error processing your card details. Please verify your details and try again.'); } elseif ($exception instanceof OmiseBadRequestException) { throw new InvalidRequestException('Invalid parameters were supplied to Omise\'s API.'); } elseif ($exception instanceof OmiseAuthenticationFailureException) { throw new AuthenticationException('Omise authentication failed.'); } else { throw new InvalidResponseException($exception->getMessage()); } } } src/OmiseUtil.php +22 −0 Original line number Diff line number Diff line Loading @@ -2,7 +2,11 @@ namespace Drupal\commerce_omise; use Drupal\commerce_payment\Exception\AuthenticationException; use Drupal\commerce_payment\Exception\DeclineException; use Drupal\commerce_payment\Exception\HardDeclineException; use Drupal\commerce_payment\Exception\InvalidRequestException; use Drupal\commerce_payment\Exception\InvalidResponseException; use Drupal\commerce_price\Price; /** Loading Loading @@ -50,4 +54,22 @@ class OmiseUtil implements OmiseUtilInterface { return $map[$cardType]; } /** * {@inheritdoc} */ public function handleException(\OmiseException $exception) { if ($exception instanceof \OmiseInvalidCardException) { throw new DeclineException('We encountered an error processing your card details. Please verify your details and try again.'); } elseif ($exception instanceof \OmiseBadRequestException) { throw new InvalidRequestException('Invalid parameters were supplied to Omise\'s API.'); } elseif ($exception instanceof \OmiseAuthenticationFailureException) { throw new AuthenticationException('Omise authentication failed.'); } else { throw new InvalidResponseException($exception->getMessage()); } } } src/OmiseUtilInterface.php +11 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,15 @@ interface OmiseUtilInterface { */ public function mapCreditCardType($cardType); /** * Translates Omise exceptions into Commerce exceptions. * * @param \OmiseException $exception * The Omise exception. * * @throws \Drupal\commerce_payment\Exception\PaymentGatewayException * The Commerce exception. */ public function handleException(\OmiseException $exception); } src/Plugin/Commerce/PaymentGateway/Omise.php +6 −7 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\commerce_omise\Plugin\Commerce\PaymentGateway; use Drupal\commerce_omise\ErrorHelper; use Drupal\commerce_omise\OmiseUtilInterface; use Drupal\commerce_payment\CreditCard; use Drupal\commerce_payment\Entity\PaymentInterface; Loading Loading @@ -185,7 +184,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { } } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $next_state = $capture ? 'completed' : 'authorization'; Loading @@ -208,7 +207,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { $charge->capture(); } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $payment->setState('completed'); Loading @@ -234,7 +233,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { $charge->refunds()->create($data); } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } // Update payment. Loading @@ -261,7 +260,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { $charge->refunds()->create($data); } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $old_refunded_amount = $payment->getRefundedAmount(); Loading Loading @@ -317,7 +316,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { } } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $payment_method->delete(); Loading Loading @@ -382,7 +381,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { } } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } } else { Loading Loading
src/ErrorHelper.phpdeleted 100644 → 0 +0 −44 Original line number Diff line number Diff line <?php namespace Drupal\commerce_omise; use Drupal\commerce_payment\Exception\AuthenticationException; use Drupal\commerce_payment\Exception\DeclineException; use Drupal\commerce_payment\Exception\InvalidRequestException; use Drupal\commerce_payment\Exception\InvalidResponseException; use OmiseException; use OmiseInvalidCardException; use OmiseBadRequestException; use OmiseAuthenticationFailureException; /** * Translates Omise exceptions and errors into Commerce exceptions. */ class ErrorHelper { /** * Translates Omise exceptions into Commerce exceptions. * * @param \OmiseException $exception * The Omise exception. * * @throws \Drupal\commerce_payment\Exception\PaymentGatewayException * The Commerce exception. */ public static function handleException(OmiseException $exception) { if ($exception instanceof OmiseInvalidCardException) { throw new DeclineException('We encountered an error processing your card details. Please verify your details and try again.'); } elseif ($exception instanceof OmiseBadRequestException) { throw new InvalidRequestException('Invalid parameters were supplied to Omise\'s API.'); } elseif ($exception instanceof OmiseAuthenticationFailureException) { throw new AuthenticationException('Omise authentication failed.'); } else { throw new InvalidResponseException($exception->getMessage()); } } }
src/OmiseUtil.php +22 −0 Original line number Diff line number Diff line Loading @@ -2,7 +2,11 @@ namespace Drupal\commerce_omise; use Drupal\commerce_payment\Exception\AuthenticationException; use Drupal\commerce_payment\Exception\DeclineException; use Drupal\commerce_payment\Exception\HardDeclineException; use Drupal\commerce_payment\Exception\InvalidRequestException; use Drupal\commerce_payment\Exception\InvalidResponseException; use Drupal\commerce_price\Price; /** Loading Loading @@ -50,4 +54,22 @@ class OmiseUtil implements OmiseUtilInterface { return $map[$cardType]; } /** * {@inheritdoc} */ public function handleException(\OmiseException $exception) { if ($exception instanceof \OmiseInvalidCardException) { throw new DeclineException('We encountered an error processing your card details. Please verify your details and try again.'); } elseif ($exception instanceof \OmiseBadRequestException) { throw new InvalidRequestException('Invalid parameters were supplied to Omise\'s API.'); } elseif ($exception instanceof \OmiseAuthenticationFailureException) { throw new AuthenticationException('Omise authentication failed.'); } else { throw new InvalidResponseException($exception->getMessage()); } } }
src/OmiseUtilInterface.php +11 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,15 @@ interface OmiseUtilInterface { */ public function mapCreditCardType($cardType); /** * Translates Omise exceptions into Commerce exceptions. * * @param \OmiseException $exception * The Omise exception. * * @throws \Drupal\commerce_payment\Exception\PaymentGatewayException * The Commerce exception. */ public function handleException(\OmiseException $exception); }
src/Plugin/Commerce/PaymentGateway/Omise.php +6 −7 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\commerce_omise\Plugin\Commerce\PaymentGateway; use Drupal\commerce_omise\ErrorHelper; use Drupal\commerce_omise\OmiseUtilInterface; use Drupal\commerce_payment\CreditCard; use Drupal\commerce_payment\Entity\PaymentInterface; Loading Loading @@ -185,7 +184,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { } } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $next_state = $capture ? 'completed' : 'authorization'; Loading @@ -208,7 +207,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { $charge->capture(); } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $payment->setState('completed'); Loading @@ -234,7 +233,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { $charge->refunds()->create($data); } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } // Update payment. Loading @@ -261,7 +260,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { $charge->refunds()->create($data); } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $old_refunded_amount = $payment->getRefundedAmount(); Loading Loading @@ -317,7 +316,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { } } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } $payment_method->delete(); Loading Loading @@ -382,7 +381,7 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface { } } catch (\OmiseException $e) { ErrorHelper::handleException($e); $this->util->handleException($e); } } else { Loading