Skip to content

Commit

Permalink
BP-2824 - PayByBank on refactor branch
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianTuriacArnia committed Aug 15, 2023
1 parent e84f5b7 commit 3dd51fb
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 122 deletions.
7 changes: 4 additions & 3 deletions Gateway/Request/SaveIssuerDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ public function __construct(
* Save last used issuer, it will be used to select automatically the issuer in the checkout
*
* @param array $buildSubject
* @return void
* @return array
*/
public function build(array $buildSubject): void
public function build(array $buildSubject): array
{
$this->saveLastUsedIssuer(SubjectReader::readPayment($buildSubject)->getPayment());
return [];
}

/**
Expand All @@ -70,7 +71,7 @@ public function saveLastUsedIssuer(OrderPaymentInterface|InfoInterface $payment)

if ($customerId !== null) {
$this->customerAttributes->setAttribute(
$customerId,
(int)$customerId,
self::EAV_LAST_USED_ISSUER_ID,
$payment->getAdditionalInformation('issuer')
);
Expand Down
14 changes: 9 additions & 5 deletions Gateway/Validator/IssuerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
use Buckaroo\Magento2\Model\ConfigProvider\Method\ConfigProviderInterface;
use Buckaroo\Magento2\Model\ConfigProvider\Method\Factory;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Payment\Gateway\Validator\AbstractValidator;
use Magento\Payment\Gateway\Validator\ResultInterface;
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
use Magento\Payment\Model\InfoInterface;
use Magento\Quote\Model\Quote\Payment;

class IssuerValidator extends AbstractValidator
{
Expand Down Expand Up @@ -73,15 +75,17 @@ public function __construct(
*
* @param array $validationSubject
* @return ResultInterface
* @throws LocalizedException
*/
public function validate(array $validationSubject): ResultInterface
{
$paymentInfo = SubjectReader::readPayment($validationSubject)->getPayment();
/** @var Payment $paymentInfo */
$paymentInfo = $validationSubject['payment'];

$skipValidation = $paymentInfo->getAdditionalInformation('buckaroo_skip_validation');
if ($skipValidation) {
return $this->createResult(true);
}
// $skipValidation = $paymentInfo->getAdditionalInformation('buckaroo_skip_validation');
// if ($skipValidation) {
// return $this->createResult(true);
// }

$chosenIssuer = $paymentInfo->getAdditionalInformation('issuer');

Expand Down
61 changes: 22 additions & 39 deletions Model/ConfigProvider/Method/PayByBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
* If you are unable to obtain it through the world-wide-web, please email
* to [email protected], so we can send you a copy immediately.
*
* DISCLAIMER
*
Expand All @@ -17,35 +17,24 @@
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/
declare(strict_types=1);

namespace Buckaroo\Magento2\Model\ConfigProvider\Method;

use Buckaroo\Magento2\Gateway\Request\SaveIssuerDataBuilder;
use Buckaroo\Magento2\Model\ConfigProvider\Account;
use Magento\Framework\View\Asset\Repository;
use Buckaroo\Magento2\Helper\PaymentFee;
use Buckaroo\Magento2\Model\ConfigProvider\AllowedCurrencies;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Buckaroo\Magento2\Model\Method\PayByBank as PayByBankMethod;
use Magento\Store\Model\ScopeInterface;

class PayByBank extends AbstractConfigProvider
{
public const XPATH_PAYBYBANK_ACTIVE = 'payment/buckaroo_magento2_paybybank/active';
public const XPATH_PAYBYBANK_SUBTEXT = 'payment/buckaroo_magento2_paybybank/subtext';
public const XPATH_PAYBYBANK_SUBTEXT_STYLE = 'payment/buckaroo_magento2_paybybank/subtext_style';
public const XPATH_PAYBYBANK_SUBTEXT_COLOR = 'payment/buckaroo_magento2_paybybank/subtext_color';
public const XPATH_PAYBYBANK_ACTIVE_STATUS = 'payment/buckaroo_magento2_paybybank/active_status';
public const XPATH_PAYBYBANK_ORDER_STATUS_SUCCESS = 'payment/buckaroo_magento2_paybybank/order_status_success';
public const XPATH_PAYBYBANK_ORDER_STATUS_FAILED = 'payment/buckaroo_magento2_paybybank/order_status_failed';
public const XPATH_PAYBYBANK_ORDER_EMAIL = 'payment/buckaroo_magento2_paybybank/order_email';
public const XPATH_PAYBYBANK_AVAILABLE_IN_BACKEND = 'payment/buckaroo_magento2_paybybank/available_in_backend';

public const XPATH_ALLOWED_CURRENCIES = 'payment/buckaroo_magento2_paybybank/allowed_currencies';

public const XPATH_ALLOW_SPECIFIC = 'payment/buckaroo_magento2_paybybank/allowspecific';
public const XPATH_SPECIFIC_COUNTRY = 'payment/buckaroo_magento2_paybybank/specificcountry';
public const XPATH_PAYBYBANK_SELECTION_TYPE = 'buckaroo_magento2/account/selection_type';
public const XPATH_SPECIFIC_CUSTOMER_GROUP = 'payment/buckaroo_magento2_paybybank/specificcustomergroup';
public const CODE = 'buckaroo_magento2_paybybank';

public const XPATH_ACCOUNT_SELECTION_TYPE = 'buckaroo_magento2/account/selection_type';

protected array $issuers = [
[
Expand Down Expand Up @@ -125,17 +114,13 @@ public function __construct(
*/
public function getConfig(): array
{
if (!$this->scopeConfig->getValue(
static::XPATH_PAYBYBANK_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)) {
if (!$this->getActive()) {
return [];
}


$selectionType = $this->scopeConfig->getValue(
self::XPATH_PAYBYBANK_SELECTION_TYPE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
self::XPATH_ACCOUNT_SELECTION_TYPE,
ScopeInterface::SCOPE_STORE
);

return [
Expand All @@ -155,26 +140,22 @@ public function getConfig(): array
}

/**
* @param null|int $storeId
*
* @return float
* @inheritdoc
*/
public function getPaymentFee($storeId = null)
public function getPaymentFee($store = null)
{
return 0;
}

/**
* @param null|int $storeId
*
* @return string
* @inheritdoc
*/
public function getPaymentFeeLabel($storeId = null)
public function getPaymentFeeLabel($store = null)
{
return $this->scopeConfig->getValue(
Account::XPATH_ACCOUNT_PAYMENT_FEE_LABEL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
ScopeInterface::SCOPE_STORE,
$store
);
}

Expand All @@ -184,15 +165,17 @@ public function getPaymentFeeLabel($storeId = null)
*
* @return array
*/
public function getIssuersWithSelected()
public function getIssuersWithSelected(): array
{
$issuers = $this->formatIssuers();
$customer = $this->customerSession->getCustomer();
$savedBankIssuer = $customer->getData(PayByBankMethod::EAV_LAST_USED_ISSUER_ID);
$savedBankIssuer = $customer->getData(SaveIssuerDataBuilder::EAV_LAST_USED_ISSUER_ID);

if ($savedBankIssuer !== null) {
$issuers = array_map(function ($issuer) use ($savedBankIssuer) {
$issuer['selected'] = is_scalar($savedBankIssuer) && isset($issuer['code']) && $issuer['code'] === $savedBankIssuer;
$issuer['selected'] = is_scalar($savedBankIssuer)
&& isset($issuer['code'])
&& $issuer['code'] === $savedBankIssuer;
return $issuer;
}, $issuers);

Expand Down
2 changes: 1 addition & 1 deletion Observer/RestoreQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function execute(Observer $observer): void
if ($payment = $lastRealOrder->getPayment()) {
if ($this->shouldSkipFurtherEventHandling()
|| strpos($payment->getMethod(), 'buckaroo_magento2') === false
|| in_array($payment->getMethod(), [Payconiq::PAYMENT_METHOD_CODE])) {
|| in_array($payment->getMethod(), [Payconiq::CODE])) {
$this->helper->addDebug(__METHOD__ . '|10|');
return;
}
Expand Down
Loading

0 comments on commit 3dd51fb

Please sign in to comment.