Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/b-6.3.x' into b-6.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Sosnowski committed Nov 14, 2023
2 parents ce116ad + aab44a1 commit b6510ab
Show file tree
Hide file tree
Showing 17 changed files with 264 additions and 22 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.3] - 2023-??-??
## [1.1.3] - 2023-11-14

- [0007526](https://bugs.oxid-esales.com/view.php?id=7526) Order would be saved only, if everything is correct. In all other cases redirect to checkout
- [0007509](https://bugs.oxid-esales.com/view.php?id=7509) Order would be saved only, if everything is correct. In all other cases redirect to checkout
- [0007524](https://bugs.oxid-esales.com/view.php?id=7524) catch Error if Unzer-API not working and redirect to Checkout
- [0007527](https://bugs.oxid-esales.com/view.php?id=7527) prevent clicking the buy-now-button several times
- [0007544](https://bugs.oxid-esales.com/view.php?id=7544) Add Error handling When unsupported Credit Card is used (e.g. Amex)
- [0007553](https://bugs.oxid-esales.com/view.php?id=7553) The billing and delivery address must be identical for invoice purchases (Paylater)
- [0007546](https://bugs.oxid-esales.com/view.php?id=7546): We provide an additional Order Number to Unzer for identify the Order in OXID-Backend and Unzer-Insights
- Prepayment - Adjust payment date when the payment has been completed
- change information for Unzer-Metadata
- Unzer Invoice (Paylater): Display bank details for invoice

## [1.1.2] - 2023-08-18

Expand Down
7 changes: 6 additions & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</ul>',
],
'thumbnail' => 'logo.svg',
'version' => '1.1.3-rc.3',
'version' => '1.1.3',
'author' => 'OXID eSales AG',
'url' => 'https://www.oxid-esales.com',
'email' => '[email protected]',
Expand Down Expand Up @@ -134,6 +134,11 @@
'block' => 'admin_module_config_var',
'file' => 'views/admin/blocks/admin_module_config_var.tpl'
],
[
'template' => 'order_list.tpl',
'block' => 'admin_order_list_item',
'file' => 'views/admin/blocks/admin_order_list_item.tpl'
],
//email
[
'template' => 'email/plain/order_cust.tpl',
Expand Down
51 changes: 51 additions & 0 deletions migration/data/Version20231107212500.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidSolutionCatalysts\Unzer\Migrations;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231107212500 extends AbstractMigration
{
/** @throws Exception */
public function __construct($version)
{
parent::__construct($version);

$this->platform->registerDoctrineTypeMapping('enum', 'string');
}

public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->updateOxOrderTable($schema);
}

public function down(Schema $schema): void
{
}

protected function updateOxOrderTable(Schema $schema): void
{
$oxorder = $schema->getTable('oxorder');
if (!$oxorder->hasColumn('OXUNZERORDERNR')) {
$oxorder->addColumn('OXUNZERORDERNR', Types::INTEGER, ['columnDefinition' => 'int(11)', 'default' => 0, 'comment' => 'Unzer Order Nr']);
}
}
}
6 changes: 6 additions & 0 deletions src/Controller/Admin/AdminOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ protected function addAuthorizationViewData(Authorization $authorization): void
$this->_aViewData["AuthShortId"] = $authorization->getShortId();
$this->_aViewData["AuthId"] = $authorization->getId();
$this->_aViewData["AuthAmount"] = $authorization->getAmount();
$holderData = [];
$holderData['bic'] = $authorization->getBic();
$holderData['iban'] = $authorization->getIban();
$holderData['descriptor'] = $authorization->getDescriptor();
$holderData['holder'] = $authorization->getHolder();
$this->_aViewData["holderData"] = $holderData;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Controller/DispatcherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public function updatePaymentTransStatus(): void
$unzerPayment = $unzer->fetchPayment($paymentId);

if ($order->load($data[0]['OXORDERID'])) {
/** @var string $oxTransStatus */
$oxTransStatus = $order->getFieldData('oxtransstatus');
if ($oxTransStatus === "OK" && $unzerPayment->getState() === PaymentState::STATE_COMPLETED) {
if ($unzerPayment->getState() === PaymentState::STATE_COMPLETED) {
$order->markUnzerOrderAsPaid();
}

Expand Down
8 changes: 5 additions & 3 deletions src/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ public function isSepaPayment(): ?bool
$payment = $this->getPayment();

return (
($payment instanceof Payment) ?
( $payment->getId() === CoreUnzerDefinitions::SEPA_UNZER_PAYMENT_ID
|| $payment->getId() === CoreUnzerDefinitions::SEPA_SECURED_UNZER_PAYMENT_ID) : false
$payment instanceof Payment &&
(
$payment->getId() === CoreUnzerDefinitions::SEPA_UNZER_PAYMENT_ID ||
$payment->getId() === CoreUnzerDefinitions::SEPA_SECURED_UNZER_PAYMENT_ID
)
);
}

Expand Down
7 changes: 7 additions & 0 deletions src/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OxidSolutionCatalysts\Unzer\Controller;

use OxidEsales\Eshop\Application\Model\Order;
use OxidSolutionCatalysts\Unzer\Core\UnzerDefinitions as CoreUnzerDefinitions;
use OxidSolutionCatalysts\Unzer\Service\UserRepository;
use OxidSolutionCatalysts\Unzer\Core\UnzerDefinitions;
use OxidSolutionCatalysts\Unzer\Service\UnzerDefinitions as UnzerDefinitionsService;
Expand Down Expand Up @@ -63,6 +64,8 @@ public function getPaymentList()
continue;
}

$invAndDelAddrIdent = !Registry::getSession()->getVariable('blshowshipaddress');

if (
(
$payment->isUnzerPaymentHealthy()
Expand All @@ -74,6 +77,10 @@ public function getPaymentList()
(
empty($unzerDefinitions[$key]['countries']) ||
in_array($userCountryIso, $unzerDefinitions[$key]['countries'], true)
) &&
(
$key !== CoreUnzerDefinitions::INVOICE_UNZER_PAYMENT_ID ||
($key === CoreUnzerDefinitions::INVOICE_UNZER_PAYMENT_ID && $invAndDelAddrIdent)
)
) {
$paymentList[$key] = $payment;
Expand Down
70 changes: 62 additions & 8 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@

namespace OxidSolutionCatalysts\Unzer\Model;

use Exception;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Field;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidSolutionCatalysts\Unzer\Service\Payment as PaymentService;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
use OxidSolutionCatalysts\Unzer\Service\Unzer;
use OxidSolutionCatalysts\Unzer\Traits\ServiceContainer;
use Psr\Container\ContainerInterface;
use UnzerSDK\Exceptions\UnzerApiException;

/**
* TODO: Decrease count of dependencies to 13
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Order extends Order_parent
{
use ServiceContainer;
Expand All @@ -27,7 +33,7 @@ class Order extends Order_parent
* @param Basket $oBasket
* @param User $oUser
* @return int|bool
* @throws \Exception
* @throws Exception
*
* @SuppressWarnings(PHPMD.ElseExpression)
*/
Expand All @@ -44,7 +50,9 @@ public function finalizeUnzerOrderAfterRedirect(
}

$this->setId($orderId);
$unzerPaymentStatus = $this->getServiceFromContainer(PaymentService::class)->getUnzerPaymentStatus();
$paymentService = $this->getServiceFromContainer(PaymentService::class);
$unzerService = $this->getServiceFromContainer(Unzer::class);
$unzerPaymentStatus = $paymentService->getUnzerPaymentStatus();

if ($unzerPaymentStatus !== "ERROR") {
// copies user info
Expand All @@ -65,6 +73,10 @@ public function finalizeUnzerOrderAfterRedirect(
$this->_setNumber();
}

// setUnzerOrderId
$this->setUnzerOrderNr($paymentService->getUnzerOrderId());
$unzerService->resetUnzerOrderId();

// deleting remark info only when order is finished
Registry::getSession()->deleteVariable('ordrem');

Expand Down Expand Up @@ -104,6 +116,46 @@ public function finalizeUnzerOrderAfterRedirect(
return $iRet;
}

public function getUnzerOrderNr(): int
{
$value = $this->getFieldData('oxunzerordernr');
return is_numeric($value) ? (int)$value : 0;
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function setUnzerOrderNr(int $unzerOrderId): int
{
/** @var ContainerInterface $container */
$container = ContainerFactory::getInstance()
->getContainer();

/** @var QueryBuilderFactoryInterface $queryBuilderFactory */
$queryBuilderFactory = $container->get(QueryBuilderFactoryInterface::class);

$queryBuilder = $queryBuilderFactory->create();

$query = $queryBuilder
->update('oxorder')
->set("oxunzerordernr", ":oxunzerordernr")
->where("oxid = :oxid");

$parameters = [
':oxunzerordernr' => $unzerOrderId,
':oxid' => $this->getId()
];

$query->setParameters($parameters)->execute();

// TODO fixme Access to an undefined property
// OxidSolutionCatalysts\Unzer\Model\Order::$oxorder__oxunzerordernr.
/** @phpstan-ignore-next-line */
$this->oxorder__oxunzerordernr = new Field($unzerOrderId);

return $unzerOrderId;
}

/**
* @return void
* @SuppressWarnings(PHPMD.StaticAccess)
Expand All @@ -117,6 +169,9 @@ public function markUnzerOrderAsPaid(): void
$this->setFieldData('oxpaid', $date);
$this->save();
}
// e.g. prepayments start with "NO_FINISHED", if they are marked as paid,
// we set the status to OK here
$this->_setOrderStatus('OK');
}

/**
Expand All @@ -138,8 +193,7 @@ public function initWriteTransactionToDB($unzerPayment = null): bool
/** @var string $oxpaymenttype */
$oxpaymenttype = $this->getFieldData('oxpaymenttype');
if (
$this->getFieldData('oxtransstatus') === "OK"
&& strpos($oxpaymenttype, "oscunzer") !== false
strpos($oxpaymenttype, "oscunzer") !== false
) {
$transactionService = $this->getServiceFromContainer(TransactionService::class);
return $transactionService->writeTransactionToDB(
Expand Down Expand Up @@ -196,7 +250,7 @@ public function delete($sOxId = null)
* @param int $dataType
* @return false|void
*/
public function setFieldData($fieldName, $value, $dataType = \OxidEsales\Eshop\Core\Field::T_TEXT)
public function setFieldData($fieldName, $value, $dataType = Field::T_TEXT)
{
return parent::_setFieldData($fieldName, $value, $dataType);
}
Expand Down
1 change: 1 addition & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
class Module
{
public const MODULE_ID = 'osc-unzer';
public const GITHUB_NAME = 'OXID-eSales/unzer-module';
}
6 changes: 5 additions & 1 deletion src/PaymentExtensions/UnzerPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OxidSolutionCatalysts\Unzer\PaymentExtensions;

use Exception;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Exception\StandardException;
Expand Down Expand Up @@ -43,14 +44,17 @@ abstract class UnzerPayment
/** @var array */
protected $allowedCurrencies = [];

/**
* @throws Exception
*/
public function __construct(
Unzer $unzerSDK,
UnzerService $unzerService
) {
$this->unzerSDK = $unzerSDK;
$this->unzerService = $unzerService;

$this->unzerOrderId = $this->unzerService->generateUnzerOrderId();
$this->unzerOrderId = (string)$this->unzerService->generateUnzerOrderId();

$this->unzerService->setIsAjaxPayment($this->ajaxResponse);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Service/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public function getModuleVersion(): string
return $this->moduleInfoBridge->get(Module::MODULE_ID)->getVersion();
}

/**
* @return string
*/
public function getGitHubName(): string
{
return Module::GITHUB_NAME;
}

/**
* @return bool
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ public function getUnzerPaymentStatus(): string
return $result;
}

/**
* @return int
* @throws UnzerApiException
*/
public function getUnzerOrderId(): int
{
$result = 0;
$sessionUnzerPayment = $this->getSessionUnzerPayment();
if ($sessionUnzerPayment) {
$transaction = $sessionUnzerPayment->getInitialTransaction();
if ($transaction) {
$result = (int)$transaction->getOrderId();
}
}
return $result;
}

/**
* @param string $customerType
* @param string $currency
Expand Down
Loading

0 comments on commit b6510ab

Please sign in to comment.