From d0dadc97ed985401d170e410bb1f2aea39a89223 Mon Sep 17 00:00:00 2001 From: vegimcarkaxhija Date: Fri, 24 Jan 2025 10:59:50 +0100 Subject: [PATCH] revert hosted fields --- Magewire/Payment/Method/Creditcard.php | 114 ++++++++++++++++++ etc/frontend/di.xml | 1 + .../layout/hyva_checkout_components.xml | 10 ++ .../component/payment/method/creditcard.phtml | 56 +++++++++ 4 files changed, 181 insertions(+) create mode 100644 Magewire/Payment/Method/Creditcard.php create mode 100644 view/frontend/templates/component/payment/method/creditcard.phtml diff --git a/Magewire/Payment/Method/Creditcard.php b/Magewire/Payment/Method/Creditcard.php new file mode 100644 index 0000000..4c5acc5 --- /dev/null +++ b/Magewire/Payment/Method/Creditcard.php @@ -0,0 +1,114 @@ + 'Saving card type' + ]; + + protected $rules = [ + 'cardType' => 'required' + ]; + + protected $messages = [ + 'cardType:required' => 'A card type is required' + ]; + + protected SessionCheckout $sessionCheckout; + + protected CartRepositoryInterface $quoteRepository; + + protected ScopeConfigInterface $scopeConfig; + + protected MethodConfigProvider $methodConfigProvider; + + public function __construct( + Validator $validator, + SessionCheckout $sessionCheckout, + CartRepositoryInterface $quoteRepository, + ScopeConfigInterface $scopeConfig, + MethodConfigProvider $methodConfigProvider + ) { + parent::__construct($validator); + + $this->sessionCheckout = $sessionCheckout; + $this->quoteRepository = $quoteRepository; + $this->scopeConfig = $scopeConfig; + $this->methodConfigProvider = $methodConfigProvider; + } + + /** + * @throws LocalizedException + * @throws NoSuchEntityException + */ + public function mount(): void + { + $this->cardType = $this->sessionCheckout + ->getQuote() + ->getPayment() + ->getAdditionalInformation('card_type'); + } + + /** + * Listen for bank cardType been updated. + */ + public function updatedCardType(string $value): ?string + { + $this->validateOnly(); + $value = empty($value) ? null : $value; + + try { + $quote = $this->sessionCheckout->getQuote(); + $quote->getPayment()->setAdditionalInformation('card_type', $value); + + $this->quoteRepository->save($quote); + } catch (LocalizedException $exception) { + $this->dispatchErrorMessage($exception->getMessage()); + } + + return $value; + } + public function evaluateCompletion(EvaluationResultFactory $resultFactory): EvaluationResultInterface + { + if ($this->cardType === null) { + return $resultFactory->createErrorMessageEvent() + ->withCustomEvent('payment:method:error') + ->withMessage('A card type is required'); + } + + return $resultFactory->createSuccess(); + } + + public function getIssuers(): array + { + return $this->methodConfigProvider->formatIssuers(); + } + + public function displayAsSelect($storeId = null): bool + { + return $this->scopeConfig->getValue( + MethodIdeal::XPATH_IDEAL_SELECTION_TYPE, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $storeId + ) === '2'; + } +} diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 427e08b..906255e 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -19,6 +19,7 @@ \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService + \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService \Buckaroo\HyvaCheckout\Model\Magewire\Payment\PlaceOrderService diff --git a/view/frontend/layout/hyva_checkout_components.xml b/view/frontend/layout/hyva_checkout_components.xml index 0553026..2e3d8a6 100644 --- a/view/frontend/layout/hyva_checkout_components.xml +++ b/view/frontend/layout/hyva_checkout_components.xml @@ -45,6 +45,16 @@ + + + + \Buckaroo\HyvaCheckout\Magewire\Payment\Method\Creditcard + + + + diff --git a/view/frontend/templates/component/payment/method/creditcard.phtml b/view/frontend/templates/component/payment/method/creditcard.phtml new file mode 100644 index 0000000..f7d46e8 --- /dev/null +++ b/view/frontend/templates/component/payment/method/creditcard.phtml @@ -0,0 +1,56 @@ +getIssuers(); + +?> +
+
+ displayAsSelect()) { ?> + + + +

escapeHtml(__('Select a Credit Card or Debit Card:')); ?>

+ +
+ " + value="escapeHtmlAttr($issuer["code"]) ?>" + /> + +
+ + +
+