diff --git a/Block/System/Config/GooglePayChannelId.php b/Block/System/Config/GooglePayChannelId.php index 20adfab..5e9018e 100644 --- a/Block/System/Config/GooglePayChannelId.php +++ b/Block/System/Config/GooglePayChannelId.php @@ -4,10 +4,14 @@ namespace Unzer\PAPI\Block\System\Config; use Magento\Backend\Block\Template\Context; +use Magento\Backend\Block\Widget\Button; + use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; -use Unzer\PAPI\Model\Config; -use UnzerSDK\Exceptions\UnzerApiException; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Serialize\SerializerInterface; +use Unzer\PAPI\Controller\Adminhtml\Webhooks\AbstractAction; /** * Adminhtml Webhook Configuration Buttons Block @@ -16,70 +20,79 @@ */ class GooglePayChannelId extends Field { - /** - * @var Config - */ - private Config $configHelper; + /** @var string */ + protected $_template = 'Unzer_PAPI::system/config/googlepaychannelid.phtml'; /** * Constructor * * @param Context $context - * @param Config $configHelper + * @param SerializerInterface $serializer * @param array $data */ public function __construct( Context $context, - Config $configHelper, + SerializerInterface $serializer, array $data = [] ) { parent::__construct($context, $data); - $this->configHelper = $configHelper; + $this->serializer = $serializer; } /** * @inheritDoc * - * @throws UnzerApiException + * @throws LocalizedException */ protected function _getElementHtml(AbstractElement $element): string { - if ($element->getValue() === '' || $element->getValue() === null) { - $element->setValue($this->fetchChannelId()); - } + $button = $this->getGooglePayChannelIdButton(); - return $element->getElementHtml(); + $block = $this->_layout->createBlock(self::class); + $block->setTemplate('Unzer_PAPI::system/config/googlepaychannelid.phtml') + ->setChild('button', $button); + return parent::_getElementHtml($element) . $block->toHtml(); } /** - * Fetch Channel ID + * Get Google Pay Channel ID Button * - * @return string - * @throws UnzerApiException + * @return Button + * @throws LocalizedException */ - private function fetchChannelId(): string + public function getGooglePayChannelIdButton(): Button { - $keyPair = $this->configHelper->getUnzerClient()->getResourceService()->fetchKeypair(true); - - foreach ($keyPair->getPaymentTypes() as $paymentType) { - if (!property_exists($paymentType, 'type')) { - continue; - } - if ($paymentType->type === 'googlepay') { - if (!property_exists($paymentType, 'supports')) { - return ''; - } - if (!is_array($paymentType->supports) || !array_key_exists(0, $paymentType->supports)) { - return ''; - } - if (!property_exists($paymentType->supports[0], 'channel')) { - return ''; - } + $button = $this->getLayout()->createBlock(Button::class); + $button->setData([ + 'id' => 'unzer_googlepay_channelid', + 'label' => __('Fetch Gateway Merchant ID'), + ]); + return $button; + } - return $paymentType->supports[0]->channel; - } - } + /** + * Get Channel ID Action + * + * @return string + * @throws NoSuchEntityException + */ + public function getChannelIdAction(): string + { + return $this->getUrl('unzer/googlepay/channelid', [ + AbstractAction::URL_PARAM_STORE => $this->getStoreIdentifier() + ]); + } - return ''; + /** + * Get Store Identifier + * + * @return int + * @throws NoSuchEntityException + */ + protected function getStoreIdentifier(): int + { + /** @var int|string $storeIdentifier */ + $storeIdentifier = $this->getRequest()->getParam(AbstractAction::URL_PARAM_STORE, 0); + return (int)$this->_storeManager->getStore($storeIdentifier)->getId(); } } diff --git a/CHANGELOG.md b/CHANGELOG.md index d14726f..fa06d81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [3.2.0](https://github.com/unzerdev/magento2/compare/3.1.0..3.2.0) +### Added +* TWINT payment method +### Changed +* automatic fetching of Google Pay Gateway Merchant ID to manual fetching by adding a button for fetching of the ID +* Giropay to be deactivated in checkout and marked as deprecated +### Removed +* Discover and JCB from available Google Pay card list + ## [3.1.0](https://github.com/unzerdev/magento2/compare/3.0.0..3.1.0) ### Added * Google Pay ### Changed * Terms and Conditions are now included in the input check for the "Place Order" button to get activated. Additionally to all required input fields, all terms need to be checked, too. See the [terms-checked.js file]( view/frontend/web/js/model/checkout/terms-checked.js) * system.xml to include separate files for each payment method instead of keeping everything in one file -* refactored Apple Pay "supported networks" to allow "supported networks" for Google Pay, too +* refactored Apple Pay "supported networks" to allow "supported networks" for Google Pay, too ### Fixed * Threat Metrix data was not correctly handled for some payment methods diff --git a/Controller/Adminhtml/Googlepay/ChannelId.php b/Controller/Adminhtml/Googlepay/ChannelId.php new file mode 100644 index 0000000..9b710e2 --- /dev/null +++ b/Controller/Adminhtml/Googlepay/ChannelId.php @@ -0,0 +1,92 @@ +configHelper = $configHelper; + $this->jsonFactory = $jsonFactory; + $this->request = $request; + } + + /** + * Controller execution. + * + * @return Json + * @throws UnzerApiException + */ + public function execute(): Json + { + $json = $this->jsonFactory->create(); + $data = [ + 'channel_id' => $this->fetchChannelId(), + ]; + $json->setData($data); + + return $json; + } + + /** + * Fetch Channel ID + * + * @return string + * @throws UnzerApiException + */ + private function fetchChannelId(): string + { + $storeId = (string) $this->request->getParam('store', 0); + + $keyPair = $this->configHelper->getUnzerClient($storeId)->getResourceService()->fetchKeypair(true); + + foreach ($keyPair->getPaymentTypes() as $paymentType) { + if (!property_exists($paymentType, 'type')) { + continue; + } + if ($paymentType->type === 'googlepay') { + if (!property_exists($paymentType, 'supports')) { + return ''; + } + if (!is_array($paymentType->supports) || !array_key_exists(0, $paymentType->supports)) { + return ''; + } + if (!property_exists($paymentType->supports[0], 'channel')) { + return ''; + } + + return $paymentType->supports[0]->channel; + } + } + + return ''; + } +} diff --git a/Model/Config.php b/Model/Config.php index 71f4c95..51b7d27 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -56,6 +56,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config public const METHOD_PREPAYMENT = 'unzer_prepayment'; public const METHOD_APPLEPAY = 'unzer_applepay'; public const METHOD_GOOGLEPAY = 'unzer_googlepay'; + public const METHOD_TWINT = 'unzer_twint'; /** * @var DebugHandler diff --git a/Model/Config/Provider.php b/Model/Config/Provider.php index dd8b6ed..9c0e9ed 100644 --- a/Model/Config/Provider.php +++ b/Model/Config/Provider.php @@ -45,6 +45,7 @@ class Provider implements ConfigProviderInterface Config::METHOD_PREPAYMENT, Config::METHOD_APPLEPAY, Config::METHOD_GOOGLEPAY, + Config::METHOD_TWINT, ]; /** diff --git a/Model/Method/Giropay.php b/Model/Method/Giropay.php index 4665600..cea1a6e 100644 --- a/Model/Method/Giropay.php +++ b/Model/Method/Giropay.php @@ -7,6 +7,8 @@ * Giropay payment method * * @link https://docs.unzer.com/ + * @deprecated + * @see https://docs.unzer.com/payment-methods/giropay/ */ class Giropay extends Base { diff --git a/Model/Method/Twint.php b/Model/Method/Twint.php new file mode 100644 index 0000000..7dab231 --- /dev/null +++ b/Model/Method/Twint.php @@ -0,0 +1,20 @@ +config = $config; + } + + /** + * Validate + * + * @param array $validationSubject + * @return bool|ResultInterface + * @throws Exception + */ + public function validate(array $validationSubject) + { + $isValid = true; + + /** @var string|null $currencyString */ + $currencyString = $this->config->getValue('currency_restrictions', $validationSubject['storeId']); + + if (!empty($currencyString)) { + /** @var string[] $currencies */ + $currencies = preg_split('/\s*,\s*/', $currencyString); + + if (!in_array($validationSubject['currency'], $currencies)) { + $isValid = false; + } + } + + return $this->createResult($isValid); + } +} diff --git a/composer.json b/composer.json index 561b0b6..c5273b9 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "unzerdev/magento2", "description": "This extension for Magento 2 provides a direct integration of the Unzer payment types to your Magento 2 shop via the Unzer Payment API (PAPI).", "type": "magento2-module", - "version": "3.1.0", + "version": "3.2.0", "license": "Apache-2.0", "require": { "php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0", diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c4d21c8..ef98938 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -71,6 +71,7 @@ + diff --git a/etc/adminhtml/system/googlepay.xml b/etc/adminhtml/system/googlepay.xml index 712d0cd..9c034ff 100644 --- a/etc/adminhtml/system/googlepay.xml +++ b/etc/adminhtml/system/googlepay.xml @@ -41,7 +41,7 @@ payment/unzer_googlepay/unzer_channel_id Unzer\PAPI\Block\System\Config\GooglePayChannelId - + diff --git a/etc/adminhtml/system/twint.xml b/etc/adminhtml/system/twint.xml new file mode 100644 index 0000000..e7c3087 --- /dev/null +++ b/etc/adminhtml/system/twint.xml @@ -0,0 +1,34 @@ + + + + + + + Magento\Config\Model\Config\Source\Yesno + payment/unzer_twint/active + + + + payment/unzer_twint/title + + + + payment/unzer_twint/min_order_total + + + + payment/unzer_twint/max_order_total + Insert 0 to disable limit. + + + + payment/unzer_twint/sort_order + + + diff --git a/etc/config.xml b/etc/config.xml index 231c322..6bbf5f3 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -276,14 +276,14 @@ 0 order authorize_capture - <![CDATA[Giropay]]> + <![CDATA[(Deprecated) Giropay]]> 0 0 0 0 1 1 - 1 + 0 0 DE Unzer\PAPI\Model\Method\Giropay @@ -350,6 +350,7 @@ 1 0 PL + PLN Unzer\PAPI\Model\Method\Przelewy24 @@ -424,6 +425,23 @@ fill 2 + + 0 + order + authorize_capture + <![CDATA[TWINT]]> + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 0 + CH + CHF + Unzer\PAPI\Model\Method\Twint + diff --git a/etc/di.xml b/etc/di.xml index a322ac7..5357140 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1203,10 +1203,17 @@ + + + UnzerPrzelewy24Config + + + UnzerPrzelewy24ValidatorCountry + UnzerPrzelewy24ValidatorCurrency @@ -1425,4 +1432,61 @@ UnzerAuthorizeAndCaptureCommandPool + + + + + Unzer\PAPI\Model\Config::METHOD_TWINT + + + + + + UnzerTwintConfig + + + + + + + UnzerTwintConfigValueHandler + Unzer\PAPI\Model\Config\CanCancelHandler + Unzer\PAPI\Model\Config\CanRefundHandler + Unzer\PAPI\Model\Config\CanRefundHandler + Unzer\PAPI\Model\Config\CanVoidHandler + + + + + + + UnzerTwintConfig + + + + + + UnzerTwintConfig + + + + + + + UnzerTwintValidatorCountry + UnzerTwintValidatorCurrency + + + + + + + Unzer\PAPI\Model\Config::METHOD_TWINT + Magento\Payment\Block\Form + Magento\Payment\Block\Info + UnzerTwintValueHandlerPool + UnzerTwintValidatorPool + UnzerAuthorizeAndCaptureCommandPool + + diff --git a/etc/events.xml b/etc/events.xml index 1419f63..be07425 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -69,4 +69,7 @@ + + + diff --git a/etc/module.xml b/etc/module.xml index 998c23f..6d10fee 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index b4045b2..e73d5de 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -4,7 +4,7 @@ "UNZER_DIRECT_DEBIT","SEPA Lastschrift" "UNZER_DIRECT_DEBIT_SECURED","(Veraltet) SEPA Lastschrift Gesichert" "UNZER_EPS","EPS" -"UNZER_GIROPAY","Giropay" +"UNZER_GIROPAY","(Veraltet) Giropay" "UNZER_BANK_TRANSFER","Unzer Direktüberweisung" "UNZER_IDEAL","iDEAL" "UNZER_INVOICE","(Veraltet) Unzer Rechnungskauf" @@ -25,6 +25,7 @@ "UNZER_ABOUT_US","Unzer ist eine innovative und modulare Plattform für den internationalen Zahlungsverkehr. Unternehmen aller Größen und Branchen vertrauen auf die datengetriebenen, sicheren und passgenauen Lösungen für mehr Wachstum – online, mobil oder am Point of Sale. Die einfach integrierbaren Module decken das gesamte Spektrum des Zahlungsmanagements ab: Von der Abwicklung verschiedener Zahlungsarten über automatisierte Analysen von Kundenverhalten und -bedürfnissen bis hin zum ganzheitlichen Risikomanagement.

Mehr Informationen finden Sie auf www.unzer.com" "UNZER_APPLEPAY","Apple Pay" "UNZER_GOOGLEPAY","Google Pay" +"UNZER_TWINT","TWINT" "MODULE_VERSION_LABEL","Modul-Version:" "ABOUT_UNZER_LABEL","Über Unzer:" @@ -49,7 +50,7 @@ "SEPA Direct Debit","SEPA Lastschrift" "(Deprecated) SEPA Direct Debit Secured","(Veraltet) SEPA Lastschrift Gesichert" "EPS","EPS" -"Giropay","Giropay" +"(Deprecated) Giropay","(Veraltet) Giropay" "iDEAL","iDEAL" "(Deprecated) Unzer Invoice Secured B2B","(Veraltet) Rechnungskauf Gesichert B2B" "(Deprecated) Unzer Invoice Secured","(Veraltet) Rechnungskauf Gesichert" @@ -69,6 +70,7 @@ "Unzer Prepayment","Unzer Vorkasse" "ApplePay","ApplePay" "GooglePay","GooglePay" +"TWINT","TWINT" "Customer Information","Kundendaten" "mr","Herr" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 4cbde9c..76ce65e 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -4,7 +4,7 @@ "UNZER_DIRECT_DEBIT","SEPA Direct Debit" "UNZER_DIRECT_DEBIT_SECURED","(Deprecated) SEPA Direct Debit Secured" "UNZER_EPS","EPS" -"UNZER_GIROPAY","Giropay" +"UNZER_GIROPAY","(Deprecated) Giropay" "UNZER_BANK_TRANSFER","Unzer Bank Transfer" "UNZER_IDEAL","iDEAL" "UNZER_INVOICE","(Deprecated) Unzer Invoice" @@ -25,6 +25,7 @@ "UNZER_ABOUT_US","Unzer is an innovative and modular platform for international payment transactions. Companies of all sizes and from all sectors rely on the data-driven, secure and perfectly tailored solutions to help them drive growth – whether online, mobile or at the point of sale. The modules, which are easy to integrate, cover the entire spectrum of payment management: from processing of various payment types, through automated analytics of customer behaviour and requirements, all the way up to integrative risk management.

For more information please visit www.unzer.com" "UNZER_APPLEPAY","Apple Pay" "UNZER_GOOGLEPAY","Google Pay" +"UNZER_TWINT","TWINT" "MODULE_VERSION_LABEL","Module version:" "ABOUT_UNZER_LABEL","About Unzer:" @@ -60,7 +61,7 @@ "PayPal","PayPal" "PayPal Account","PayPal Account" "Sofort","Sofort" -"Giropay","Giropay" +"(Deprecated) Giropay","(Veraltet) Giropay" "EPS","EPS" "Alipay","Alipay" "WeChat Pay","WeChat Pay" @@ -69,6 +70,7 @@ "Unzer Prepayment","Unzer Prepayment" "ApplePay","ApplePay" "GooglePay","GooglePay" +"TWINT","TWINT" "Customer Information","Customer Information" "mr","Mr." diff --git a/view/adminhtml/templates/system/config/googlepaychannelid.phtml b/view/adminhtml/templates/system/config/googlepaychannelid.phtml new file mode 100644 index 0000000..f9a296e --- /dev/null +++ b/view/adminhtml/templates/system/config/googlepaychannelid.phtml @@ -0,0 +1,40 @@ + +getChildHtml('button') ?> + +getChannelIdAction(); +$scriptString = <<