Skip to content

Commit ea4ffd7

Browse files
authored
DAVAMS-484: Add MyBank payment method (#535)
* DAVAMS-484: Add MyBank payment method * DAVAMS-484: Unify IdealGatewayInfoBuilder and MyBankGatewayInfoBuilder * DAVAMS-484: Unify event MyBankDataAssignObserver and IdealDataAssignObserver in IssuersDataAssignObserver * DAVAMS-484: Refactor getIssuers, moving this method to GenericConfigProvider * DAVAMS-484: PHPCS tuning * DAVAMS-484: PHPCS tuning * DAVAMS-484: Refactor method getStoreIdFromCheckoutSession
1 parent 2baf254 commit ea4ffd7

File tree

12 files changed

+270
-57
lines changed

12 files changed

+270
-57
lines changed

Logger/Logger.php

-15
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,6 @@ public function logGetRequestApiException(string $orderId, ApiException $apiExce
9797
$this->debug($apiException->getDetails());
9898
}
9999

100-
/**
101-
* @param string $orderId
102-
* @param ApiException $apiException
103-
* @return void
104-
*/
105-
public function logGetIssuersApiException(string $orderId, ApiException $apiException): void
106-
{
107-
$this->error(
108-
'(Order ID: ' . $orderId . ') MultiSafepay error when trying to retrieve the iDEAL issuers. Error: ' .
109-
$apiException->getCode() . ' ' . $apiException->getMessage()
110-
);
111-
112-
$this->debug($apiException->getDetails());
113-
}
114-
115100
/**
116101
* @param string $orderId
117102
* @param ApiException $apiException

Model/Api/Builder/OrderRequestBuilder/GatewayInfoBuilder.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
use MultiSafepay\Api\Transactions\OrderRequest;
2424
use MultiSafepay\ConnectCore\Model\Api\Builder\OrderRequestBuilder\GatewayInfoBuilder\GatewayInfoBuilderInterface;
2525
use MultiSafepay\ConnectCore\Model\Ui\Gateway\IdealConfigProvider;
26+
use MultiSafepay\ConnectCore\Model\Ui\Gateway\MyBankConfigProvider;
2627

2728
class GatewayInfoBuilder implements OrderRequestBuilderInterface
2829
{
30+
public const GATEWAY_WITH_ISSUER_LIST = [IdealConfigProvider::CODE, MyBankConfigProvider::CODE];
31+
2932
/**
3033
* @var GatewayInfoBuilderInterface[]
3134
*/
@@ -61,7 +64,7 @@ public function build(OrderInterface $order, OrderPaymentInterface $payment, Ord
6164
return;
6265
}
6366

64-
if ($paymentCode === IdealConfigProvider::CODE
67+
if (in_array($paymentCode, self::GATEWAY_WITH_ISSUER_LIST, true)
6568
&& !isset($payment->getAdditionalInformation()['issuer_id'])
6669
) {
6770
return;

Model/Api/Builder/OrderRequestBuilder/GatewayInfoBuilder/IdealGatewayInfoBuilder.php renamed to Model/Api/Builder/OrderRequestBuilder/GatewayInfoBuilder/IssuerGatewayInfoBuilder.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,34 @@
1919

2020
use Magento\Sales\Api\Data\OrderInterface;
2121
use Magento\Sales\Api\Data\OrderPaymentInterface;
22-
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\GatewayInfo\Ideal;
22+
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\GatewayInfo\Issuer;
23+
use MultiSafepay\Api\Transactions\OrderRequest\Arguments\GatewayInfoInterface;
2324

24-
class IdealGatewayInfoBuilder implements GatewayInfoBuilderInterface
25+
class IssuerGatewayInfoBuilder implements GatewayInfoBuilderInterface
2526
{
2627
/**
27-
* @var Ideal
28+
* @var Issuer
2829
*/
29-
private $ideal;
30+
private $issuer;
3031

3132
/**
3233
* GatewayInfo constructor.
3334
*
34-
* @param Ideal $ideal
35+
* @param Issuer $issuer
3536
*/
3637
public function __construct(
37-
Ideal $ideal
38+
Issuer $issuer
3839
) {
39-
$this->ideal = $ideal;
40+
$this->issuer = $issuer;
4041
}
4142

4243
/**
4344
* @param OrderInterface $order
4445
* @param OrderPaymentInterface $payment
45-
* @return Ideal
46+
* @return GatewayInfoInterface
4647
*/
47-
public function build(OrderInterface $order, OrderPaymentInterface $payment): Ideal
48+
public function build(OrderInterface $order, OrderPaymentInterface $payment): GatewayInfoInterface
4849
{
49-
return $this->ideal->addIssuerId($payment->getAdditionalInformation()['issuer_id']);
50+
return $this->issuer->addIssuerId($payment->getAdditionalInformation()['issuer_id']);
5051
}
5152
}

Model/Ui/Gateway/IdealConfigProvider.php

-22
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,4 @@ public function getConfig(): array
4646
],
4747
];
4848
}
49-
50-
/**
51-
* @return array
52-
* @throws ClientExceptionInterface
53-
*/
54-
public function getIssuers(): array
55-
{
56-
$issuers = [];
57-
58-
if ($multiSafepaySdk = $this->getSdk()) {
59-
$issuerListing = $multiSafepaySdk->getIssuerManager()->getIssuersByGatewayCode('IDEAL');
60-
61-
foreach ($issuerListing as $issuer) {
62-
$issuers[] = [
63-
'code' => $issuer->getCode(),
64-
'description' => $issuer->getDescription(),
65-
];
66-
}
67-
}
68-
69-
return $issuers;
70-
}
7149
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
*
4+
* NOTICE OF LICENSE
5+
*
6+
* This source file is subject to the Open Software License (OSL 3.0)
7+
* that is provided with Magento in the file LICENSE.txt.
8+
* It is also available through the world-wide-web at this URL:
9+
* http://opensource.org/licenses/osl-3.0.php
10+
*
11+
* Copyright © 2022 MultiSafepay, Inc. All rights reserved.
12+
* See DISCLAIMER.md for disclaimer details.
13+
*
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace MultiSafepay\ConnectCore\Model\Ui\Gateway;
19+
20+
use Magento\Framework\Exception\LocalizedException;
21+
use MultiSafepay\ConnectCore\Model\Ui\GenericConfigProvider;
22+
use Psr\Http\Client\ClientExceptionInterface;
23+
24+
class MyBankConfigProvider extends GenericConfigProvider
25+
{
26+
public const CODE = 'multisafepay_mybank';
27+
28+
/**
29+
* Retrieve assoc array of checkout configuration
30+
*
31+
* @return array
32+
* @throws ClientExceptionInterface
33+
* @throws LocalizedException
34+
*/
35+
public function getConfig(): array
36+
{
37+
return [
38+
'payment' => [
39+
$this->getCode() => [
40+
'issuers' => $this->getIssuers(),
41+
'image' => $this->getImage(),
42+
'is_preselected' => $this->isPreselected(),
43+
],
44+
],
45+
];
46+
}
47+
}

Model/Ui/GenericConfigProvider.php

+50-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use Magento\Checkout\Model\ConfigProviderInterface;
2121
use Magento\Checkout\Model\Session;
22-
use Magento\Framework\App\Config\ScopeConfigInterface;
2322
use Magento\Framework\App\Config\Storage\WriterInterface;
2423
use Magento\Framework\Exception\LocalizedException;
2524
use Magento\Framework\Exception\NoSuchEntityException;
@@ -33,6 +32,7 @@
3332
use MultiSafepay\ConnectCore\Util\JsonHandler;
3433
use MultiSafepay\Exception\ApiException;
3534
use MultiSafepay\Exception\InvalidApiKeyException;
35+
use MultiSafepay\Exception\InvalidArgumentException;
3636
use MultiSafepay\Sdk;
3737
use Psr\Http\Client\ClientExceptionInterface;
3838

@@ -181,15 +181,18 @@ public function isPreselected(): bool
181181
*/
182182
public function getSdk(?int $storeId = null): ?Sdk
183183
{
184+
if ($storeId === null) {
185+
$storeId = $this->getStoreIdFromCheckoutSession();
186+
}
187+
184188
try {
185189
return $this->sdkFactory->create($storeId);
186190
} catch (InvalidApiKeyException $invalidApiKeyException) {
187191
$this->logger->logInvalidApiKeyException($invalidApiKeyException);
188192

189193
return null;
190194
} catch (ApiException $apiException) {
191-
$orderId = $this->checkoutSession->getLastRealOrder()->getIncrementId();
192-
$this->logger->logGetIssuersApiException($orderId, $apiException);
195+
$this->logger->logException($apiException);
193196

194197
return null;
195198
}
@@ -231,7 +234,7 @@ public function getTransactionType(): string
231234

232235
return (string)$this->paymentConfig->getValue(
233236
'transaction_type',
234-
$this->checkoutSession->getQuote()->getStoreId()
237+
$this->getStoreIdFromCheckoutSession()
235238
);
236239
}
237240

@@ -292,4 +295,47 @@ public function getAccountData(int $storeId = null): array
292295

293296
return $accountData;
294297
}
298+
299+
/**
300+
* @return array
301+
* @throws ClientExceptionInterface
302+
*/
303+
public function getIssuers(): array
304+
{
305+
$issuers = [];
306+
307+
if ($multiSafepaySdk = $this->getSdk()) {
308+
try {
309+
$issuerListing = $multiSafepaySdk->getIssuerManager()->getIssuersByGatewayCode($this->getGatewayCode());
310+
foreach ($issuerListing as $issuer) {
311+
$issuers[] = [
312+
'code' => $issuer->getCode(),
313+
'description' => $issuer->getDescription(),
314+
];
315+
}
316+
} catch (InvalidArgumentException $invalidArgumentException) {
317+
$this->logger->logException($invalidArgumentException);
318+
return $issuers;
319+
}
320+
}
321+
322+
return $issuers;
323+
}
324+
325+
/**
326+
* Return the store ID from the Checkout Session
327+
*
328+
* @return int|null
329+
*/
330+
private function getStoreIdFromCheckoutSession(): ?int
331+
{
332+
try {
333+
$storeId = $this->checkoutSession->getQuote()->getStoreId();
334+
} catch (LocalizedException $localizedException) {
335+
$this->logger->logException($localizedException);
336+
return null;
337+
}
338+
339+
return $storeId;
340+
}
295341
}

Observer/Gateway/IdealDataAssignObserver.php renamed to Observer/Gateway/IssuersDataAssignObserver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Magento\Quote\Api\Data\PaymentInterface;
2323
use MultiSafepay\ConnectCore\Model\Api\Builder\OrderRequestBuilder\TransactionTypeBuilder;
2424

25-
class IdealDataAssignObserver extends AbstractDataAssignObserver
25+
class IssuersDataAssignObserver extends AbstractDataAssignObserver
2626
{
2727

2828
/**

Test/Integration/EventsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use MultiSafepay\ConnectCore\Observer\Gateway\DirectBankTransferDataAssignObserver;
2323
use MultiSafepay\ConnectCore\Observer\Gateway\DirectDebitDataAssignObserver;
2424
use MultiSafepay\ConnectCore\Observer\Gateway\EinvoicingDataAssignObserver;
25-
use MultiSafepay\ConnectCore\Observer\Gateway\IdealDataAssignObserver;
25+
use MultiSafepay\ConnectCore\Observer\Gateway\IssuersDataAssignObserver;
2626
use MultiSafepay\ConnectCore\Observer\Gateway\PayafterDataAssignObserver;
2727

2828
class EventsTest extends EventsTestCase
@@ -33,7 +33,7 @@ class EventsTest extends EventsTestCase
3333
public function testForAdminObservers()
3434
{
3535
$this->findObserverForEvent(
36-
IdealDataAssignObserver::class,
36+
IssuersDataAssignObserver::class,
3737
'payment_method_assign_data_multisafepay_ideal'
3838
);
3939

etc/config.xml

+25
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,31 @@
721721
<is_multisafepay>1</is_multisafepay>
722722
<gateway_code>MASTERCARD</gateway_code>
723723
</multisafepay_mastercard>
724+
<multisafepay_mybank>
725+
<active>0</active>
726+
<model>MyBankFacade</model>
727+
<order_status>pending</order_status>
728+
<payment_action>initialize</payment_action>
729+
<title>MyBank</title>
730+
<currency>EUR</currency>
731+
<can_initialize>1</can_initialize>
732+
<can_fetch_transaction_information>1</can_fetch_transaction_information>
733+
<can_fetch_transaction_info>1</can_fetch_transaction_info>
734+
<can_use_checkout>1</can_use_checkout>
735+
<can_use_internal>1</can_use_internal>
736+
<can_refund>1</can_refund>
737+
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
738+
<is_gateway>1</is_gateway>
739+
<sort_order>1</sort_order>
740+
<allowspecific>0</allowspecific>
741+
<allow_specific_currency>0</allow_specific_currency>
742+
<allow_specific_shipping_method>0</allow_specific_shipping_method>
743+
<allow_specific_customer_group>0</allow_specific_customer_group>
744+
<allow_amount>0</allow_amount>
745+
<custom_payment_link_lifetime>0</custom_payment_link_lifetime>
746+
<is_multisafepay>1</is_multisafepay>
747+
<gateway_code>MYBANK</gateway_code>
748+
</multisafepay_mybank>
724749
<multisafepay_paysafecard>
725750
<active>0</active>
726751
<model>MultiSafepayPaysafecardFacade</model>

0 commit comments

Comments
 (0)