Skip to content

[Release 3.3.0 - 2024-11-29] #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ 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.3.0](https://github.com/unzerdev/magento2/compare/3.2.2..3.3.0)
### Added
* ApplePay V2

## [3.2.2](https://github.com/unzerdev/magento2/compare/3.2.1..3.2.2)
### Fixed
* bank name not needed anymore for eps payment method
Expand Down
1 change: 1 addition & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
public const METHOD_BANCONTACT = 'unzer_bancontact';
public const METHOD_PREPAYMENT = 'unzer_prepayment';
public const METHOD_APPLEPAY = 'unzer_applepay';
public const METHOD_APPLEPAYV2 = 'unzer_applepayv2';
public const METHOD_GOOGLEPAY = 'unzer_googlepay';
public const METHOD_TWINT = 'unzer_twint';

Expand Down
1 change: 1 addition & 0 deletions Model/Config/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Provider implements ConfigProviderInterface
Config::METHOD_BANCONTACT,
Config::METHOD_PREPAYMENT,
Config::METHOD_APPLEPAY,
Config::METHOD_APPLEPAYV2,
Config::METHOD_GOOGLEPAY,
Config::METHOD_TWINT,
];
Expand Down
27 changes: 27 additions & 0 deletions Model/Method/ApplepayV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

namespace Unzer\PAPI\Model\Method;

/**
* Apple Pay V2 payment method
*
* @link https://docs.unzer.com/
*/
class ApplepayV2 extends Base
{
/**
* @inheritDoc
*/
public function getFrontendConfig(): array
{
$supportedNetworks = (string) $this->_scopeConfig->getValue('payment/unzer/applepayv2/supported_networks');
$supportedNetworks = explode(',', $supportedNetworks);

return [
'supportedNetworks' => $supportedNetworks,
'merchantCapabilities' => ['supports3DS'],
'label' => $this->_scopeConfig->getValue('payment/unzer_applepayv2/display_name') //label
];
}
}
57 changes: 57 additions & 0 deletions Model/Source/ApplepayV2/SupportedNetworks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);

namespace Unzer\PAPI\Model\Source\ApplepayV2;

use Magento\Framework\Data\OptionSourceInterface;

/**
* @link https://docs.unzer.com/
*/
class SupportedNetworks implements OptionSourceInterface
{
/**
* Supported Networks
*
* @var array
*/
protected static array $networks = [
//'amex',
//'bancomat',
//'bancontact',
//'cartesBancaires',
//'chinaUnionPay',
//'dankort',
//'discover',
//'eftpos',
//'electron',
//'elo',
//'girocard',
//'interac',
//'jcb',
//'mada',
//'maestro',
'masterCard',
//'mir',
//'privateLabel',
'visa',
//'vPay'
];

/**
* Return Supported Networks
*
* @return array
*/
public function toOptionArray(): array
{
$options = [];
foreach (self::$networks as $network) {
$options[] = [
'value' => $network,
'label' => ucfirst($network),
];
}
return $options;
}
}
80 changes: 80 additions & 0 deletions Model/System/Config/Backend/ApplepayV2/Upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);

namespace Unzer\PAPI\Model\System\Config\Backend\ApplepayV2;

use Exception;
use Magento\Config\Model\Config\Backend\File;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;

/**
* @link https://docs.unzer.com/
*/
class Upload extends File
{
/**
* Retrieve upload directory path
*
* @param string $uploadDir
* @return string
* @throws FileSystemException
*/
protected function getUploadDirPath($uploadDir): string
{
$this->_mediaDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::PUB);

$path = $this->_mediaDirectory->getAbsolutePath($uploadDir);

if (!$this->_mediaDirectory->isDirectory($path)) {
$this->_mediaDirectory->create($path);
}

return $path;
}

/**
* Save uploaded file before saving config value
*
* @return $this
* @throws LocalizedException
*/
public function beforeSave(): Upload
{
$value = $this->getValue();
$file = $this->getFileData();

if (!empty($file)) {
$uploadDir = $this->getUploadDirPath('.well-known/');
try {
$uploader = $this->_uploaderFactory->create(['fileId' => $file]);
$uploader->setAllowRenameFiles(false);
$uploader->addValidateCallback('size', $this, 'validateMaxSize');
$uploader->setFilesDispersion(false);

$domainAssocFileName = 'apple-developer-merchantid-domain-association';

$result = $uploader->save($uploadDir, $domainAssocFileName);
} catch (Exception $e) {
throw new LocalizedException(__('%1', $e->getMessage()));
}
if ($result !== false) {
if ($this->_addWhetherScopeInfo()) {
$domainAssocFileName = $this->_prependScopeInfo($domainAssocFileName);
}
$this->setValue($domainAssocFileName);
}
} else {
if (is_array($value) && !empty($value['delete'])) {
$this->setValue('');
} elseif (is_array($value) && !empty($value['value'])) {
$this->setValue($value['value']);
} else {
$this->unsValue();
}
}

return $this;
}
}
1 change: 1 addition & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<include path="Unzer_PAPI::system/bancontact.xml"/>
<include path="Unzer_PAPI::system/prepayment.xml"/>
<include path="Unzer_PAPI::system/applepay.xml"/>
<include path="Unzer_PAPI::system/applepayv2.xml"/>
<include path="Unzer_PAPI::system/googlepay.xml"/>
<include path="Unzer_PAPI::system/twint.xml"/>
</group>
Expand Down
16 changes: 16 additions & 0 deletions etc/adminhtml/system/applepay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
<group id="applepay" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>UNZER_APPLEPAY</label>
<field id="applepay_info_text" type="note" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<comment>
<![CDATA[
<div style="background-color: #d4edda; padding: 15px; border-radius: 4px;">
<span style="content: `\e60e`;"></span>
<h3><strong>Existing merchants:</strong></h3>
<p>We have updated our integration with Apple Pay, but since you already have it set up, you don't need to do anything just now.</p>
<p>However, when your Apple Pay certificates are about to expire, you can change to the new integration.</p>
<p>You can of course change to the new integration now, if you want, and then you don't have to worry about expiring certificates, changing integration, etc. in the future.</p>
</br>
<h3><strong>Existing and new both:</strong></h3>
<p>Before you activate Apple Pay, please make sure you have read our <a href="https://docs.unzer.com/payment-methods/applepay/applepay-prerequisites/#prerequisites-for-accepting-apple-pay-transactions" target="_blank">checklist</a>.</p>
</div>
]]>
</comment>
</field>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Enabled</label>
Expand Down
48 changes: 48 additions & 0 deletions etc/adminhtml/system/applepayv2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="applepayv2" translate="label" type="text" sortOrder="70" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>UNZER_APPLEPAYV2</label>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/unzer_applepayv2/active</config_path>
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Title</label>
<config_path>payment/unzer_applepayv2/title</config_path>
</field>
<field id="order_payment_action" translate="label" type="select" sortOrder="25" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Booking Mode</label>
<config_path>payment/unzer_applepayv2/order_payment_action</config_path>
<source_model>Unzer\PAPI\Model\System\Config\Source\PaymentAction</source_model>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="27" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Minimum Order Total</label>
<config_path>payment/unzer_applepayv2/min_order_total</config_path>
</field>
<field id="max_order_total" translate="label" type="text" sortOrder="28" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Maximum Order Total</label>
<config_path>payment/unzer_applepayv2/max_order_total</config_path>
<comment>Insert 0 to disable limit.</comment>
</field>
<field id="supported_networks" translate="label" type="multiselect" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Supported Networks</label>
<source_model>Unzer\PAPI\Model\Source\ApplepayV2\SupportedNetworks</source_model>
</field>
<field id="apple_merchantid_association_upload" translate="label" type="Magento\Config\Block\System\Config\Form\Field\File" sortOrder="56" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Apple Merchant ID Domain Association</label>
<backend_model>Unzer\PAPI\Model\System\Config\Backend\ApplepayV2\Upload</backend_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Sort Order</label>
<config_path>payment/unzer_applepayv2/sort_order</config_path>
</field>
</group>
</include>
16 changes: 16 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,22 @@
<can_use_internal>0</can_use_internal>
<model>Unzer\PAPI\Model\Method\Applepay</model>
</unzer_applepay>
<unzer_applepayv2>
<active>0</active>
<payment_action>order</payment_action>
<order_payment_action>authorize_capture</order_payment_action>
<title><![CDATA[Apple Pay]]></title>
<allowspecific>0</allowspecific>
<min_order_total>0</min_order_total>
<max_order_total>0</max_order_total>
<can_authorize>1</can_authorize>
<can_capture>1</can_capture>
<can_order>1</can_order>
<can_void>1</can_void>
<can_use_checkout>1</can_use_checkout>
<can_use_internal>0</can_use_internal>
<model>Unzer\PAPI\Model\Method\ApplepayV2</model>
</unzer_applepayv2>
<unzer_googlepay>
<active>0</active>
<payment_action>order</payment_action>
Expand Down
52 changes: 51 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,6 @@
<argument name="commandPool" xsi:type="object">UnzerCaptureCommandPool</argument>
</arguments>
</type>

<!-- Define types for Apple Pay payment method -->
<virtualType name="UnzerApplepayConfig" type="Unzer\PAPI\Model\Config">
<arguments>
Expand Down Expand Up @@ -1382,6 +1381,57 @@
</arguments>
</type>

<!-- Define types for Apple Pay V2payment method-->
<virtualType name="UnzerApplepayV2Config" type="Unzer\PAPI\Model\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Unzer\PAPI\Model\Config::METHOD_APPLEPAYV2</argument>
</arguments>
</virtualType>

<virtualType name="UnzerApplepayV2ConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">UnzerApplepayV2Config</argument>
</arguments>
</virtualType>

<virtualType name="UnzerApplepayV2ValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">UnzerApplepayV2ConfigValueHandler</item>
<item name="can_cancel" xsi:type="string">Unzer\PAPI\Model\Config\CanCancelHandler</item>
<item name="can_refund" xsi:type="string">Unzer\PAPI\Model\Config\CanRefundHandler</item>
<item name="can_refund_partial_per_invoice" xsi:type="string">Unzer\PAPI\Model\Config\CanRefundHandler
</item>
<item name="can_void" xsi:type="string">Unzer\PAPI\Model\Config\CanVoidHandler</item>
</argument>
</arguments>
</virtualType>

<virtualType name="UnzerApplepayV2ValidatorCountry" type="Unzer\PAPI\Model\Validator\CountryRestrictionValidator">
<arguments>
<argument name="config" xsi:type="object">UnzerApplepayV2Config</argument>
</arguments>
</virtualType>

<virtualType name="UnzerApplepayV2ValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">UnzerApplepayV2ValidatorCountry</item>
</argument>
</arguments>
</virtualType>

<type name="Unzer\PAPI\Model\Method\ApplepayV2">
<arguments>
<argument name="code" xsi:type="const">Unzer\PAPI\Model\Config::METHOD_APPLEPAYV2</argument>
<argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
<argument name="infoBlockType" xsi:type="string">Magento\Payment\Block\Info</argument>
<argument name="valueHandlerPool" xsi:type="object">UnzerApplepayV2ValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">UnzerApplepayV2ValidatorPool</argument>
<argument name="commandPool" xsi:type="object">UnzerAuthorizeAndCaptureCommandPool</argument>
</arguments>
</type>

<!-- Define types for Google Pay payment method-->
<virtualType name="UnzerGooglepayConfig" type="Unzer\PAPI\Model\Config">
<arguments>
Expand Down
3 changes: 3 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<event name="payment_method_assign_data_unzer_applepay">
<observer name="unzer_applepay_data_assign" instance="Unzer\PAPI\Model\Method\Observer\BaseDataAssignObserver" />
</event>
<event name="payment_method_assign_data_unzer_applepayv2">
<observer name="unzer_applepayv2_data_assign" instance="Unzer\PAPI\Model\Method\Observer\BaseDataAssignObserver" />
</event>
<event name="payment_method_assign_data_unzer_googlepay">
<observer name="unzer_googlepay_data_assign" instance="Unzer\PAPI\Model\Method\Observer\BaseDataAssignObserver" />
</event>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Unzer_PAPI" setup_version="3.2.2">
<module name="Unzer_PAPI" setup_version="3.2.3">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Config" />
Expand Down
Loading