-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SUPESC-755 Implemented OMS state resolver.
- Loading branch information
1 parent
ce3129f
commit 0113907
Showing
8 changed files
with
260 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/SprykerEco/Zed/Unzer/Business/Payment/OmsStateResolver/UnzerOmsStateResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver; | ||
|
||
use Generated\Shared\Transfer\UnzerPaymentTransfer; | ||
use SprykerEco\Zed\Unzer\UnzerConfig; | ||
use SprykerEco\Zed\Unzer\UnzerConstants; | ||
|
||
class UnzerOmsStateResolver implements UnzerOmsStateResolverInterface | ||
{ | ||
protected UnzerConfig $unzerConfig; | ||
|
||
/** | ||
* @param \SprykerEco\Zed\Unzer\UnzerConfig $unzerConfig | ||
*/ | ||
public function __construct(UnzerConfig $unzerConfig) | ||
{ | ||
$this->unzerConfig = $unzerConfig; | ||
} | ||
|
||
/** | ||
* @param \Generated\Shared\Transfer\UnzerPaymentTransfer $unzerPaymentTransfer | ||
* | ||
* @return string | ||
*/ | ||
public function getUnzerPaymentOmsStatus(UnzerPaymentTransfer $unzerPaymentTransfer): string | ||
{ | ||
$chargeUnzerTransactionTransfer = null; | ||
$authorizeUnzerTransactionTransfer = null; | ||
foreach ($unzerPaymentTransfer->getTransactions() as $unzerTransactionTransfer) { | ||
if ($unzerTransactionTransfer->getTypeOrFail() === UnzerConstants::TRANSACTION_TYPE_CHARGE) { | ||
$chargeUnzerTransactionTransfer = $unzerTransactionTransfer; | ||
|
||
continue; | ||
} | ||
|
||
if ($unzerTransactionTransfer->getTypeOrFail() === UnzerConstants::TRANSACTION_TYPE_CHARGE) { | ||
$authorizeUnzerTransactionTransfer = $unzerTransactionTransfer; | ||
} | ||
} | ||
|
||
if ($chargeUnzerTransactionTransfer !== null) { | ||
return $this->unzerConfig->mapUnzerChargePaymentStatusToOmsStatus($chargeUnzerTransactionTransfer->getStatusOrFail()); | ||
} | ||
|
||
if ($authorizeUnzerTransactionTransfer !== null) { | ||
return $this->unzerConfig->mapUnzerAuthorizePaymentStatusToOmsStatus($authorizeUnzerTransactionTransfer->getStatusOrFail()); | ||
} | ||
|
||
return $this->unzerConfig->mapUnzerPaymentStatusToOmsStatus($unzerPaymentTransfer->getStateIdOrFail()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...SprykerEco/Zed/Unzer/Business/Payment/OmsStateResolver/UnzerOmsStateResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver; | ||
|
||
use Generated\Shared\Transfer\UnzerPaymentTransfer; | ||
|
||
interface UnzerOmsStateResolverInterface | ||
{ | ||
/** | ||
* @param \Generated\Shared\Transfer\UnzerPaymentTransfer $unzerPaymentTransfer | ||
* | ||
* @return string | ||
*/ | ||
public function getUnzerPaymentOmsStatus(UnzerPaymentTransfer $unzerPaymentTransfer): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tests/SprykerEcoTest/Zed/Unzer/Business/Payment/UnzerOmsStateResolverTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* For full license information, please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SprykerEcoTest\Zed\Unzer\Business\Payment; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\UnzerPaymentTransfer; | ||
use Generated\Shared\Transfer\UnzerTransactionTransfer; | ||
use SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolver; | ||
use SprykerEco\Zed\Unzer\UnzerConfig; | ||
use SprykerEco\Zed\Unzer\UnzerConstants; | ||
|
||
class UnzerOmsStateResolverTest extends Unit | ||
{ | ||
/** | ||
* @dataProvider unzerPaymentStatusDataProvider | ||
* | ||
* @param string $expectedOmsState | ||
* @param \Generated\Shared\Transfer\UnzerPaymentTransfer $paymentTransfer | ||
* | ||
* @return void | ||
*/ | ||
public function testShouldReturn(string $expectedOmsState, UnzerPaymentTransfer $paymentTransfer): void | ||
{ | ||
// Act | ||
$omsState = (new UnzerOmsStateResolver(new UnzerConfig()))->getUnzerPaymentOmsStatus($paymentTransfer); | ||
|
||
// Assert | ||
$this->assertSame($expectedOmsState, $omsState); | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
protected function unzerPaymentStatusDataProvider(): array | ||
{ | ||
return [ | ||
'Payment status authorize pending' => [ | ||
UnzerConstants::OMS_STATUS_AUTHORIZE_PENDING, | ||
(new UnzerPaymentTransfer()) | ||
->setStateId(UnzerConstants::UNZER_PAYMENT_STATUS_PENDING) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_AUTHORIZE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_PENDING), | ||
), | ||
], | ||
'Payment status authorize success' => [ | ||
UnzerConstants::OMS_STATUS_AUTHORIZE_SUCCEEDED, | ||
(new UnzerPaymentTransfer()) | ||
->setStateId(UnzerConstants::UNZER_PAYMENT_STATUS_PENDING) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_AUTHORIZE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_SUCCESS), | ||
), | ||
], | ||
'Payment status authorize failed' => [ | ||
UnzerConstants::OMS_STATUS_AUTHORIZE_FAILED, | ||
(new UnzerPaymentTransfer()) | ||
->setStateId(UnzerConstants::UNZER_PAYMENT_STATUS_PENDING) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_AUTHORIZE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_PENDING), | ||
), | ||
], | ||
'Payment status charge failed' => [ | ||
UnzerConstants::OMS_STATUS_CHARGE_FAILED, | ||
(new UnzerPaymentTransfer()) | ||
->setStateId(UnzerConstants::UNZER_PAYMENT_STATUS_CANCELED) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_AUTHORIZE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_SUCCESS), | ||
) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_CHARGE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_ERROR), | ||
), | ||
], | ||
'Payment status payment completed' => [ | ||
UnzerConstants::OMS_STATUS_PAYMENT_COMPLETED, | ||
(new UnzerPaymentTransfer()) | ||
->setStateId(UnzerConstants::UNZER_PAYMENT_STATUS_PENDING) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_AUTHORIZE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_SUCCESS), | ||
) | ||
->addTransaction( | ||
(new UnzerTransactionTransfer()) | ||
->setType(UnzerConstants::TRANSACTION_TYPE_CHARGE) | ||
->setStatus(UnzerConstants::TRANSACTION_STATUS_SUCCESS), | ||
), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters