Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUPESC-755 Fixed Unzer notifications processing order. #35

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:
jobs:
setup:
name: Setup Database MariaDB
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand All @@ -44,7 +44,7 @@ jobs:
ci:
name: Unzer (PHP ${{ matrix.php-versions }})
needs: setup
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

strategy:
fail-fast: false
Expand Down
1 change: 1 addition & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ paths:
tests: tests
support: .
log: tests/_output
output: tests/_output
data: tests/_data
envs: tests/_envs

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"spryker/zed-request": "^3.0.0"
},
"require-dev": {
"codeception/module-asserts": "^1.3.0",
"phpstan/phpstan": "^1.2.0",
"codeception/module-asserts": "*",
"phpstan/phpstan": "*",
"spryker/application": "*",
"spryker/code-sniffer": "*",
"spryker/customer": "*",
Expand All @@ -44,7 +44,7 @@
"spryker/queue": "*",
"spryker/router": "*",
"spryker/state-machine": "*",
"spryker/testify": "^3.43.0"
"spryker/testify": "*"
},
"suggest": {
"spryker/checkout": "Use this module if you want to use Checkout plugins.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SprykerEco\Zed\Unzer\Business\ApiAdapter\UnzerPaymentAdapterInterface;
use SprykerEco\Zed\Unzer\Business\Credentials\UnzerCredentialsResolverInterface;
use SprykerEco\Zed\Unzer\Business\Payment\Mapper\UnzerPaymentMapperInterface;
use SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolverInterface;
use SprykerEco\Zed\Unzer\Business\Payment\Updater\UnzerPaymentUpdaterInterface;
use SprykerEco\Zed\Unzer\Business\Reader\UnzerReaderInterface;
use SprykerEco\Zed\Unzer\UnzerConfig;
Expand All @@ -24,32 +25,37 @@ class UnzerNotificationProcessor implements UnzerNotificationProcessorInterface
/**
* @var \SprykerEco\Zed\Unzer\Business\ApiAdapter\UnzerPaymentAdapterInterface
*/
protected $unzerPaymentAdapter;
protected UnzerPaymentAdapterInterface $unzerPaymentAdapter;

/**
* @var \SprykerEco\Zed\Unzer\UnzerConfig
*/
protected $unzerConfig;
protected UnzerConfig $unzerConfig;

/**
* @var \SprykerEco\Zed\Unzer\Business\Reader\UnzerReaderInterface
*/
protected $unzerReader;
protected UnzerReaderInterface $unzerReader;

/**
* @var \SprykerEco\Zed\Unzer\Business\Payment\Mapper\UnzerPaymentMapperInterface
*/
protected $unzerPaymentMapper;
protected UnzerPaymentMapperInterface $unzerPaymentMapper;

/**
* @var \SprykerEco\Zed\Unzer\Business\Payment\Updater\UnzerPaymentUpdaterInterface
*/
protected $unzerPaymentUpdater;
protected UnzerPaymentUpdaterInterface $unzerPaymentUpdater;

/**
* @var \SprykerEco\Zed\Unzer\Business\Credentials\UnzerCredentialsResolverInterface
*/
protected $unzerCredentialsResolver;
protected UnzerCredentialsResolverInterface $unzerCredentialsResolver;

/**
* @var \SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolverInterface
*/
protected UnzerOmsStateResolverInterface $unzerOmsStateResolver;

/**
* @param \SprykerEco\Zed\Unzer\Business\ApiAdapter\UnzerPaymentAdapterInterface $unzerPaymentAdapter
Expand All @@ -58,21 +64,24 @@ class UnzerNotificationProcessor implements UnzerNotificationProcessorInterface
* @param \SprykerEco\Zed\Unzer\Business\Payment\Mapper\UnzerPaymentMapperInterface $unzerPaymentMapper
* @param \SprykerEco\Zed\Unzer\Business\Payment\Updater\UnzerPaymentUpdaterInterface $unzerPaymentUpdater
* @param \SprykerEco\Zed\Unzer\Business\Credentials\UnzerCredentialsResolverInterface $unzerCredentialsResolver
* @param \SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolverInterface $unzerOmsStateResolver
*/
public function __construct(
UnzerPaymentAdapterInterface $unzerPaymentAdapter,
UnzerConfig $unzerConfig,
UnzerReaderInterface $unzerReader,
UnzerPaymentMapperInterface $unzerPaymentMapper,
UnzerPaymentUpdaterInterface $unzerPaymentUpdater,
UnzerCredentialsResolverInterface $unzerCredentialsResolver
UnzerCredentialsResolverInterface $unzerCredentialsResolver,
UnzerOmsStateResolverInterface $unzerOmsStateResolver
) {
$this->unzerPaymentAdapter = $unzerPaymentAdapter;
$this->unzerConfig = $unzerConfig;
$this->unzerReader = $unzerReader;
$this->unzerPaymentMapper = $unzerPaymentMapper;
$this->unzerPaymentUpdater = $unzerPaymentUpdater;
$this->unzerCredentialsResolver = $unzerCredentialsResolver;
$this->unzerOmsStateResolver = $unzerOmsStateResolver;
}

/**
Expand Down Expand Up @@ -109,9 +118,7 @@ public function processNotification(UnzerNotificationTransfer $unzerNotification
return $unzerNotificationTransfer;
}

$orderItemStatus = $this->unzerConfig->mapUnzerEventToOmsStatus(
$unzerNotificationTransfer->getEventOrFail(),
);
$orderItemStatus = $this->unzerOmsStateResolver->getUnzerPaymentOmsStatus($unzerPaymentTransfer);

$this->unzerPaymentUpdater->updateUnzerPaymentDetails($unzerPaymentTransfer, $orderItemStatus);

Expand Down
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;
DmitryLymarenko marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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_AUTHORIZE) {
$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());
DmitryLymarenko marked this conversation as resolved.
Show resolved Hide resolved
}
}
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;
}
13 changes: 13 additions & 0 deletions src/SprykerEco/Zed/Unzer/Business/UnzerBusinessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
use SprykerEco\Zed\Unzer\Business\Payment\Filter\UnzerPaymentMethodFilterInterface;
use SprykerEco\Zed\Unzer\Business\Payment\Mapper\UnzerPaymentMapper;
use SprykerEco\Zed\Unzer\Business\Payment\Mapper\UnzerPaymentMapperInterface;
use SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolver;
use SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolverInterface;
use SprykerEco\Zed\Unzer\Business\Payment\Processor\Charge\UnzerChargeProcessorInterface;
use SprykerEco\Zed\Unzer\Business\Payment\Processor\Charge\UnzerCreditCardChargeProcessor;
use SprykerEco\Zed\Unzer\Business\Payment\Processor\Charge\UnzerMarketplaceCreditCardChargeProcessor;
Expand Down Expand Up @@ -403,6 +405,17 @@ public function createUnzerNotificationProcessor(): UnzerNotificationProcessorIn
$this->createUnzerPaymentMapper(),
$this->createUnzerPaymentUpdater(),
$this->createUnzerCredentialsResolver(),
$this->createUnzerOmsStateResolver(),
);
}

/**
* @return \SprykerEco\Zed\Unzer\Business\Payment\OmsStateResolver\UnzerOmsStateResolverInterface
*/
public function createUnzerOmsStateResolver(): UnzerOmsStateResolverInterface
{
return new UnzerOmsStateResolver(
$this->getConfig(),
);
}

Expand Down
50 changes: 50 additions & 0 deletions src/SprykerEco/Zed/Unzer/UnzerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ class UnzerConfig extends AbstractBundleConfig
UnzerConstants::UNZER_PAYMENT_STATUS_CHARGE_BACK => UnzerConstants::OMS_STATUS_PAYMENT_CHARGEBACK,
];

/**
* @var array<string, string>
*/
protected const UNZER_CHARGE_STATE_OMS_STATUS_MAP = [
UnzerConstants::TRANSACTION_STATUS_SUCCESS => UnzerConstants::OMS_STATUS_PAYMENT_COMPLETED,
UnzerConstants::TRANSACTION_STATUS_PENDING => UnzerConstants::OMS_STATUS_CHARGE_PENDING,
UnzerConstants::TRANSACTION_STATUS_ERROR => UnzerConstants::OMS_STATUS_CHARGE_FAILED,
];

/**
* @var array<string, string>
*/
protected const UNZER_AUTHORIZE_STATE_OMS_STATUS_MAP = [
UnzerConstants::TRANSACTION_STATUS_SUCCESS => UnzerConstants::OMS_STATUS_AUTHORIZE_SUCCEEDED,
UnzerConstants::TRANSACTION_STATUS_PENDING => UnzerConstants::OMS_STATUS_AUTHORIZE_PENDING,
UnzerConstants::TRANSACTION_STATUS_ERROR => UnzerConstants::OMS_STATUS_AUTHORIZE_FAILED,
];

/**
* @var array<string, string>
*/
Expand Down Expand Up @@ -367,6 +385,8 @@ public function isNotificationTypeEnabled(string $eventType): bool
*
* @api
*
* @deprecated Will be removed without replacement.
*
* @param string $unzerEvent
*
* @return string
Expand All @@ -376,6 +396,36 @@ public function mapUnzerEventToOmsStatus(string $unzerEvent): string
return static::UNZER_EVENT_OMS_STATUS_MAP[$unzerEvent];
}

/**
* Specification:
* - Maps Unzer charge transaction status to OMS status.
*
* @api
*
* @param string $transactionStatus
*
* @return string
*/
public function mapUnzerChargePaymentStatusToOmsStatus(string $transactionStatus): string
DmitryLymarenko marked this conversation as resolved.
Show resolved Hide resolved
{
return static::UNZER_CHARGE_STATE_OMS_STATUS_MAP[$transactionStatus];
}

/**
* Specification:
* - Maps Unzer authorize transaction status to OMS status.
*
* @api
*
* @param string $transactionStatus
*
* @return string
*/
public function mapUnzerAuthorizePaymentStatusToOmsStatus(string $transactionStatus): string
{
return static::UNZER_AUTHORIZE_STATE_OMS_STATUS_MAP[$transactionStatus];
}

/**
* Specification:
* - Get OMS status `Authorize succeeded`.
Expand Down
10 changes: 10 additions & 0 deletions src/SprykerEco/Zed/Unzer/UnzerConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ interface UnzerConstants
*/
public const TRANSACTION_STATUS_SUCCESS = 'success';

/**
* @var string
*/
public const TRANSACTION_STATUS_PENDING = 'pending';

/**
* @var string
*/
public const TRANSACTION_STATUS_ERROR = 'error';

/**
* @var int
*/
Expand Down
Loading
Loading