Skip to content

Commit 55ed681

Browse files
authored
Merge pull request #64 from unzerdev/develop
Develop
2 parents 826d57e + 766962a commit 55ed681

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1755
-954
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Block\System\Config;
5+
6+
use Magento\Backend\Block\Template\Context;
7+
use Magento\Config\Block\System\Config\Form\Field;
8+
use Magento\Framework\Data\Form\Element\AbstractElement;
9+
use Unzer\PAPI\Model\Config;
10+
use UnzerSDK\Exceptions\UnzerApiException;
11+
12+
/**
13+
* Adminhtml Webhook Configuration Buttons Block
14+
*
15+
* @link https://docs.unzer.com/
16+
*/
17+
class GooglePayChannelId extends Field
18+
{
19+
/**
20+
* @var Config
21+
*/
22+
private Config $configHelper;
23+
24+
/**
25+
* Constructor
26+
*
27+
* @param Context $context
28+
* @param Config $configHelper
29+
* @param array $data
30+
*/
31+
public function __construct(
32+
Context $context,
33+
Config $configHelper,
34+
array $data = []
35+
) {
36+
parent::__construct($context, $data);
37+
$this->configHelper = $configHelper;
38+
}
39+
40+
/**
41+
* @inheritDoc
42+
*
43+
* @throws UnzerApiException
44+
*/
45+
protected function _getElementHtml(AbstractElement $element): string
46+
{
47+
if ($element->getValue() === '' || $element->getValue() === null) {
48+
$element->setValue($this->fetchChannelId());
49+
}
50+
51+
return $element->getElementHtml();
52+
}
53+
54+
/**
55+
* Fetch Channel ID
56+
*
57+
* @return string
58+
* @throws UnzerApiException
59+
*/
60+
private function fetchChannelId(): string
61+
{
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+
}
78+
79+
return $paymentType->supports[0]->channel;
80+
}
81+
}
82+
83+
return '';
84+
}
85+
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ 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.1.0](https://github.com/unzerdev/magento2/compare/3.0.0..3.1.0)
7+
### Added
8+
* Google Pay
9+
### Changed
10+
* 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)
11+
* 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
13+
### Fixed
14+
* Threat Metrix data was not correctly handled for some payment methods
15+
616
## [3.0.0](https://github.com/unzerdev/magento2/compare/2.5.0..3.0.0)
717
### Added
818
* Partial Charge for Credit Card, Paylater Invoice, Unzer Installment, Direct Debit and PayPal

Helper/Order.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,8 @@ public function createMetadataForOrder(OrderModel $order): Metadata
224224

225225
$metaData->setShopType('Magento 2')
226226
->setShopVersion($this->_productMetadata->getVersion())
227-
->addMetadata('customerId', (string)$order->getCustomerId())
228-
->addMetadata('customerGroupId', (string)$order->getCustomerGroupId())
229227
->addMetadata('pluginType', 'unzerdev/magento2')
230-
->addMetadata('pluginVersion', $this->_moduleList->getOne('Unzer_PAPI')['setup_version'])
231-
->addMetadata('storeId', (string)$order->getStoreId());
228+
->addMetadata('pluginVersion', $this->_moduleList->getOne('Unzer_PAPI')['setup_version']);
232229

233230
return $metaData;
234231
}

Model/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
5555
public const METHOD_BANCONTACT = 'unzer_bancontact';
5656
public const METHOD_PREPAYMENT = 'unzer_prepayment';
5757
public const METHOD_APPLEPAY = 'unzer_applepay';
58+
public const METHOD_GOOGLEPAY = 'unzer_googlepay';
5859

5960
/**
6061
* @var DebugHandler

Model/Config/Provider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Provider implements ConfigProviderInterface
4444
Config::METHOD_BANCONTACT,
4545
Config::METHOD_PREPAYMENT,
4646
Config::METHOD_APPLEPAY,
47+
Config::METHOD_GOOGLEPAY,
4748
];
4849

4950
/**

Model/Method/Googlepay.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Model\Method;
5+
6+
/**
7+
* Googlepay payment method
8+
*
9+
* @link https://docs.unzer.com/
10+
*/
11+
class Googlepay extends Base
12+
{
13+
private const CONFIG_UNZER_CHANNEL_ID = 'unzer_channel_id';
14+
private const CONFIG_MERCHANT_ID = 'merchant_id';
15+
private const CONFIG_MERCHANT_NAME = 'merchant_name';
16+
private const CONFIG_COUNTRY_CODE = 'country_code';
17+
private const CONFIG_ALLOWED_CARD_NETWORKS = 'allowed_card_networks';
18+
private const CONFIG_ALLOW_CREDIT_CARDS = 'allow_credit_cards';
19+
private const CONFIG_ALLOW_PREPAID_CARDS = 'allow_prepaid_cards';
20+
private const CONFIG_BUTTON_COLOR = 'button_color';
21+
private const CONFIG_BUTTON_SIZE_MODE = 'button_size_mode';
22+
private const CONFIG_BUTTON_BORDER_RADIUS = 'button_border_radius';
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
public function hasRedirect(): bool
28+
{
29+
return true;
30+
}
31+
32+
/**
33+
* Get Frontend Config
34+
*
35+
* @return array
36+
*/
37+
public function getFrontendConfig(): array
38+
{
39+
$parentConfig = parent::getFrontendConfig();
40+
41+
$parentConfig['unzer_channel_id'] = $this->getConfigData(self::CONFIG_UNZER_CHANNEL_ID);
42+
$parentConfig['merchant_id'] = $this->getConfigData(self::CONFIG_MERCHANT_ID);
43+
$parentConfig['merchant_name'] = $this->getConfigData(self::CONFIG_MERCHANT_NAME);
44+
$parentConfig['country_code'] = $this->getConfigData(self::CONFIG_COUNTRY_CODE);
45+
$parentConfig['allowed_card_networks'] = explode(',', $this->getConfigData(self::CONFIG_ALLOWED_CARD_NETWORKS));
46+
$parentConfig['allow_credit_cards'] = $this->getConfigData(self::CONFIG_ALLOW_CREDIT_CARDS);
47+
$parentConfig['allow_prepaid_cards'] = $this->getConfigData(self::CONFIG_ALLOW_PREPAID_CARDS);
48+
$parentConfig['button_color'] = $this->getConfigData(self::CONFIG_BUTTON_COLOR);
49+
$parentConfig['button_size_mode'] = $this->getConfigData(self::CONFIG_BUTTON_SIZE_MODE);
50+
$parentConfig['button_border_radius'] = $this->getConfigData(self::CONFIG_BUTTON_BORDER_RADIUS);
51+
52+
return $parentConfig;
53+
}
54+
}

Model/Source/SupportedNetworks.php renamed to Model/Source/Applepay/SupportedNetworks.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Unzer\PAPI\Model\Source;
4+
namespace Unzer\PAPI\Model\Source\Applepay;
55

6-
use Magento\Framework\Option\ArrayInterface;
6+
use Magento\Framework\Data\OptionSourceInterface;
77

88
/**
99
* @link https://docs.unzer.com/
1010
*/
11-
class SupportedNetworks implements ArrayInterface
11+
class SupportedNetworks implements OptionSourceInterface
1212
{
1313
/**
1414
* Supported Networks
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Model\Source\Googlepay;
5+
6+
use Magento\Framework\Data\OptionSourceInterface;
7+
8+
class ButtonColor implements OptionSourceInterface
9+
{
10+
/**
11+
* Google Pay Button Colors
12+
*
13+
* @var array
14+
*/
15+
protected static array $buttonColors = [
16+
"default",
17+
"black",
18+
"white",
19+
];
20+
21+
/**
22+
* Return Google Pay Button Colors
23+
*
24+
* @return array
25+
*/
26+
public function toOptionArray(): array
27+
{
28+
$options = [];
29+
foreach (self::$buttonColors as $color) {
30+
$options[] = [
31+
'value' => $color,
32+
'label' => $color,
33+
];
34+
}
35+
return $options;
36+
}
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Model\Source\Googlepay;
5+
6+
use Magento\Framework\Data\OptionSourceInterface;
7+
8+
class ButtonSizeMode implements OptionSourceInterface
9+
{
10+
/**
11+
* Google Pay Button Size Mode
12+
*
13+
* @var array
14+
*/
15+
protected static array $buttonSizeModes = [
16+
"static",
17+
"fill",
18+
];
19+
20+
/**
21+
* Return Google Pay Button Size Mode
22+
*
23+
* @return array
24+
*/
25+
public function toOptionArray(): array
26+
{
27+
$options = [];
28+
foreach (self::$buttonSizeModes as $mode) {
29+
$options[] = [
30+
'value' => $mode,
31+
'label' => $mode,
32+
];
33+
}
34+
return $options;
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Unzer\PAPI\Model\Source\Googlepay;
6+
7+
use Magento\Framework\Data\OptionSourceInterface;
8+
9+
class CountryCode implements OptionSourceInterface
10+
{
11+
/**
12+
* Supported Networks
13+
*
14+
* @var array
15+
*/
16+
protected static array $networks = [
17+
"DK" => "Denmark",
18+
"CH" => "Switzerland",
19+
];
20+
21+
/**
22+
* Return Supported Networks
23+
*
24+
* @return array
25+
*/
26+
public function toOptionArray(): array
27+
{
28+
$options = [];
29+
foreach (self::$networks as $code => $name) {
30+
$options[] = [
31+
'value' => $code,
32+
'label' => __($name),
33+
];
34+
}
35+
return $options;
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Model\Source\Googlepay;
5+
6+
use Magento\Framework\Data\OptionSourceInterface;
7+
8+
/**
9+
* @link https://docs.unzer.com/
10+
*/
11+
class SupportedNetworks implements OptionSourceInterface
12+
{
13+
/**
14+
* Supported Networks
15+
*
16+
* @var array
17+
*/
18+
protected static array $networks = [
19+
"DISCOVER",
20+
"JCB",
21+
"MASTERCARD",
22+
"VISA"
23+
];
24+
25+
/**
26+
* Return Supported Networks
27+
*
28+
* @return array
29+
*/
30+
public function toOptionArray(): array
31+
{
32+
$options = [];
33+
foreach (self::$networks as $network) {
34+
$options[] = [
35+
'value' => $network,
36+
'label' => $network,
37+
];
38+
}
39+
return $options;
40+
}
41+
}

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.0.0",
5+
"version": "3.1.0",
66
"license": "Apache-2.0",
77
"require": {
88
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0",

0 commit comments

Comments
 (0)