Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Exception/BadRequestApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace ThePay\ApiClient\Exception;

final class BadRequestApiException extends \RuntimeException implements ApiExceptionInterface
{
}
9 changes: 9 additions & 0 deletions src/Exception/ConflictApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace ThePay\ApiClient\Exception;

final class ConflictApiException extends \RuntimeException implements ApiExceptionInterface
{
}
9 changes: 9 additions & 0 deletions src/Exception/ForbiddenApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace ThePay\ApiClient\Exception;

final class ForbiddenApiException extends \RuntimeException implements ApiExceptionInterface
{
}
5 changes: 5 additions & 0 deletions src/Exception/MissingExtensionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use Exception;

/**
* @deprecated no longer thrown
*
* @todo breaking change: remove it
*/
class MissingExtensionException extends Exception
{
}
5 changes: 5 additions & 0 deletions src/Exception/NoAvailablePaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use Exception;

/**
* @deprecated no longer thrown
*
* @todo breaking change: remove it
*/
class NoAvailablePaymentMethod extends Exception
{
}
9 changes: 9 additions & 0 deletions src/Exception/TooManyRequestsApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace ThePay\ApiClient\Exception;

final class TooManyRequestsApiException extends \RuntimeException implements ApiExceptionInterface
{
}
9 changes: 9 additions & 0 deletions src/Exception/UnauthorizedApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace ThePay\ApiClient\Exception;

final class UnauthorizedApiException extends \RuntimeException implements ApiExceptionInterface
{
}
9 changes: 9 additions & 0 deletions src/Exception/UnprocessableContentApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace ThePay\ApiClient\Exception;

final class UnprocessableContentApiException extends \RuntimeException implements ApiExceptionInterface
{
}
18 changes: 18 additions & 0 deletions src/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use ThePay\ApiClient\Exception\ApiExceptionInterface;
use ThePay\ApiClient\Exception\BadRequestApiException;
use ThePay\ApiClient\Exception\ConflictApiException;
use ThePay\ApiClient\Exception\ForbiddenApiException;
use ThePay\ApiClient\Exception\NotFoundApiException;
use ThePay\ApiClient\Exception\ServiceUnavailableApiException;
use ThePay\ApiClient\Exception\TooManyRequestsApiException;
use ThePay\ApiClient\Exception\UnauthorizedApiException;
use ThePay\ApiClient\Exception\UnprocessableContentApiException;
use ThePay\ApiClient\Filter\PaymentsFilter;
use ThePay\ApiClient\Filter\TransactionFilter;
use ThePay\ApiClient\Model\AccountBalance;
Expand Down Expand Up @@ -483,8 +489,20 @@ private function buildException(string $requestUrl, ResponseInterface $response)
$message .= $this->getErrorResponseMessage($response->getBody()->getContents());

switch (true) {
case $responseCode == 400:
return new BadRequestApiException($message, $responseCode);
case $responseCode == 401:
return new UnauthorizedApiException($message, $responseCode);
case $responseCode == 403:
return new ForbiddenApiException($message, $responseCode);
case $responseCode == 404:
return new NotFoundApiException($message, $responseCode);
case $responseCode == 409:
return new ConflictApiException($message, $responseCode);
case $responseCode == 422:
return new UnprocessableContentApiException($message, $responseCode);
case $responseCode == 429:
return new TooManyRequestsApiException($message, $responseCode);
case $responseCode >= 500:
case $responseCode == 0: // network communication failure
return new ServiceUnavailableApiException($message, $responseCode);
Expand Down
11 changes: 8 additions & 3 deletions src/Service/ApiServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Psr\Http\Message\StreamInterface;
use ThePay\ApiClient\Exception\ApiExceptionInterface;
use ThePay\ApiClient\Exception\ConflictApiException;
use ThePay\ApiClient\Exception\NotFoundApiException;
use ThePay\ApiClient\Exception\UnprocessableContentApiException;
use ThePay\ApiClient\Filter\PaymentsFilter;
use ThePay\ApiClient\Filter\TransactionFilter;
use ThePay\ApiClient\Model\AccountBalance;
Expand All @@ -30,6 +32,9 @@
use ThePay\ApiClient\ValueObject\LanguageCode;
use ThePay\ApiClient\ValueObject\StringValue;

/**
* @note List only exceptions meant for flow control in `@throws`, all other errors should be covered by {@see ApiExceptionInterface}.
*/
interface ApiServiceInterface
{
/**
Expand Down Expand Up @@ -171,7 +176,7 @@ public function getAccountStatementGPC(TransactionFilter $filter, ?GPCPaymentIde
*
* @param non-empty-string|null $methodCode
*
* @throws ApiExceptionInterface
* @throws ConflictApiException|ApiExceptionInterface
*/
public function createPayment(CreatePaymentParams $createPaymentParams, ?string $methodCode = null): CreatePaymentResponse;

Expand All @@ -180,7 +185,7 @@ public function createPayment(CreatePaymentParams $createPaymentParams, ?string
*
* @see https://docs.thepay.eu/#tag/Preauthorized-Payments/paths/~1v2~1projects~1%7Bproject_id%7D~1payments~1%7Bpayment_uid%7D~1preauthorized/post
*
* @throws NotFoundApiException|ApiExceptionInterface
* @throws NotFoundApiException|UnprocessableContentApiException|ApiExceptionInterface
*/
public function realizePreauthorizedPayment(RealizePreauthorizedPaymentParams $params): RealizePreauthorizedPaymentResult;

Expand All @@ -189,7 +194,7 @@ public function realizePreauthorizedPayment(RealizePreauthorizedPaymentParams $p
*
* @see https://docs.thepay.eu/#tag/Preauthorized-Payments/paths/~1v1~1projects~1%7Bproject_id%7D~1payments~1%7Bpayment_uid%7D~1preauthorized/delete
*
* @throws NotFoundApiException|ApiExceptionInterface
* @throws NotFoundApiException|UnprocessableContentApiException|ApiExceptionInterface
*/
public function cancelPreauthorizedPayment(Identifier $uid): void;

Expand Down
10 changes: 6 additions & 4 deletions src/TheClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use ThePay\ApiClient\Exception\ApiExceptionInterface;
use ThePay\ApiClient\Exception\ConflictApiException;
use ThePay\ApiClient\Exception\NotFoundApiException;
use ThePay\ApiClient\Exception\UnprocessableContentApiException;
use ThePay\ApiClient\Filter\PaymentMethodFilter;
use ThePay\ApiClient\Filter\PaymentsFilter;
use ThePay\ApiClient\Filter\TransactionFilter;
Expand Down Expand Up @@ -295,7 +297,7 @@ public function getPaymentButtonsForPayment($uid, $languageCode = null, $useInli
/**
* @param non-empty-string|null $methodCode
*
* @throws ApiExceptionInterface
* @throws ConflictApiException|ApiExceptionInterface
*/
public function createPayment(CreatePaymentParams $params, ?string $methodCode = null): CreatePaymentResponse
{
Expand Down Expand Up @@ -327,7 +329,7 @@ public function changePaymentMethod(string $paymentUid, string $methodCode): voi
*
* @return RealizePreauthorizedPaymentResult
*
* @throws InvalidArgumentException|NotFoundApiException|ApiExceptionInterface
* @throws InvalidArgumentException|NotFoundApiException|UnprocessableContentApiException|ApiExceptionInterface
*/
public function realizePreauthorizedPayment(RealizePreauthorizedPaymentParams $params): RealizePreauthorizedPaymentResult
{
Expand All @@ -340,7 +342,7 @@ public function realizePreauthorizedPayment(RealizePreauthorizedPaymentParams $p
/**
* @param non-empty-string $paymentUid
*
* @throws InvalidArgumentException|NotFoundApiException|ApiExceptionInterface
* @throws InvalidArgumentException|NotFoundApiException|UnprocessableContentApiException|ApiExceptionInterface
*/
public function cancelPreauthorizedPayment(string $paymentUid): void
{
Expand Down Expand Up @@ -392,7 +394,7 @@ public function createPaymentRefund($paymentUid, $amount, $reason)
*
* @return string with binary content of PDF file
*
* @throws NotFoundApiException|ApiExceptionInterface if payment is not paid yet
* @throws InvalidArgumentException|NotFoundApiException|ApiExceptionInterface if payment is not paid yet
*/
public function generatePaymentConfirmationPdf(string $paymentUid, ?string $languageCode = null): string
{
Expand Down