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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ 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.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
* Incorrect Invoice B2B UI component
### Changed
* Unblock Apple Pay on non-Safari browsers
* Reorder the default payment method list on checkout
* Set the Wero booking method mode to Charge
* Improve Unzer customer initialization using unique customerId

## [4.0.1](https://github.com/unzerdev/magento2/compare/4.0.0..4.0.1)
### Changed
* Invoice B2B component on checkout page
Expand Down
8 changes: 4 additions & 4 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ public function createCustomerFromQuote(Quote $quote, string $email, bool $creat
$customer->setPhone($billingAddress->getTelephone());
$customer->setBirthDate($quote->getCustomer()->getDob());

$customerId = (string) $quote->getCustomerId();
$customerId = $quote->getCustomerId() . '_' . $email . '_' . $quote->getStore()->getId();

if(!$quote->getCustomerIsGuest()) {
if (!$quote->getCustomerIsGuest()) {
$customer->setCustomerId($customerId);
}

Expand Down Expand Up @@ -431,9 +431,9 @@ public function createCustomerFromOrder(
}
$customer->setEmail($email);

$customerId = (string) $order->getCustomerId();
$customerId = $order->getCustomerId() . '_' . $email . '_' . $order->getStore()->getId();

if(!$order->getCustomerIsGuest()) {
if (!$order->getCustomerIsGuest()) {
$customer->setCustomerId($customerId);
}

Expand Down
93 changes: 76 additions & 17 deletions Model/Config/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

namespace Unzer\PAPI\Model\Config;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Quote\Model\Quote;
use Magento\Vault\Model\VaultPaymentInterface;
use Unzer\PAPI\Model\Config;
use Unzer\PAPI\Model\Method\Base as MethodBase;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Payment\Helper\Data as PaymentHelper;
use UnzerSDK\Resources\Customer;

/**
* JavaScript configuration provider
Expand All @@ -22,26 +25,26 @@ class Provider implements ConfigProviderInterface
* @var array
*/
protected array $_methodCodes = [
Config::METHOD_CARDS,
Config::METHOD_DIRECT_DEBIT,
Config::METHOD_EPS,
Config::METHOD_IDEAL,
Config::METHOD_PAYLATER_INVOICE,
Config::METHOD_PAYLATER_INVOICE_B2B,
Config::METHOD_PAYLATER_INSTALLMENT,
Config::METHOD_PAYLATER_DIRECT_DEBIT,
Config::METHOD_PAYPAL,
Config::METHOD_ALIPAY,
Config::METHOD_WECHATPAY,
Config::METHOD_PRZELEWY24,
Config::METHOD_BANCONTACT,
Config::METHOD_PREPAYMENT,
Config::METHOD_OPEN_BANKING,
Config::METHOD_CARDS,
Config::METHOD_APPLEPAYV2,
Config::METHOD_GOOGLEPAY,
Config::METHOD_TWINT,
Config::METHOD_OPEN_BANKING,
Config::METHOD_KLARNA,
Config::METHOD_WERO,
Config::METHOD_KLARNA,
Config::METHOD_EPS,
Config::METHOD_IDEAL,
Config::METHOD_PRZELEWY24,
Config::METHOD_TWINT,
Config::METHOD_DIRECT_DEBIT,
Config::METHOD_PREPAYMENT,
Config::METHOD_BANCONTACT,
Config::METHOD_PAYPAL,
Config::METHOD_ALIPAY,
Config::METHOD_WECHATPAY,
];

/**
Expand All @@ -59,20 +62,29 @@ class Provider implements ConfigProviderInterface
*/
private ScopeConfigInterface $scopeConfig;

/**
* @var Session
*/
private Session $checkoutSession;


/**
* Provider constructor.
* @param Config $moduleConfig
* @param PaymentHelper $paymentHelper
* @param ScopeConfigInterface $scopeConfig
* @param Session $checkoutSession
*/
public function __construct(
Config $moduleConfig,
PaymentHelper $paymentHelper,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
Session $checkoutSession
) {
$this->_moduleConfig = $moduleConfig;
$this->_paymentHelper = $paymentHelper;
$this->scopeConfig = $scopeConfig;
$this->checkoutSession = $checkoutSession;
}

/**
Expand All @@ -83,6 +95,12 @@ public function __construct(
*/
public function getConfig(): array
{
/** @var Quote $quote */
$quote = $this->checkoutSession->getQuote();

/** @var Customer $baseCustomer */
$baseCustomer = $quote ? $this->fetchUnzerCustomer($quote) : null;

$methodConfigs = [
Config::METHOD_BASE => [
'publicKey' => $this->_moduleConfig->getPublicKey(),
Expand All @@ -93,17 +111,58 @@ public function getConfig(): array
foreach ($this->_methodCodes as $methodCode) {
/** @var MethodBase $model */
$model = $this->_paymentHelper->getMethodInstance($methodCode);
if ($model instanceof VaultPaymentInterface) {
if ($model instanceof VaultPaymentInterface || !$model->isAvailable()) {
continue;
}

if ($model->isAvailable()) {
$methodConfigs[$model->getCode()] = $model->getFrontendConfig();
$methodConfig = $model->getFrontendConfig();

if (!$model->hasMethodValidOverrideKeys()) {
if ($baseCustomer) {
$methodConfig['unzerCustomerId'] = $baseCustomer->getId();
}

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

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

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

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

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

/**
* @param Quote $quote
* @param MethodBase|null $method
*
* @return Customer|null
*/
private function fetchUnzerCustomer(Quote $quote, ?MethodBase $method = null): ?Customer
{
if ($quote->getCustomerIsGuest() || !$quote->getCustomerId()) {
return null;
}

try {
$client = $this->_moduleConfig->getUnzerClient(
$quote->getStore()->getCode(),
$method
);

$customerId = $quote->getCustomerId() . '_' . $quote->getCustomerEmail() . '_' . $quote->getStore()->getId();

return $client->fetchCustomerByExtCustomerId($customerId);
} catch (\Exception $e) {
return null;
}
}
}
2 changes: 1 addition & 1 deletion Model/Method/ApplepayV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getFrontendConfig(): array
return [
'supportedNetworks' => $supportedNetworks,
'merchantCapabilities' => ['supports3DS'],
'label' => $this->_scopeConfig->getValue('payment/unzer_applepayv2/display_name') //label
'label' => 'Unzer GmbH'
];
}
}
113 changes: 0 additions & 113 deletions Model/Method/Invoice.php

This file was deleted.

2 changes: 1 addition & 1 deletion Model/Method/PaylaterInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @link https://docs.unzer.com/
*/
class PaylaterInvoice extends Invoice implements OverrideApiCredentialInterface
class PaylaterInvoice extends Base implements OverrideApiCredentialInterface
{
/**
* @inheritDoc
Expand Down
2 changes: 1 addition & 1 deletion Model/Method/PaylaterInvoiceB2b.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @link https://docs.unzer.com/
*/
class PaylaterInvoiceB2b extends Invoice implements OverrideApiCredentialInterface
class PaylaterInvoiceB2b extends Base implements OverrideApiCredentialInterface
{
/**
* @inheritDoc
Expand Down
Loading