Skip to content

Commit

Permalink
Merge branch 'release/v5.1.0' into 'master'
Browse files Browse the repository at this point in the history
release/v5.1.0 into master

See merge request agence-dnd/marketplace/magento-2/external/module-checkout-magento2-plugin!123
  • Loading branch information
JuliosDnd committed Jul 4, 2023
2 parents 4f6b817 + ffb32df commit d793452
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 102 deletions.
82 changes: 24 additions & 58 deletions Block/Adminhtml/Order/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

namespace CheckoutCom\Magento2\Block\Adminhtml\Order\View;

use CheckoutCom\Magento2\Gateway\Config\Loader;
use CheckoutCom\Magento2\Helper\Utilities;
use CheckoutCom\Magento2\Model\Config\Backend\Source\ConfigAlternativePayments;
use CheckoutCom\Magento2\Model\Methods\AlternativePaymentMethod;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\App\Request\Http;
Expand All @@ -27,52 +30,30 @@

class View extends Template
{
/**
* $utilities field
*
* @var Utilities $utilities
*/
private $utilities;
/**
* $request field
*
* @var Http $request
*/
private $request;
/**
* $orderRepository field
*
* @var OrderRepositoryInterface $orderRepository
*/
private $orderRepository;

/**
* @param Context $context
* @param Utilities $utilities
* @param Http $request
* @param OrderRepositoryInterface $orderRepository
* @param array $data
*/
private Utilities $utilities;
private Http $request;
private OrderRepositoryInterface $orderRepository;
private ConfigAlternativePayments $configAlternativePayments;
private Loader $configLoader;

public function __construct(
Context $context,
Utilities $utilities,
Http $request,
OrderRepositoryInterface $orderRepository,
ConfigAlternativePayments $configAlternativePayments,
Loader $configLoader,
array $data = []
) {
parent::__construct($context, $data);

$this->utilities = $utilities;
$this->request = $request;
$this->orderRepository = $orderRepository;
$this->configAlternativePayments = $configAlternativePayments;
$this->configLoader = $configLoader;
}

/**
* @param string $data
*
* @return string|null
* @throws LocalizedException
*/
public function getCkoPaymentData(string $data): ?string
{
$paymentData = $this->utilities->getPaymentData($this->getOrder(), 'cko_payment_information')['source'] ?? [];
Expand All @@ -83,12 +64,6 @@ public function getCkoPaymentData(string $data): ?string
return null;
}

/**
* @param string $data
*
* @return string|null
* @throws LocalizedException
*/
public function getCko3dsPaymentData(string $data): ?string
{
$paymentData = $this->utilities->getPaymentData($this->getOrder(), 'cko_threeDs')['threeDs'] ?? [];
Expand All @@ -99,21 +74,11 @@ public function getCko3dsPaymentData(string $data): ?string
return null;
}

/**
* Get order
*
* @return OrderInterface $order
*/
private function getOrder(): OrderInterface
{
return $this->orderRepository->get($this->request->getParam('order_id'));
}

/**
* @param string $avsCheckCode
*
* @return string
*/
public function getAvsCheckDescription(string $avsCheckCode): string
{
switch ($avsCheckCode) {
Expand Down Expand Up @@ -163,11 +128,6 @@ public function getAvsCheckDescription(string $avsCheckCode): string
}
}

/**
* @param string $cvvCheckCode
*
* @return string
*/
public function getCvvCheckDescription(string $cvvCheckCode): string
{
switch ($cvvCheckCode) {
Expand All @@ -188,11 +148,6 @@ public function getCvvCheckDescription(string $cvvCheckCode): string
}
}

/**
* @param string $threeDsCode
*
* @return string
*/
public function get3dsDescription(string $threeDsCode): string
{
switch ($threeDsCode) {
Expand All @@ -216,4 +171,15 @@ public function get3dsDescription(string $threeDsCode): string
return '';
}
}

public function getAlternativePaymentMethodName(): string
{
$methodId = $this->getOrder()->getPayment()->getAdditionalInformation()['method_id'] ?? '';
return $methodId ?? $this->configLoader->getApmLabel($methodId)[$methodId];
}

public function getAlternativePaymentMethodTransactionInfo(): string
{
return $this->getOrder()->getPayment()->getAdditionalInformation()['transaction_info']['id'] ?? '';
}
}
40 changes: 25 additions & 15 deletions Block/Cart/ApplePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@

namespace CheckoutCom\Magento2\Block\Cart;

use CheckoutCom\Magento2\Gateway\Config\Config;
use CheckoutCom\Magento2\Model\Ui\ConfigProvider;
use Magento\Checkout\Block\Onepage;
use Magento\Checkout\Model\Cart;
use Magento\Checkout\Model\CompositeConfigProvider;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Serialize\Serializer\JsonHexTag;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Template\Context;

class ApplePay extends Onepage
{
protected Cart $cart;
private Cart $cart;
private ConfigProvider $checkoutComConfigProvider;
private SerializerInterface $serializer;

/**
* @param Cart $cart
* @param Context $context
* @param FormKey $formKey
* @param CompositeConfigProvider $configProvider
* @param array $layoutProcessors
* @param array $data
* @param Json|null $serializer
* @param SerializerInterface|null $serializerInterface
*/
public function __construct(
Cart $cart,
Context $context,
FormKey $formKey,
CompositeConfigProvider $configProvider,
Config $checkoutComConfig,
ConfigProvider $checkoutComConfigProvider,
array $layoutProcessors = [],
array $data = [],
Json $serializer = null,
Expand All @@ -61,12 +61,11 @@ public function __construct(
$serializerInterface
);
$this->cart = $cart;
$this->checkoutComConfigProvider = $checkoutComConfigProvider;
$this->serializer = $serializerInterface ?: ObjectManager::getInstance()
->get(JsonHexTag::class);
}

/**
*
* @return int
*/
public function getProductCount(): int
{
$productCount = 0;
Expand All @@ -76,4 +75,15 @@ public function getProductCount(): int

return $productCount;
}

/**
* @throws NoSuchEntityException
* @throws LocalizedException
*/
public function getSerializedCheckoutComConfig(): string
{
$config = $this->checkoutComConfigProvider->getConfig();

return $this->serializer->serialize($config);
}
}
15 changes: 15 additions & 0 deletions Gateway/Config/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ public function loadApmList(): array
return $output;
}

public function getApmLabel(string $value = ''): array
{
/** @var array $apmXmlData */
$apmXmlData = $this->loadApmXmlData();

foreach ($apmXmlData as $row) {
if ($value === $row['id']) {
return [$row['id'] => $row['title']];
}
$output[$row['id']] = $row['title'];
}

return $output;
}

/**
* Finds a file path from file name.
*
Expand Down
23 changes: 16 additions & 7 deletions Model/Vault/VaultToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
use DateTimeZone;
use Exception;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Zend_Json;

/**
* Class VaultToken
Expand All @@ -52,22 +52,31 @@ class VaultToken
* @var CardHandlerService $cardHandler
*/
private $cardHandler;
/**
* $json field
*
* @var JsonSerializer
*/
private $json;

/**
* VaultToken constructor
*
* @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param EncryptorInterface $encryptor
* @param CardHandlerService $cardHandler
* @param EncryptorInterface $encryptor
* @param CardHandlerService $cardHandler
* @param JsonSerializer $json
*/
public function __construct(
PaymentTokenFactoryInterface $paymentTokenFactory,
EncryptorInterface $encryptor,
CardHandlerService $cardHandler
CardHandlerService $cardHandler,
JsonSerializer $json
) {
$this->paymentTokenFactory = $paymentTokenFactory;
$this->encryptor = $encryptor;
$this->cardHandler = $cardHandler;
$this->encryptor = $encryptor;
$this->cardHandler = $cardHandler;
$this->json = $json;
}

/**
Expand Down Expand Up @@ -165,7 +174,7 @@ private function generatePublicHash(PaymentTokenInterface $paymentToken): string
*/
private function convertDetailsToJSON(array $details): string
{
$json = Zend_Json::encode($details);
$json = $this->json->serialize($details);

return $json ?: '{}';
}
Expand Down
30 changes: 30 additions & 0 deletions Plugin/AddConfigDataToCart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace CheckoutCom\Magento2\Plugin;

use CheckoutCom\Magento2\Gateway\Config\Config;
use Magento\Checkout\CustomerData\Cart;
use Magento\Checkout\Model\CompositeConfigProvider;

class AddConfigDataToCart
{
private Config $config;
private CompositeConfigProvider $compositeConfigProvider;

public function __construct(
Config $config,
CompositeConfigProvider $compositeConfigProvider
) {
$this->config = $config;
$this->compositeConfigProvider = $compositeConfigProvider;
}

public function afterGetSectionData(Cart $subject, array $result): array
{
$configProvider = ['checkoutConfigProvider' => $this->compositeConfigProvider->getConfig()];

return array_merge($this->config->getMethodsConfig(), $configProvider, $result);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"magento/framework": ">=100.0.1"
},
"type": "magento2-module",
"version": "5.0.0",
"version": "5.1.0",
"autoload": {
"files": [
"registration.php"
Expand Down
6 changes: 3 additions & 3 deletions etc/apm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
<id>klarna</id>
<title>Klarna</title>
<currencies>EUR,DKK,GBP,NOK,SEK</currencies>
<countries>AT,DK,FI,DE,NL,NO,SE,GB</countries>
<countries>AT,DK,ES,FI,DE,NL,NO,SE,GB</countries>
<mappings>
<EUR>AT,FI,DE,NL,DK,NO,SE</EUR>
<EUR>AT,ES,FI,DE,NL,DK,NO,SE</EUR>
<DKK>DK</DKK>
<GBP>GB</GBP>
<NOK>NO</NOK>
Expand Down Expand Up @@ -103,4 +103,4 @@
<currencies>KWD</currencies>
<countries>KW</countries>
</item>
</config>
</config>
5 changes: 5 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@
</argument>
</arguments>
</type>

<!-- Add Config Data To Cart Section -->
<type name="Magento\Checkout\CustomerData\Cart">
<plugin name="checkoutcom_magento2_add_config_data_to_cart" type="CheckoutCom\Magento2\Plugin\AddConfigDataToCart"/>
</type>
</config>
2 changes: 2 additions & 0 deletions i18n/en_GB.csv
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Debitor,Debitor
"3DS authorization code","3DS authorization code"
"Payment Method refunded","Payment Method refunded"
"Mismatched Address (fraud check)","Mismatched Address (fraud check)"
"Alternative payment method","Alternative payment method"
"Transaction Id","Transaction Id"
"Card Country","Card Country"
"Card Bank","Card Bank"
"Card expiry year","Card expiry year"
Expand Down
2 changes: 2 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Debitor,Debitor
"3DS authorization code","3DS authorization code"
"Payment Method refunded","Payment Method refunded"
"Mismatched Address (fraud check)","Mismatched Address (fraud check)"
"Alternative payment method","Alternative payment method"
"Transaction Id","Transaction Id"
"Card Country","Card Country"
"Card Bank","Card Bank"
"Card expiry year","Card expiry year"
Expand Down
Loading

0 comments on commit d793452

Please sign in to comment.