Skip to content
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ 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).

## [4.0.3](https://github.com/unzerdev/magento2/compare/4.0.2..4.0.3)
### Fixed
* Initialization of the Invoice B2B component on the checkout page
* Apple Pay v1 backward compatibility
* Replace 'array_last()' with 'array_key_last()' in TransactionSynchronizer class
### Changed
* Add payment reference to payment, capture, and refund requests
* Remove the country restriction for Direct Bank Transfer

## [4.0.2](https://github.com/unzerdev/magento2/compare/4.0.1..4.0.2)
### Fixed
* Storing PayPal and SEPA Direct Debit on Magento 2.4.8
Expand Down
2 changes: 2 additions & 0 deletions Model/Command/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ protected function processSaveToVault(
*/
protected function createAuthorization(OrderInterface $order, float $amount): Authorization
{
/** @var Authorization $authorization */
$authorization = $this->authorizationFactory->create([
'amount' => $amount,
'currency' => $order->getBaseCurrencyCode(),
'returnUrl' => $this->_getCallbackUrl()
]);
$authorization->setOrderId($order->getIncrementId());
$authorization->setPaymentReference($order->getIncrementId());

return $authorization;
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Command/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function execute(array $commandSubject): void
return;
}

$cancellations = $client->cancelPayment($hpPayment, $amount, static::REASON);
$cancellations = $client->cancelPayment($hpPayment, $amount, static::REASON, $order->getIncrementId());

if (count($cancellations) > 0) {
$lastCancellation = end($cancellations);
Expand Down
3 changes: 3 additions & 0 deletions Model/Command/CancelAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Unzer\PAPI\Model\Config;
use UnzerSDK\Constants\CancelReasonCodes;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\TransactionTypes\Cancellation;
use UnzerSDK\Resources\TransactionTypes\CancellationFactory;

/**
Expand Down Expand Up @@ -80,8 +81,10 @@ public function execute(array $commandSubject): void
return;
}

/** @var Cancellation $cancellation */
$cancellation = $this->cancellationFactory->create(['amount' => $amount]);
$cancellation->setReasonCode(self::REASON);
$cancellation->setPaymentReference($order->getIncrementId());

$cancellation = $client->cancelAuthorizedPayment($hpPayment, $cancellation);

Expand Down
26 changes: 17 additions & 9 deletions Model/Command/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use UnzerSDK\Constants\RecurrenceTypes;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\AbstractUnzerResource;
use UnzerSDK\Resources\TransactionTypes\Authorization;
use UnzerSDK\Resources\TransactionTypes\Charge;
use UnzerSDK\Resources\TransactionTypes\ChargeFactory;

Expand Down Expand Up @@ -134,17 +133,24 @@ public function execute(array $commandSubject): ?ResultInterface
*/
protected function _chargeExisting(Order $order, string $paymentId, float $amount, ?string $storeId = null): Charge
{
$payment = $this->_getClient($storeId, $order->getPayment()->getMethodInstance())
->fetchPayment($paymentId);
$unzerClient = $this->_getClient(
$storeId,
$order->getPayment()->getMethodInstance()
);

/** @var Authorization|null $authorization */
$authorization = $payment->getAuthorization();
$payment = $unzerClient->fetchPayment($paymentId);

if ($authorization !== null) {
return $authorization->charge($amount);
}
/** @var Charge $charge */
$charge = $this->chargeFactory->create([
'amount' => $amount,
'currency' => $order->getBaseCurrencyCode(),
'returnUrl' => $this->_getCallbackUrl()
]);

$charge->setOrderId($order->getIncrementId());
$charge->setPaymentReference($order->getIncrementId());

return $payment->charge($amount);
return $unzerClient->performChargeOnPayment($payment, $charge);
}

/**
Expand All @@ -164,12 +170,14 @@ protected function _chargeNew(
): Charge {
$storeId = (string)$order->getStoreId();

/** @var Charge $charge */
$charge = $this->chargeFactory->create([
'amount' => $amount,
'currency' => $order->getBaseCurrencyCode(),
'returnUrl' => $this->_getCallbackUrl()
]);
$charge->setOrderId($order->getIncrementId());
$charge->setPaymentReference($order->getIncrementId());

$unzerClient = $this->_getClient(
$storeId,
Expand Down
10 changes: 8 additions & 2 deletions Model/Command/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute(array $commandSubject): void
// because of the nature of Prepayment, we need to refund the whole payment,
// otherwise refund is not possible at all for prepayment.
if ($payment->getMethodInstance()->getCode() === self::METHOD_PREPAYMENT) {
$cancellations = $client->cancelPayment($hpPayment, $amount, static::REASON);
$cancellations = $client->cancelPayment($hpPayment, $amount, static::REASON, $order->getIncrementId());

if (count($cancellations) > 0) {
$lastCancellation = end($cancellations);
Expand All @@ -57,7 +57,13 @@ public function execute(array $commandSubject): void

$chargeId = $payment->getParentTransactionId();

$cancellation = $client->cancelChargeById($hpPayment, $chargeId, $amount, self::REASON);
$cancellation = $client->cancelChargeById(
$hpPayment,
$chargeId,
$amount,
self::REASON,
$order->getIncrementId()
);

$payment->setLastTransId($cancellation->getId());
}
Expand Down
3 changes: 3 additions & 0 deletions Model/Command/RefundCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Unzer\PAPI\Model\Config;
use UnzerSDK\Constants\CancelReasonCodes;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\TransactionTypes\Cancellation;
use UnzerSDK\Resources\TransactionTypes\CancellationFactory;

/**
Expand Down Expand Up @@ -82,8 +83,10 @@ public function execute(array $commandSubject): void
return;
}

/** @var Cancellation $cancellation */
$cancellation = $this->cancellationFactory->create(['amount' => $amount]);
$cancellation->setReasonCode(self::REASON);
$cancellation->setPaymentReference($order->getIncrementId());

$cancellation = $client->cancelChargedPayment($hpPayment, $cancellation);

Expand Down
9 changes: 6 additions & 3 deletions Model/Command/TransactionSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function __construct(
public function applyCaptureOnMagento(OrderInterface $order, UnzerPayment $unzer): void
{
$payment = $this->getOrderPayment($order);
$capture = array_last($unzer->getCharges());
$charges = $unzer->getCharges();
$capture = $charges[array_key_last($charges)] ?? null;

if (!$payment || !$capture) {
return;
Expand Down Expand Up @@ -85,7 +86,8 @@ public function applyCaptureOnMagento(OrderInterface $order, UnzerPayment $unzer
public function applyCancellationOnMagento(OrderInterface $order, UnzerPayment $unzer): void
{
$payment = $this->getOrderPayment($order);
$cancellation = array_last($unzer->getCancellations());
$cancellations = $unzer->getCancellations();
$cancellation = $cancellations[array_key_last($cancellations)] ?? null;

if (!$payment || !$cancellation) {
return;
Expand Down Expand Up @@ -152,7 +154,8 @@ public function applyCancellationOnMagento(OrderInterface $order, UnzerPayment $
public function applyChargebackOnMagento(OrderInterface $order, UnzerPayment $unzer): void
{
$payment = $this->getOrderPayment($order);
$chargeback = array_last($unzer->getChargebacks());
$chargebacks = $unzer->getChargebacks();
$chargeback = $chargebacks[array_key_last($chargebacks)] ?? null;

if (!$payment || !$chargeback) {
return;
Expand Down
1 change: 1 addition & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
public const METHOD_BANCONTACT = 'unzer_bancontact';
public const METHOD_PREPAYMENT = 'unzer_prepayment';
public const METHOD_APPLEPAYV2 = 'unzer_applepayv2';
public const METHOD_APPLEPAY = 'unzer_applepay';
public const METHOD_GOOGLEPAY = 'unzer_googlepay';
public const METHOD_TWINT = 'unzer_twint';
public const METHOD_OPEN_BANKING = 'unzer_open_banking';
Expand Down
41 changes: 26 additions & 15 deletions Model/Config/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,18 @@ public function getConfig(): array

$methodConfig = $model->getFrontendConfig();

if (!$model->hasMethodValidOverrideKeys()) {
if ($baseCustomer) {
$methodConfig['unzerCustomerId'] = $baseCustomer->getId();
}
$customer = $model->hasMethodValidOverrideKeys()
? $this->fetchUnzerCustomer($quote, $model)
: $baseCustomer;

$methodConfigs[$model->getCode()] = $methodConfig;
continue;
}

$overrideCustomer = $this->fetchUnzerCustomer($quote, $model);

if ($overrideCustomer) {
$methodConfig['unzerCustomerId'] = $overrideCustomer->getId();
if ($customer) {
$methodConfig = $this->applyCustomerConfig($methodConfig, $customer);
}

$methodConfigs[$model->getCode()] = $methodConfig;
}

return [
'payment' => array_filter($methodConfigs),
];
return ['payment' => array_filter($methodConfigs)];
}

/**
Expand Down Expand Up @@ -165,4 +156,24 @@ private function fetchUnzerCustomer(Quote $quote, ?MethodBase $method = null): ?
return null;
}
}

/**
* @param array $methodConfig
* @param Customer $customer
*
* @return array
*/
private function applyCustomerConfig(array $methodConfig, Customer $customer): array
{
$methodConfig['unzerCustomerId'] = $customer->getId();

if ($customer->getCompany()) {
$companyInfo = $customer->getCompanyInfo();
$methodConfig['companyType'] = $companyInfo->getCompanyType();
$methodConfig['function'] = $companyInfo->getFunction();
$methodConfig['commercialSector'] = $companyInfo->getCommercialSector();
}

return $methodConfig;
}
}
13 changes: 13 additions & 0 deletions Model/Method/ApplepayV1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace Unzer\PAPI\Model\Method;

/**
* Apple Pay V1 backward compatibility - orders placed with plugin <=3.2.2
*
* @link https://docs.unzer.com/
*/
class ApplepayV1 extends Base
{
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "4.0.2",
"version": "4.0.3",
"license": "Apache-2.0",
"require": {
"php": "~7.4.0|~8.1.0|~8.2.0|~8.3.0|~8.4.0",
Expand All @@ -22,7 +22,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
"phpunit/phpunit": "~6.2.0"
"phpunit/phpunit": "^9.6"
},
"support": {
"email": "support@unzer.com"
Expand Down
15 changes: 14 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<allowspecific>0</allowspecific>
<min_order_total>0</min_order_total>
<max_order_total>0</max_order_total>
<country_restrictions>DE</country_restrictions>
<currency_restrictions>EUR</currency_restrictions>
<can_authorize>0</can_authorize>
<can_capture>1</can_capture>
Expand Down Expand Up @@ -153,6 +152,20 @@
<can_use_internal>0</can_use_internal>
<model>Unzer\PAPI\Model\Method\ApplepayV2</model>
</unzer_applepayv2>
<unzer_applepay>
<active>0</active>
<title><![CDATA[Apple Pay v1]]></title>
<payment_action>order</payment_action>
<order_payment_action>authorize_capture</order_payment_action>
<allowspecific>0</allowspecific>
<can_authorize>1</can_authorize>
<can_capture>1</can_capture>
<can_order>1</can_order>
<can_void>1</can_void>
<can_use_checkout>0</can_use_checkout>
<can_use_internal>0</can_use_internal>
<model>Unzer\PAPI\Model\Method\ApplepayV1</model>
</unzer_applepay>
<unzer_googlepay>
<active>0</active>
<payment_action>order</payment_action>
Expand Down
32 changes: 32 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1426,4 +1426,36 @@
<argument name="commandPool" xsi:type="object">UnzerAuthorizeAndCaptureCommandPool</argument>
</arguments>
</type>

<!-- Apple Pay V1 backward compatibility - orders placed with plugin <=3.2.2 -->
<virtualType name="UnzerApplepayV1Config" type="Unzer\PAPI\Model\Config">
<arguments>
<argument name="methodCode" xsi:type="const">Unzer\PAPI\Model\Config::METHOD_APPLEPAY</argument>
</arguments>
</virtualType>
<virtualType name="UnzerApplepayV1ConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">UnzerApplepayV1Config</argument>
</arguments>
</virtualType>
<virtualType name="UnzerApplepayV1ValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">UnzerApplepayV1ConfigValueHandler</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="Unzer\PAPI\Model\Method\ApplepayV1">
<arguments>
<argument name="code" xsi:type="const">Unzer\PAPI\Model\Config::METHOD_APPLEPAY</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">UnzerApplepayV1ValueHandlerPool</argument>
<argument name="commandPool" xsi:type="object">UnzerAuthorizeAndCaptureCommandPool</argument>
</arguments>
</virtualType>
</config>
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="4.0.2">
<module name="Unzer_PAPI" setup_version="4.0.3">
<sequence>
<module name="Magento_Checkout"/>
<module name="Magento_Config" />
Expand Down
9 changes: 8 additions & 1 deletion view/frontend/web/js/view/payment/method-renderer/basev2.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,14 @@ define(
country: shipping.countryId
} : {},
...(billing?.company && billing.company.trim() !== ''
? {company: billing.company.trim()}
? {
company: billing.company.trim(),
companyInfo: {
companyType: methodConfig.companyType || null,
function: methodConfig.function || null,
commercialSector: methodConfig.commercialSector || null,
}
}
: {}),
customerSettings: {
type: billing?.company && billing.company.trim() !== '' ? 'B2B' : 'B2C'
Expand Down
Loading