Skip to content

Commit e7dcfba

Browse files
authored
Merge pull request #66 from unzerdev/develop
Develop
2 parents 55ed681 + 17bdd71 commit e7dcfba

File tree

24 files changed

+476
-50
lines changed

24 files changed

+476
-50
lines changed

Block/System/Config/GooglePayChannelId.php

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
namespace Unzer\PAPI\Block\System\Config;
55

66
use Magento\Backend\Block\Template\Context;
7+
use Magento\Backend\Block\Widget\Button;
8+
79
use Magento\Config\Block\System\Config\Form\Field;
810
use Magento\Framework\Data\Form\Element\AbstractElement;
9-
use Unzer\PAPI\Model\Config;
10-
use UnzerSDK\Exceptions\UnzerApiException;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Framework\Serialize\SerializerInterface;
14+
use Unzer\PAPI\Controller\Adminhtml\Webhooks\AbstractAction;
1115

1216
/**
1317
* Adminhtml Webhook Configuration Buttons Block
@@ -16,70 +20,79 @@
1620
*/
1721
class GooglePayChannelId extends Field
1822
{
19-
/**
20-
* @var Config
21-
*/
22-
private Config $configHelper;
23+
/** @var string */
24+
protected $_template = 'Unzer_PAPI::system/config/googlepaychannelid.phtml';
2325

2426
/**
2527
* Constructor
2628
*
2729
* @param Context $context
28-
* @param Config $configHelper
30+
* @param SerializerInterface $serializer
2931
* @param array $data
3032
*/
3133
public function __construct(
3234
Context $context,
33-
Config $configHelper,
35+
SerializerInterface $serializer,
3436
array $data = []
3537
) {
3638
parent::__construct($context, $data);
37-
$this->configHelper = $configHelper;
39+
$this->serializer = $serializer;
3840
}
3941

4042
/**
4143
* @inheritDoc
4244
*
43-
* @throws UnzerApiException
45+
* @throws LocalizedException
4446
*/
4547
protected function _getElementHtml(AbstractElement $element): string
4648
{
47-
if ($element->getValue() === '' || $element->getValue() === null) {
48-
$element->setValue($this->fetchChannelId());
49-
}
49+
$button = $this->getGooglePayChannelIdButton();
5050

51-
return $element->getElementHtml();
51+
$block = $this->_layout->createBlock(self::class);
52+
$block->setTemplate('Unzer_PAPI::system/config/googlepaychannelid.phtml')
53+
->setChild('button', $button);
54+
return parent::_getElementHtml($element) . $block->toHtml();
5255
}
5356

5457
/**
55-
* Fetch Channel ID
58+
* Get Google Pay Channel ID Button
5659
*
57-
* @return string
58-
* @throws UnzerApiException
60+
* @return Button
61+
* @throws LocalizedException
5962
*/
60-
private function fetchChannelId(): string
63+
public function getGooglePayChannelIdButton(): Button
6164
{
62-
$keyPair = $this->configHelper->getUnzerClient()->getResourceService()->fetchKeypair(true);
63-
64-
foreach ($keyPair->getPaymentTypes() as $paymentType) {
65-
if (!property_exists($paymentType, 'type')) {
66-
continue;
67-
}
68-
if ($paymentType->type === 'googlepay') {
69-
if (!property_exists($paymentType, 'supports')) {
70-
return '';
71-
}
72-
if (!is_array($paymentType->supports) || !array_key_exists(0, $paymentType->supports)) {
73-
return '';
74-
}
75-
if (!property_exists($paymentType->supports[0], 'channel')) {
76-
return '';
77-
}
65+
$button = $this->getLayout()->createBlock(Button::class);
66+
$button->setData([
67+
'id' => 'unzer_googlepay_channelid',
68+
'label' => __('Fetch Gateway Merchant ID'),
69+
]);
70+
return $button;
71+
}
7872

79-
return $paymentType->supports[0]->channel;
80-
}
81-
}
73+
/**
74+
* Get Channel ID Action
75+
*
76+
* @return string
77+
* @throws NoSuchEntityException
78+
*/
79+
public function getChannelIdAction(): string
80+
{
81+
return $this->getUrl('unzer/googlepay/channelid', [
82+
AbstractAction::URL_PARAM_STORE => $this->getStoreIdentifier()
83+
]);
84+
}
8285

83-
return '';
86+
/**
87+
* Get Store Identifier
88+
*
89+
* @return int
90+
* @throws NoSuchEntityException
91+
*/
92+
protected function getStoreIdentifier(): int
93+
{
94+
/** @var int|string $storeIdentifier */
95+
$storeIdentifier = $this->getRequest()->getParam(AbstractAction::URL_PARAM_STORE, 0);
96+
return (int)$this->_storeManager->getStore($storeIdentifier)->getId();
8497
}
8598
}

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ All notable changes to this project will be documented in this file.
33

44
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).
55

6+
## [3.2.0](https://github.com/unzerdev/magento2/compare/3.1.0..3.2.0)
7+
### Added
8+
* TWINT payment method
9+
### Changed
10+
* automatic fetching of Google Pay Gateway Merchant ID to manual fetching by adding a button for fetching of the ID
11+
* Giropay to be deactivated in checkout and marked as deprecated
12+
### Removed
13+
* Discover and JCB from available Google Pay card list
14+
615
## [3.1.0](https://github.com/unzerdev/magento2/compare/3.0.0..3.1.0)
716
### Added
817
* Google Pay
918
### Changed
1019
* 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)
1120
* system.xml to include separate files for each payment method instead of keeping everything in one file
12-
* refactored Apple Pay "supported networks" to allow "supported networks" for Google Pay, too
21+
* refactored Apple Pay "supported networks" to allow "supported networks" for Google Pay, too
1322
### Fixed
1423
* Threat Metrix data was not correctly handled for some payment methods
1524

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\Papi\Controller\Adminhtml\Googlepay;
5+
6+
use Magento\Framework\App\Action\HttpGetActionInterface;
7+
use Magento\Framework\App\RequestInterface;
8+
use Magento\Framework\Controller\Result\Json;
9+
use Magento\Framework\Controller\Result\JsonFactory;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
use UnzerSDK\Exceptions\UnzerApiException;
12+
use Unzer\PAPI\Model\Config;
13+
14+
class ChannelId implements HttpGetActionInterface
15+
{
16+
/** @var Config */
17+
private Config $configHelper;
18+
19+
/** @var JsonFactory */
20+
private JsonFactory $jsonFactory;
21+
22+
/** @var RequestInterface */
23+
private RequestInterface $request;
24+
25+
/**
26+
* Index constructor.
27+
*
28+
* @param Config $configHelper
29+
* @param JsonFactory $jsonFactory
30+
* @param RequestInterface $request
31+
*/
32+
public function __construct(
33+
Config $configHelper,
34+
JsonFactory $jsonFactory,
35+
RequestInterface $request
36+
) {
37+
$this->configHelper = $configHelper;
38+
$this->jsonFactory = $jsonFactory;
39+
$this->request = $request;
40+
}
41+
42+
/**
43+
* Controller execution.
44+
*
45+
* @return Json
46+
* @throws UnzerApiException
47+
*/
48+
public function execute(): Json
49+
{
50+
$json = $this->jsonFactory->create();
51+
$data = [
52+
'channel_id' => $this->fetchChannelId(),
53+
];
54+
$json->setData($data);
55+
56+
return $json;
57+
}
58+
59+
/**
60+
* Fetch Channel ID
61+
*
62+
* @return string
63+
* @throws UnzerApiException
64+
*/
65+
private function fetchChannelId(): string
66+
{
67+
$storeId = (string) $this->request->getParam('store', 0);
68+
69+
$keyPair = $this->configHelper->getUnzerClient($storeId)->getResourceService()->fetchKeypair(true);
70+
71+
foreach ($keyPair->getPaymentTypes() as $paymentType) {
72+
if (!property_exists($paymentType, 'type')) {
73+
continue;
74+
}
75+
if ($paymentType->type === 'googlepay') {
76+
if (!property_exists($paymentType, 'supports')) {
77+
return '';
78+
}
79+
if (!is_array($paymentType->supports) || !array_key_exists(0, $paymentType->supports)) {
80+
return '';
81+
}
82+
if (!property_exists($paymentType->supports[0], 'channel')) {
83+
return '';
84+
}
85+
86+
return $paymentType->supports[0]->channel;
87+
}
88+
}
89+
90+
return '';
91+
}
92+
}

Model/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
5656
public const METHOD_PREPAYMENT = 'unzer_prepayment';
5757
public const METHOD_APPLEPAY = 'unzer_applepay';
5858
public const METHOD_GOOGLEPAY = 'unzer_googlepay';
59+
public const METHOD_TWINT = 'unzer_twint';
5960

6061
/**
6162
* @var DebugHandler

Model/Config/Provider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Provider implements ConfigProviderInterface
4545
Config::METHOD_PREPAYMENT,
4646
Config::METHOD_APPLEPAY,
4747
Config::METHOD_GOOGLEPAY,
48+
Config::METHOD_TWINT,
4849
];
4950

5051
/**

Model/Method/Giropay.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Giropay payment method
88
*
99
* @link https://docs.unzer.com/
10+
* @deprecated
11+
* @see https://docs.unzer.com/payment-methods/giropay/
1012
*/
1113
class Giropay extends Base
1214
{

Model/Method/Twint.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Model\Method;
5+
6+
/**
7+
* Twint payment method
8+
*
9+
* @link https://docs.unzer.com/
10+
*/
11+
class Twint extends Base
12+
{
13+
/**
14+
* @inheritDoc
15+
*/
16+
public function hasRedirect(): bool
17+
{
18+
return true;
19+
}
20+
}

Model/Source/Googlepay/SupportedNetworks.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class SupportedNetworks implements OptionSourceInterface
1616
* @var array
1717
*/
1818
protected static array $networks = [
19-
"DISCOVER",
20-
"JCB",
2119
"MASTERCARD",
2220
"VISA"
2321
];
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Model\Validator;
5+
6+
use Exception;
7+
use Magento\Payment\Gateway\Validator\ResultInterface;
8+
use Unzer\PAPI\Model\Config;
9+
use Magento\Payment\Gateway\Validator\AbstractValidator;
10+
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
11+
12+
/**
13+
* Validator for per payment method currency restrictions
14+
*
15+
* @link https://docs.unzer.com/
16+
*/
17+
class CurrencyRestrictionValidator extends AbstractValidator
18+
{
19+
/**
20+
* @var Config
21+
*/
22+
private Config $config;
23+
24+
/**
25+
* @param ResultInterfaceFactory $resultFactory
26+
* @param Config $config
27+
*/
28+
public function __construct(
29+
ResultInterfaceFactory $resultFactory,
30+
Config $config
31+
) {
32+
parent::__construct($resultFactory);
33+
34+
$this->config = $config;
35+
}
36+
37+
/**
38+
* Validate
39+
*
40+
* @param array $validationSubject
41+
* @return bool|ResultInterface
42+
* @throws Exception
43+
*/
44+
public function validate(array $validationSubject)
45+
{
46+
$isValid = true;
47+
48+
/** @var string|null $currencyString */
49+
$currencyString = $this->config->getValue('currency_restrictions', $validationSubject['storeId']);
50+
51+
if (!empty($currencyString)) {
52+
/** @var string[] $currencies */
53+
$currencies = preg_split('/\s*,\s*/', $currencyString);
54+
55+
if (!in_array($validationSubject['currency'], $currencies)) {
56+
$isValid = false;
57+
}
58+
}
59+
60+
return $this->createResult($isValid);
61+
}
62+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unzerdev/magento2",
33
"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).",
44
"type": "magento2-module",
5-
"version": "3.1.0",
5+
"version": "3.2.0",
66
"license": "Apache-2.0",
77
"require": {
88
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0",

etc/adminhtml/system.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<include path="Unzer_PAPI::system/prepayment.xml"/>
7272
<include path="Unzer_PAPI::system/applepay.xml"/>
7373
<include path="Unzer_PAPI::system/googlepay.xml"/>
74+
<include path="Unzer_PAPI::system/twint.xml"/>
7475
</group>
7576
</section>
7677
</system>

etc/adminhtml/system/googlepay.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<label>Gateway Merchant ID</label>
4242
<config_path>payment/unzer_googlepay/unzer_channel_id</config_path>
4343
<frontend_model>Unzer\PAPI\Block\System\Config\GooglePayChannelId</frontend_model>
44-
<comment><![CDATA[The Gateway Merchant ID will be fetched automatically on page load. If you have changed the Public/Private Keys, please save again. If the field stays empty, please contact the Unzer Support.]]></comment>
44+
<comment><![CDATA[Fetch the Gateway Merchant ID from Unzer API. If the field stays empty, please contact the Unzer Support.]]></comment>
4545
</field>
4646
<field id="merchant_id" translate="label" type="text" sortOrder="100" showInDefault="1"
4747
showInWebsite="1" showInStore="1">

0 commit comments

Comments
 (0)