Skip to content

Commit

Permalink
Merge pull request #897 from mollie/PIPRES-425
Browse files Browse the repository at this point in the history
PIPRES-425: Add exception handling for incorrect family name
  • Loading branch information
JevgenijVisockij authored Apr 3, 2024
2 parents 1d60186 + d805f26 commit e79441e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Exception/OrderCreationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ class OrderCreationException extends \Exception
const ORDER_RESOURSE_IS_MISSING = 6;

const ORDER_IS_NOT_CREATED = 7;

const WRONG_FAMILY_NAME = 8;
}
2 changes: 2 additions & 0 deletions src/Handler/Exception/OrderExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function handle(Exception $e)
return new OrderCreationException($e->getMessage(), OrderCreationException::WRONG_BILLING_PHONE_NUMBER_EXCEPTION);
} elseif (strpos($e->getMessage(), 'shippingAddress.phone')) {
return new OrderCreationException($e->getMessage(), OrderCreationException::WRONG_SHIPPING_PHONE_NUMBER_EXCEPTION);
} elseif (strpos($e->getMessage(), 'billingAddress.familyName')) {
return new OrderCreationException($e->getMessage(), OrderCreationException::WRONG_FAMILY_NAME);
} elseif (strpos($e->getMessage(), 'payment.amount')) {
if (strpos($e->getMessage(), 'minimum')) {
throw new OrderCreationException($e->getMessage(), OrderCreationException::ORDER_TOTAL_LOWER_THAN_MINIMUM);
Expand Down
5 changes: 3 additions & 2 deletions src/Service/MollieOrderCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Mollie\Config\Config;
use Mollie\DTO\OrderData;
use Mollie\DTO\PaymentData;
use Mollie\Errors\Http\HttpStatusCode;
use Mollie\Exception\OrderCreationException;
use Mollie\Handler\ErrorHandler\ErrorHandler;
use Mollie\Handler\Exception\OrderExceptionHandler;
Expand Down Expand Up @@ -66,10 +67,10 @@ public function createMollieOrder($data, MolPaymentMethod $paymentMethodObj)
$apiPayment = $this->createPayment($data, $paymentMethodObj->method);
} catch (OrderCreationException $e) {
$errorHandler = ErrorHandler::getInstance();
$errorHandler->handle($e, $e->getCode(), true);
$errorHandler->handle($e, HttpStatusCode::HTTP_BAD_REQUEST, true);
} catch (Exception $e) {
$errorHandler = ErrorHandler::getInstance();
$errorHandler->handle($e, $e->getCode(), true);
$errorHandler->handle($e, HttpStatusCode::HTTP_INTERNAL_SERVER_ERROR, true);
}
}

Expand Down

0 comments on commit e79441e

Please sign in to comment.