Skip to content

Commit

Permalink
Reduce amount of error logs (#26)
Browse files Browse the repository at this point in the history
(cherry picked from commit e5aa77d)
  • Loading branch information
matweew committed Dec 3, 2024
1 parent 553e930 commit 44c8820
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
use Generated\Shared\Transfer\CancelPaymentResponseTransfer;
use Generated\Shared\Transfer\CancelPaymentTransfer;
use Generated\Shared\Transfer\PaymentTransfer;
use Spryker\Shared\Log\LoggerTrait;
use Spryker\Zed\AppPayment\Business\MessageBroker\TenantIdentifier\TenantIdentifierExtractor;
use Spryker\Zed\AppPayment\Business\Payment\Cancel\CancelPayment;
use Spryker\Zed\AppPayment\Business\Payment\Message\MessageSender;
use Spryker\Zed\AppPayment\Business\Payment\Status\PaymentStatus;
use Spryker\Zed\AppPayment\Persistence\AppPaymentRepositoryInterface;
use Spryker\Zed\AppPayment\Persistence\Exception\PaymentByTenantIdentifierAndOrderReferenceNotFoundException;

class CancelPaymentMessageHandler implements CancelPaymentMessageHandlerInterface
{
use LoggerTrait;

public function __construct(
protected AppPaymentRepositoryInterface $appPaymentRepository,
protected TenantIdentifierExtractor $tenantIdentifierExtractor,
Expand All @@ -32,10 +36,16 @@ public function handleCancelPayment(
): void {
$tenantIdentifier = $this->tenantIdentifierExtractor->getTenantIdentifierFromMessage($cancelPaymentTransfer);

$paymentTransfer = $this->appPaymentRepository->getPaymentByTenantIdentifierAndOrderReference(
$tenantIdentifier,
$cancelPaymentTransfer->getOrderReferenceOrFail(),
);
try {
$paymentTransfer = $this->appPaymentRepository->getPaymentByTenantIdentifierAndOrderReference(
$tenantIdentifier,
$cancelPaymentTransfer->getOrderReferenceOrFail(),
);
} catch (PaymentByTenantIdentifierAndOrderReferenceNotFoundException $paymentByTenantIdentifierAndOrderReferenceNotFoundException) {
$this->getLogger()->warning($paymentByTenantIdentifierAndOrderReferenceNotFoundException->getMessage());

return;
}

$cancelPaymentRequestTransfer = (new CancelPaymentRequestTransfer())
->setTransactionId($paymentTransfer->getTransactionIdOrFail())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
use Generated\Shared\Transfer\CapturePaymentTransfer;
use Generated\Shared\Transfer\MessageContextTransfer;
use Generated\Shared\Transfer\PaymentTransfer;
use Spryker\Shared\Log\LoggerTrait;
use Spryker\Zed\AppPayment\Business\MessageBroker\TenantIdentifier\TenantIdentifierExtractor;
use Spryker\Zed\AppPayment\Business\Payment\Capture\PaymentCapturer;
use Spryker\Zed\AppPayment\Business\Payment\Message\MessageSender;
use Spryker\Zed\AppPayment\Business\Payment\Status\PaymentStatus;
use Spryker\Zed\AppPayment\Persistence\AppPaymentRepositoryInterface;
use Spryker\Zed\AppPayment\Persistence\Exception\PaymentByTenantIdentifierAndOrderReferenceNotFoundException;

class CapturePaymentMessageHandler implements CapturePaymentMessageHandlerInterface
{
use LoggerTrait;

public function __construct(
protected AppPaymentRepositoryInterface $appPaymentRepository,
protected TenantIdentifierExtractor $tenantIdentifierExtractor,
Expand All @@ -33,10 +37,16 @@ public function handleCapturePayment(
): void {
$tenantIdentifier = $this->tenantIdentifierExtractor->getTenantIdentifierFromMessage($capturePaymentTransfer);

$paymentTransfer = $this->appPaymentRepository->getPaymentByTenantIdentifierAndOrderReference(
$tenantIdentifier,
$capturePaymentTransfer->getOrderReferenceOrFail(),
);
try {
$paymentTransfer = $this->appPaymentRepository->getPaymentByTenantIdentifierAndOrderReference(
$tenantIdentifier,
$capturePaymentTransfer->getOrderReferenceOrFail(),
);
} catch (PaymentByTenantIdentifierAndOrderReferenceNotFoundException $paymentByTenantIdentifierAndOrderReferenceNotFoundException) {
$this->getLogger()->warning($paymentByTenantIdentifierAndOrderReferenceNotFoundException->getMessage());

return;
}

$capturePaymentRequestTransfer = (new CapturePaymentRequestTransfer())
->setTransactionId($paymentTransfer->getTransactionIdOrFail())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Spryker\Zed\AppPayment\Business\Payment\Refund\PaymentRefunder;
use Spryker\Zed\AppPayment\Business\Payment\Refund\PaymentRefundStatus;
use Spryker\Zed\AppPayment\Persistence\AppPaymentRepositoryInterface;
use Spryker\Zed\AppPayment\Persistence\Exception\PaymentByTenantIdentifierAndOrderReferenceNotFoundException;

class RefundPaymentMessageHandler implements RefundPaymentMessageHandlerInterface
{
Expand All @@ -36,10 +37,16 @@ public function handleRefundPayment(RefundPaymentTransfer $refundPaymentTransfer
{
$tenantIdentifier = $this->tenantIdentifierExtractor->getTenantIdentifierFromMessage($refundPaymentTransfer);

$paymentTransfer = $this->appPaymentRepository->getPaymentByTenantIdentifierAndOrderReference(
$tenantIdentifier,
$refundPaymentTransfer->getOrderReferenceOrFail(),
);
try {
$paymentTransfer = $this->appPaymentRepository->getPaymentByTenantIdentifierAndOrderReference(
$tenantIdentifier,
$refundPaymentTransfer->getOrderReferenceOrFail(),
);
} catch (PaymentByTenantIdentifierAndOrderReferenceNotFoundException $paymentByTenantIdentifierAndOrderReferenceNotFoundException) {
$this->getLogger()->warning($paymentByTenantIdentifierAndOrderReferenceNotFoundException->getMessage());

return;
}

$refundPaymentRequestTransfer = (new RefundPaymentRequestTransfer())
->setTransactionId($paymentTransfer->getTransactionIdOrFail())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Spryker\Zed\AppPayment\AppPaymentDependencyProvider;
use Spryker\Zed\AppPayment\Business\Payment\Status\PaymentStatus;
use Spryker\Zed\AppPayment\Dependency\Plugin\AppPaymentPlatformPluginInterface;
use Spryker\Zed\AppPayment\Persistence\Exception\PaymentByTenantIdentifierAndOrderReferenceNotFoundException;
use SprykerTest\AsyncApi\AppPayment\AppPaymentAsyncApiTester;
use SprykerTest\Shared\Testify\Helper\DependencyHelperTrait;

Expand Down Expand Up @@ -144,16 +143,14 @@ public function testHandleCapturePaymentMessageUpdatesPaymentToCapturedRequested
$this->tester->assertPaymentHasStatus($paymentTransfer, PaymentStatus::STATUS_CAPTURE_REQUESTED);
}

public function testHandleCapturePaymentThrowsExceptionWhenPaymentDoesNotExist(): void
public function testHandleCapturePaymentDoesNotThrowExceptionWhenPaymentDoesNotExist(): void
{
// Arrange
$tenantIdentifier = Uuid::uuid4()->toString();
$this->tester->haveAppConfigForTenant($tenantIdentifier);

$capturePaymentTransfer = $this->tester->haveCapturePaymentTransfer(['tenantIdentifier' => $tenantIdentifier, 'orderReference' => Uuid::uuid4()->toString()]);

$this->expectException(PaymentByTenantIdentifierAndOrderReferenceNotFoundException::class);

// Act
$this->tester->runMessageReceiveTest($capturePaymentTransfer, 'payment-commands');
}
Expand Down

0 comments on commit 44c8820

Please sign in to comment.