diff --git a/Block/Adminhtml/Order/View/View.php b/Block/Adminhtml/Order/View/View.php index 78340e3b..a25f74d6 100644 --- a/Block/Adminhtml/Order/View/View.php +++ b/Block/Adminhtml/Order/View/View.php @@ -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; @@ -27,37 +30,19 @@ 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); @@ -65,14 +50,10 @@ public function __construct( $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'] ?? []; @@ -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'] ?? []; @@ -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) { @@ -163,11 +128,6 @@ public function getAvsCheckDescription(string $avsCheckCode): string } } - /** - * @param string $cvvCheckCode - * - * @return string - */ public function getCvvCheckDescription(string $cvvCheckCode): string { switch ($cvvCheckCode) { @@ -188,11 +148,6 @@ public function getCvvCheckDescription(string $cvvCheckCode): string } } - /** - * @param string $threeDsCode - * - * @return string - */ public function get3dsDescription(string $threeDsCode): string { switch ($threeDsCode) { @@ -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'] ?? ''; + } } diff --git a/Block/Cart/ApplePay.php b/Block/Cart/ApplePay.php index c8ac27fa..8b1ea55d 100644 --- a/Block/Cart/ApplePay.php +++ b/Block/Cart/ApplePay.php @@ -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, @@ -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; @@ -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); + } } diff --git a/Gateway/Config/Loader.php b/Gateway/Config/Loader.php index c640d25b..457d6af9 100755 --- a/Gateway/Config/Loader.php +++ b/Gateway/Config/Loader.php @@ -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. * diff --git a/Model/Vault/VaultToken.php b/Model/Vault/VaultToken.php index 6a6022a5..f5f829d9 100755 --- a/Model/Vault/VaultToken.php +++ b/Model/Vault/VaultToken.php @@ -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 @@ -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; } /** @@ -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 ?: '{}'; } diff --git a/Plugin/AddConfigDataToCart.php b/Plugin/AddConfigDataToCart.php new file mode 100644 index 00000000..ba75c840 --- /dev/null +++ b/Plugin/AddConfigDataToCart.php @@ -0,0 +1,30 @@ +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); + } +} diff --git a/composer.json b/composer.json index b2100d2b..1a847bed 100755 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "magento/framework": ">=100.0.1" }, "type": "magento2-module", - "version": "5.0.0", + "version": "5.1.0", "autoload": { "files": [ "registration.php" diff --git a/etc/apm.xml b/etc/apm.xml index a536866c..9e235be0 100755 --- a/etc/apm.xml +++ b/etc/apm.xml @@ -70,9 +70,9 @@ klarna Klarna EUR,DKK,GBP,NOK,SEK - AT,DK,FI,DE,NL,NO,SE,GB + AT,DK,ES,FI,DE,NL,NO,SE,GB - AT,FI,DE,NL,DK,NO,SE + AT,ES,FI,DE,NL,DK,NO,SE DK GB NO @@ -103,4 +103,4 @@ KWD KW - \ No newline at end of file + diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 8fca5155..929031e2 100755 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -63,4 +63,9 @@ + + + + + diff --git a/i18n/en_GB.csv b/i18n/en_GB.csv index 2a63997f..7e43c6ec 100644 --- a/i18n/en_GB.csv +++ b/i18n/en_GB.csv @@ -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" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 2a63997f..7e43c6ec 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -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" diff --git a/view/adminhtml/templates/order/view/view.phtml b/view/adminhtml/templates/order/view/view.phtml index 38f77927..46f99d20 100644 --- a/view/adminhtml/templates/order/view/view.phtml +++ b/view/adminhtml/templates/order/view/view.phtml @@ -4,18 +4,35 @@ * @var $block \CheckoutCom\Magento2\Block\Adminhtml\Order\View\View */ +$alternativePaymentMethodName = $block->getAlternativePaymentMethodName(); +$alternativePaymentMethodTransactionInfo = $block->getAlternativePaymentMethodTransactionInfo(); $avsCheck = $block->getCkoPaymentData('avs_check'); $cvvCheck = $block->getCkoPaymentData('cvv_check'); $threeDsCode = $block->getCko3dsPaymentData('authentication_response'); $issuer = $block->getCkoPaymentData('issuer'); $threeDsVersion = $block->getCko3dsPaymentData('version'); ?> + +getCkoPaymentData('product_type') && $block->getCkoPaymentData('last4'))) : ?>

escapeHtml(__('Payment Additional Information')) ?>

+ + + + + + + + + + + + + getCkoPaymentData('product_type') && $block->getCkoPaymentData('last4')) : ?> @@ -32,36 +49,38 @@ $threeDsVersion = $block->getCko3dsPaymentData('version'); + - + - + - + - + - +
escapeHtml(__('Alternative payment method')) ?>
escapeHtml(__('Transaction Id')) ?>
escapeHtml(__('Card type')) ?> getCkoPaymentData('scheme') ?> (getCkoPaymentData('product_type') ?>)escapeHtml(__('Card Country')) ?> getCkoPaymentData('issuer_country') ?>
escapeHtml(__('Issuing Bank')) ?>
escapeHtml(__('AVS Check')) ?> (getAvsCheckDescription($avsCheck) ?>)
escapeHtml(__('CVV Check')) ?> (getCvvCheckDescription($cvvCheck) ?>)
escapeHtml(__('3DS authorization code')) ?> (get3dsDescription($threeDsCode) ?>)
escapeHtml(__('3DS version')) ?>
+ diff --git a/view/frontend/layout/default.xml b/view/frontend/layout/default.xml index 8652966e..5d705221 100644 --- a/view/frontend/layout/default.xml +++ b/view/frontend/layout/default.xml @@ -20,7 +20,7 @@ - uiComponent + CheckoutCom_Magento2/js/view/minicart/applepaybutton CheckoutCom_Magento2/checkout/minicart/applepaybutton diff --git a/view/frontend/templates/cart/minicart-config.phtml b/view/frontend/templates/cart/minicart-config.phtml index 89abc842..2c43de4f 100644 --- a/view/frontend/templates/cart/minicart-config.phtml +++ b/view/frontend/templates/cart/minicart-config.phtml @@ -9,15 +9,12 @@ /** @var \CheckoutCom\Magento2\Block\Cart\ApplePay $block */ /** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */ ?> - -getProductCount() > 0): ?> - getSerializedCheckoutConfig(); - $scriptString = <<