Skip to content
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

Release/v1.4.1 #8

Closed
wants to merge 5 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-async-to-generator", "@babel/plugin-transform-runtime"]
}
109 changes: 96 additions & 13 deletions Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<?php
declare(strict_types = 1);

declare(strict_types=1);

namespace Plugin\s360_unzer_shop5;

use JTL\Checkout\Bestellung;
use JTL\Events\Dispatcher;
use JTL\Helpers\Request;
use JTL\Plugin\Bootstrapper;
use JTL\Plugin\BootstrapperInterface;
use JTL\Plugin\Payment\Method;
use JTL\Shop;
use JTL\Smarty\JTLSmarty;
use Plugin\s360_unzer_shop5\paymentmethod\HeidelpayFlexiPayDirect;
use Plugin\s360_unzer_shop5\paymentmethod\HeidelpayHirePurchaseDirectDebit;
use Plugin\s360_unzer_shop5\paymentmethod\HeidelpayInvoiceFactoring;
use Plugin\s360_unzer_shop5\Seeders\Shop4PluginMigrationSeeder;
use Plugin\s360_unzer_shop5\src\ApplePay\CertificationService;
use Plugin\s360_unzer_shop5\src\Controllers\Admin\AdminApplePayController;
use Plugin\s360_unzer_shop5\src\Controllers\Admin\AdminKeyPairsController;
use Plugin\s360_unzer_shop5\src\Controllers\Admin\AdminOrdersController;
use Plugin\s360_unzer_shop5\src\Controllers\Admin\AdminSettingsController;
use Plugin\s360_unzer_shop5\src\Controllers\ApplePayController;
use Plugin\s360_unzer_shop5\src\Controllers\FrontendOutputController;
use Plugin\s360_unzer_shop5\src\Controllers\PaymentController;
use Plugin\s360_unzer_shop5\src\Controllers\SyncController;
use Plugin\s360_unzer_shop5\src\Foundation\Seeder;
use Plugin\s360_unzer_shop5\src\Foundation\ServiceProvider;
use Plugin\s360_unzer_shop5\src\KeyPairs\KeyPairModel;
use Plugin\s360_unzer_shop5\src\Orders\OrderMappingModel;
use Plugin\s360_unzer_shop5\src\Payments\Interfaces\NotificationInterface;
use Plugin\s360_unzer_shop5\src\Utils\Config;
use Plugin\s360_unzer_shop5\src\Utils\JtlLinkHelper;
use Plugin\s360_unzer_shop5\src\Utils\Logger;
use Plugin\s360_unzer_shop5\src\Utils\SessionHelper;
use Throwable;

/**
Expand All @@ -50,15 +60,30 @@ public function boot(Dispatcher $dispatcher): void
* Hook Registration & Handling
*/
$dispatcher->listen('shop.hook.' . \HOOK_BESTELLABSCHLUSS_INC_BESTELLUNGINDB, function (array $args) {
/**
* Handle Pending Orders.
*
* Prevent the WaWi from collection an order that is currently PENDING.
* Therefore, we mark the order as already collected (not great but JTL does not have a pending state).
*/
try {
/** @var Bestellung $order */
$order = $args['oBestellung'];

/** @var SessionHelper $sessionHelper */
$sessionHelper = Shop::Container()->get(SessionHelper::class);

// update cBestellNummer because we might already have generated it but bestellungInDB() has generated
// a new one, resulting in a wrong order number in the confirmation mail for example!
$orderNumber = $sessionHelper->get(SessionHelper::KEY_ORDER_ID);
if (!empty($orderNumber) && $orderNumber != $order->cBestellNr) {
$order->cBestellNr = $orderNumber;
} elseif ($sessionHelper->get(SessionHelper::KEY_CHECKOUT_SESSION)) {
$sessionHelper->set(SessionHelper::KEY_ORDER_ID, $order->cBestellNr);
}

/**
* Handle Pending Orders.
*
* Prevent the WaWi from collection an order that is currently PENDING.
* Therefore, we mark the order as already collected (not great but JTL does not have a pending state).
*/
if (Shop::has('360HpOrderPending')) {
$args['oBestellung']->cAbgeholt = 'Y';
$order->cAbgeholt = 'Y';
}
} catch (Throwable $th) {
Logger::error(
Expand Down Expand Up @@ -114,6 +139,23 @@ public function boot(Dispatcher $dispatcher): void
}
});

$dispatcher->listen('shop.hook.' . \HOOK_IO_HANDLE_REQUEST, function (array $args) {
// Hook into ajax request handling for apple pay merchant validation
try {
$controller = new ApplePayController(
$this->getPlugin(),
Shop::Container()->get(CertificationService::class),
$args['io']
);
$controller->handle();
} catch (Throwable $th) {
Logger::error(
'Error ' . $th->getCode() . ':' . $th->getMessage() . ', Exception in Hook '
. \HOOK_IO_HANDLE_REQUEST
);
}
});

// Backend Hooks
if (!Shop::isFrontend()) {
$dispatcher->listen('backend.notification', function () {
Expand Down Expand Up @@ -152,8 +194,9 @@ public function installed()

// Deactivate Invoice Factoring Payment Method by setting nNutzbar to 0
foreach ($this->getPlugin()->getPaymentMethods()->getMethods() as $method) {
if ($method->getActive() && $method->getUsable() &&
$method->getClassName() === HeidelpayInvoiceFactoring::class
if (
($method->getActive() || $method->getUsable()) &&
in_array($method->getClassName(), $this->getDeprecatedPaymentMethods())
) {
$this->getDB()->update(
'tzahlungsart',
Expand All @@ -180,8 +223,9 @@ public function updated($oldVersion, $newVersion)
{
// Deactivate Invoice Factoring Payment Method by setting nNutzbar to 0
foreach ($this->getPlugin()->getPaymentMethods()->getMethods() as $method) {
if (($method->getActive() || $method->getUsable()) &&
$method->getClassName() === HeidelpayInvoiceFactoring::class
if (
($method->getActive() || $method->getUsable()) &&
in_array($method->getClassName(), $this->getDeprecatedPaymentMethods())
) {
$this->getDB()->update(
'tzahlungsart',
Expand Down Expand Up @@ -219,18 +263,48 @@ public function renderAdminMenuTab(string $tabName, int $menuID, JTLSmarty $smar
$controller->setModel($model);
$controller->handleAjax();
} catch (Throwable $th) {
return json_encode([
echo json_encode([
'status' => 'error',
'messages' => [$th->getMessage()]
]);
die;
}
}

$controller = new AdminOrdersController($this->getPlugin(), $smarty);
$controller->setModel($model);
return $controller->handle();
case JtlLinkHelper::ADMIN_TAB_APPLE_PAY:
/** @var Config $config */
$config = Shop::Container()->get(Config::class);
if (!$config->get(Config::PRIVATE_KEY)) {
return 'Missing API Key';
}
$controller = new AdminApplePayController($this->getPlugin(), $smarty);
$controller->setCertService(Shop::Container()->get(CertificationService::class));

return $controller->handle();
case JtlLinkHelper::ADMIN_TAB_SETTINGS:
$controller = new AdminSettingsController($this->getPlugin(), $smarty);
return $controller->handle();
case JtlLinkHelper::ADMIN_TAB_KEYPAIRS:
$model = new KeyPairModel($this->getDB());
$controller = new AdminKeyPairsController($this->getPlugin(), $smarty);
$controller->setModel($model);

// Handle Ajax Requests
if (Request::isAjaxRequest() && Request::getVar('controller') == 'KeyPairs') {
try {
$controller->handleAjax();
} catch (Throwable $th) {
echo json_encode([
'status' => 'error',
'messages' => [$th->getMessage()]
]);
die;
}
}

return $controller->handle();
default:
return parent::renderAdminMenuTab($tabName, $menuID, $smarty);
Expand All @@ -240,4 +314,13 @@ public function renderAdminMenuTab(string $tabName, int $menuID, JTLSmarty $smar
return $th->getMessage();
}
}

private function getDeprecatedPaymentMethods(): array
{
return [
HeidelpayInvoiceFactoring::class,
HeidelpayHirePurchaseDirectDebit::class,
HeidelpayFlexiPayDirect::class
];
}
}
113 changes: 110 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,116 @@ 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.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.4.1] (April 2024)
### Changed
- reduce Unzer UI Component fields if they are already filled by the shop
- Unzer Direct Debit only available for EUR

### Fixed
- Validation of the Unzer UI Components
- use correct currency factor for instalments

## [1.4.0] (April 2024)
### Added
- New Payment Method **Unzer Direct Debit**
- Missing Translations

### Fixed
- prefill birthday field if alreay set by shop
- fixed issue with unzer ui component validation
- fixed issue with session new being cleared correctly when changing shipping/billing address in the checkout

### Changed
- updated payment and system requirements in the documenation

## [1.3.2] (January 2024)
### Fixed:
- Fixed issue with API Call in Settings after fresh install

## [1.3.1] (January 2024)
### Added
- Added Key Pair Management
- Added new payment method **Unzer Instalment**
- Added support for PHP 8.2 und PHP 8.3
- Added improved error handling for api errors

## Changed
- updated Unzer SDK
- highlight deprecated payment methods


## [1.3.0] (August 2023)
### Added
- Added LICENSE and NOTICE

### Changed
- Changed Payment Method name from Unzer Invoice to Unzer Invoice (Paylater)

### Fixed
- Clear Plugin Session on the order status page in case that a user aborted its payment process

### Removed
- Removed deprecated Payment Method **Unzer Instalment**/**Unzer Ratenkauf**
- Removed deprecated Payment Method **Unzer Bank Transfer**/**Unzer Direktüberweisung**

## [1.2.1] (February 2023)
### Added
- Added compatability for **JTL 5.2 and PHP 8.1**
- Added debug logs for the shipping API call
- Added Reference Text for cancellations

## Changed
- Show Invoice ID in Order Detail only if either local invoice id or invoice id from the API response is available
- Hide Unzer Insight Portal Button as the correct link to the order cannot be determined reliably

### Fixed
- Locale Mapping for Unzer UI Component
- Fixed unzer applepay debugging when in sandbox mode
- Fixed issue with submit button staying disabled on invalid input on the additional checkout step
- Fixed rounding issue in total gross amount API field

## [1.2.0] (November 2022)
### Added
- Added Bancontact as payment method
- Added Unzer Rechnung (Buy Now, Pay Later) as payment method
- Added option to disable automatic setting of incoming payments

### Changed
- Unzer SDK version updated to 1.2.0.0

## [1.1.0] (July 2022)
### Added
- Added company info to customer object
- Added verification and notification if frontend URLs have changed due to JTL/plugin updates and how to correct them
- Added VAT amount to shopping cart object
- Added ApplePay payment method

### Changed
- Unzer SDK version updated to 1.1.4.2
- Remove default value for payment method selection, as the NOVA theme already has a back button in the additional payment step.

### Fixed
- Fixed an issue with instalments sending incorrect/temporary order numbers to Unzer
- Fixed an unhandled error when retrieving refunds in the backend
- Fixed problem with umlauts in intermediate payment step encoded with HTML entities instead of UTF-8
- Fixed problem with cancelling Invoice (Secured) orders before they are completed
- Fixed problem with wrong order number in order confirmation emails

## [1.0.2] (March 2022)
### Added
- add minimum customer info (name and email) to all payments

### Changed
- use short id as transaction id in payment history (WaWi)

### Fixed
- set default db engine and charset when creating database tables to avoid issues due to weird defaults
- add error handling to avoid issues in the frontend when API is not callable *(ie missing keys)*
- fix issue with -0.0 beeing interpreted as negative in the unzer api
- potential fix for mismatch of order ids between the unzer insight portal and the shop
- error in the placeholder of the public key setting in the backend


## [1.0.1] (November 2021)
### Added
- JTL Shop 5.1 Compatability
Expand All @@ -17,6 +127,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
## [1.0.0] (July 2021)
### Added
- Initial Release

[1.0.1]: https://github.com/unzerdev/jtl5/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/unzerdev/jtl5
Loading
Loading