From f365560189b7ec834037e0396cfedae6e5812ece Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 11:53:10 +0100 Subject: [PATCH 01/68] [feature] (PLENTY-80) NGW-IVsec: Show b2c payment method only on b2c billing address. --- src/Methods/AbstractMethod.php | 40 ++++++++++---- src/Methods/InvoiceSecuredB2C.php | 1 + src/Methods/PaymentMethodContract.php | 5 ++ src/Providers/HeidelpayServiceProvider.php | 3 ++ src/Services/BasketService.php | 61 ++++++++++++++++++++- src/Services/BasketServiceContract.php | 63 ++++++++++++++++++++++ src/Services/PaymentService.php | 47 ++++------------ 7 files changed, 170 insertions(+), 50 deletions(-) create mode 100644 src/Services/BasketServiceContract.php diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index fff5696..2dac61f 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -4,7 +4,7 @@ use Heidelpay\Configs\MethodConfigContract; use Heidelpay\Helper\PaymentHelper; -use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; +use Heidelpay\Services\BasketServiceContract; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodService; use Plenty\Plugin\Application; @@ -34,36 +34,37 @@ abstract class AbstractMethod extends PaymentMethodService implements PaymentMet const NEEDS_CUSTOMER_INPUT = true; const NEEDS_BASKET = false; const RENDER_INVOICE_DATA = false; + const B2C_ONLY = false; /** * @var PaymentHelper $helper */ protected $helper; - /** - * @var BasketRepositoryContract $basketRepository - */ - protected $basketRepository; /** * @var MethodConfigContract */ private $config; + /** + * @var BasketServiceContract + */ + private $basketService; /** * AbstractMethod constructor. * * @param PaymentHelper $paymentHelper - * @param BasketRepositoryContract $basketRepository * @param MethodConfigContract $config + * @param BasketServiceContract $basketService */ public function __construct( PaymentHelper $paymentHelper, - BasketRepositoryContract $basketRepository, - MethodConfigContract $config + MethodConfigContract $config, + BasketServiceContract $basketService ) { $this->helper = $paymentHelper; - $this->basketRepository = $basketRepository; $this->config = $config; + $this->basketService = $basketService; } /** @@ -76,7 +77,7 @@ public function isActive(): bool return false; } - $basket = $this->basketRepository->load(); + $basket = $this->basketService->getBasket(); // check the configured minimum cart amount and return false if an amount is configured // (which means > 0.00) and the cart amount is below the configured value. @@ -88,7 +89,16 @@ public function isActive(): bool // check the configured maximum cart amount and return false if an amount is configured // (which means > 0.00) and the cart amount is above the configured value. $maxAmount = $this->config->getMaxAmount($this); - return !($maxAmount > 0.00 && $basket->basketAmount > $maxAmount); + if ($maxAmount > 0.00 && $basket->basketAmount > $maxAmount) { + return false; + } + + // enable the payment method only if it is enabled for the current transaction (B2C||B2B) + if ($this->isB2cOnly() && $this->basketService->isBasketB2B()) { + return false; + } + + return true; } /** @@ -274,4 +284,12 @@ public function renderInvoiceData(): bool { return static::RENDER_INVOICE_DATA; } + + /** + * {@inheritDoc} + */ + public function isB2cOnly(): bool + { + return static::B2C_ONLY; + } } diff --git a/src/Methods/InvoiceSecuredB2C.php b/src/Methods/InvoiceSecuredB2C.php index 05d96d9..92d79fd 100755 --- a/src/Methods/InvoiceSecuredB2C.php +++ b/src/Methods/InvoiceSecuredB2C.php @@ -28,4 +28,5 @@ class InvoiceSecuredB2C extends AbstractMethod const NEEDS_CUSTOMER_INPUT = false; const NEEDS_BASKET = true; const RENDER_INVOICE_DATA = true; + const B2C_ONLY = true; } diff --git a/src/Methods/PaymentMethodContract.php b/src/Methods/PaymentMethodContract.php index a6404c8..e8478c1 100755 --- a/src/Methods/PaymentMethodContract.php +++ b/src/Methods/PaymentMethodContract.php @@ -144,4 +144,9 @@ public function needsBasket(): bool; * @return bool */ public function renderInvoiceData(): bool; + + /** + * Returns true if the payment method is meant for B2C orders. + */ + public function isB2cOnly(): bool; } diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index c74fde8..c476eee 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -11,6 +11,8 @@ use Heidelpay\Models\Contracts\TransactionRepositoryContract; use Heidelpay\Models\Repositories\OrderTxnIdRelationRepository; use Heidelpay\Models\Repositories\TransactionRepository; +use Heidelpay\Services\BasketService; +use Heidelpay\Services\BasketServiceContract; use Heidelpay\Services\NotificationService; use Heidelpay\Services\NotificationServiceContract; use Heidelpay\Services\PaymentService; @@ -49,6 +51,7 @@ public function register() $app->bind(NotificationServiceContract::class, NotificationService::class); $app->bind(OrderTxnIdRelationRepositoryContract::class, OrderTxnIdRelationRepository::class); $app->bind(UrlServiceContract::class, UrlService::class); + $app->bind(BasketServiceContract::class, BasketService::class); } /** diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 88ee76d..4d093a0 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -3,7 +3,10 @@ namespace Heidelpay\Services; use Heidelpay\Configs\MainConfigContract; +use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; +use Plenty\Modules\Account\Address\Models\Address; use Plenty\Modules\Authorization\Services\AuthHelper; +use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Basket\Models\BasketItem; use Plenty\Modules\Item\Item\Contracts\ItemRepositoryContract; @@ -21,7 +24,7 @@ * * @package heidelpay\plentymarkets-gateway\services */ -class BasketService +class BasketService implements BasketServiceContract { /** * @var LibService @@ -39,15 +42,27 @@ class BasketService * @var ItemRepositoryContract */ private $itemRepo; + /** + * @var AddressRepositoryContract + */ + private $addressRepository; + /** + * @var BasketRepositoryContract + */ + private $basketRepo; /** * BasketService constructor. + * @param AddressRepositoryContract $addressRepository + * @param BasketRepositoryContract $basketRepo * @param LibService $libraryService * @param MainConfigContract $config * @param ItemRepositoryContract $itemRepo * @param AuthHelper $authHelper */ public function __construct( + AddressRepositoryContract $addressRepository, + BasketRepositoryContract $basketRepo, LibService $libraryService, MainConfigContract $config, ItemRepositoryContract $itemRepo, @@ -57,6 +72,8 @@ public function __construct( $this->config = $config; $this->authHelper = $authHelper; $this->itemRepo = $itemRepo; + $this->addressRepository = $addressRepository; + $this->basketRepo = $basketRepo; } /** @@ -96,4 +113,46 @@ function () use ($basketItem) { $response = $this->libService->submitBasket($params); return $response['basketId']; } + + /** + * Gathers address data (billing/invoice and shipping) and returns them as an array. + * + * @return Address[] + */ + public function getCustomerAddressData(): array + { + $basket = $this->getBasket(); + + $addresses = []; + $addresses['billing'] = $this->addressRepository->findAddressById($basket->customerInvoiceAddressId); + + // if the shipping address is -99 or null, it is matching the billing address. + if ($basket->customerShippingAddressId === null || $basket->customerShippingAddressId === -99) { + $addresses['shipping'] = $addresses['billing']; + return $addresses; + } + + $addresses['shipping'] = $this->addressRepository->findAddressById($basket->customerShippingAddressId); + return $addresses; + } + + /** + * Returns true if the billing address is B2B. + */ + public function isBasketB2B(): bool + { + $billingAddress = $this->getCustomerAddressData()['billing']; + + return $billingAddress->gender === null; + } + + /** + * Fetches current basket and returns it. + * + * @return Basket + */ + public function getBasket(): Basket + { + return $this->basketRepo->load(); + } } diff --git a/src/Services/BasketServiceContract.php b/src/Services/BasketServiceContract.php new file mode 100644 index 0000000..df3803e --- /dev/null +++ b/src/Services/BasketServiceContract.php @@ -0,0 +1,63 @@ + + * + * @package heidelpay/${Package} + */ + +namespace Heidelpay\Services; + + +use Plenty\Modules\Account\Address\Models\Address; +use Plenty\Modules\Basket\Models\Basket; + +/** + * Provides connection to heidelpay basketApi. + * + * @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. + * @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved. + * + * @link http://dev.heidelpay.com/ + * + * @author Simon Gabriel + * + * @package heidelpay\plentymarkets-gateway\services + */ +interface BasketServiceContract +{ + /** + * Submits the Basket to the Basket-API and returns its ID. + * + * @param Basket $basket + * @param array $authData + * + * @return string + */ + public function requestBasketId(Basket $basket, array $authData): string; + + /** + * Gathers address data (billing/invoice and shipping) and returns them as an array. + * + * @return Address[] + */ + public function getCustomerAddressData(): array; + + /** + * Returns true if the billing address is B2B. + */ + public function isBasketB2B(): bool; + + /** + * Fetches current basket and returns it. + * + * @return Basket + */ + public function getBasket(): Basket; +} \ No newline at end of file diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index eaa7190..9f80ccb 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -18,7 +18,6 @@ use Heidelpay\Models\OrderTxnIdRelation; use Heidelpay\Models\Transaction; use Heidelpay\Traits\Translator; -use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; use Plenty\Modules\Account\Address\Models\Address; use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; @@ -57,10 +56,6 @@ class PaymentService * @var array */ private $heidelpayRequest = []; - /** - * @var AddressRepositoryContract - */ - private $addressRepository; /** * @var CountryRepositoryContract */ @@ -117,11 +112,14 @@ class PaymentService * @var ContactRepositoryContract */ private $contactRepo; + /** + * @var BasketServiceContract + */ + private $basketService; /** * PaymentService constructor. * - * @param AddressRepositoryContract $addressRepository * @param CountryRepositoryContract $countryRepository * @param LibService $libraryService * @param PaymentRepositoryContract $paymentRepository @@ -134,11 +132,10 @@ class PaymentService * @param OrderTxnIdRelationRepositoryContract $orderTxnIdRepo * @param OrderRepositoryContract $orderRepo * @param UrlServiceContract $urlService - * @param BasketRepositoryContract $basketRepository + * @param BasketServiceContract $basketService * @param ContactRepositoryContract $contactRepo */ public function __construct( - AddressRepositoryContract $addressRepository, CountryRepositoryContract $countryRepository, LibService $libraryService, PaymentRepositoryContract $paymentRepository, @@ -151,10 +148,9 @@ public function __construct( OrderTxnIdRelationRepositoryContract $orderTxnIdRepo, OrderRepositoryContract $orderRepo, UrlServiceContract $urlService, - BasketRepositoryContract $basketRepository, + BasketServiceContract $basketService, ContactRepositoryContract $contactRepo ) { - $this->addressRepository = $addressRepository; $this->countryRepository = $countryRepository; $this->libService = $libraryService; $this->paymentRepository = $paymentRepository; @@ -167,8 +163,8 @@ public function __construct( $this->orderTxnIdRepo = $orderTxnIdRepo; $this->orderRepo = $orderRepo; $this->urlService = $urlService; - $this->basketRepository = $basketRepository; $this->contactRepo = $contactRepo; + $this->basketService = $basketService; } /** @@ -345,9 +341,6 @@ private function prepareRequest( { $basketArray = $basket->toArray(); - /** @var BasketService $basketService */ - $basketService = pluginApp(BasketService::class); - /** @var SecretService $secretService */ $secretService = pluginApp(SecretService::class); @@ -359,7 +352,7 @@ private function prepareRequest( $this->heidelpayRequest = array_merge($this->heidelpayRequest, $heidelpayAuth); // set customer personal information & address data - $addresses = $this->getCustomerAddressData($basket); + $addresses = $this->basketService->getCustomerAddressData(); $billingAddress = $addresses['billing']; $this->heidelpayRequest['IDENTIFICATION_SHOPPERID'] = $basketArray['customerId']; $this->heidelpayRequest['NAME_GIVEN'] = $billingAddress->firstName; @@ -410,7 +403,7 @@ private function prepareRequest( } if ($methodInstance->needsBasket()) { - $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); + $this->heidelpayRequest['BASKET_ID'] = $this->basketService->requestBasketId($basket, $heidelpayAuth); } // shop + module information @@ -500,28 +493,6 @@ public function handlePushNotification(array $post): array } // - /** - * Gathers address data (billing/invoice and shipping) and returns them as an array. - * - * @param Basket $basket - * - * @return Address[] - */ - private function getCustomerAddressData(Basket $basket): array - { - $addresses = []; - $addresses['billing'] = $this->addressRepository->findAddressById($basket->customerInvoiceAddressId); - - // if the shipping address is -99 or null, it is matching the billing address. - if ($basket->customerShippingAddressId === null || $basket->customerShippingAddressId === -99) { - $addresses['shipping'] = $addresses['billing']; - return $addresses; - } - - $addresses['shipping'] = $this->addressRepository->findAddressById($basket->customerShippingAddressId); - return $addresses; - } - /** * Returns street and house number as a single string. * From 4ab93659c8300c90b51249200c54b1df5eea7d45 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 12:46:00 +0100 Subject: [PATCH 02/68] [feature] (PLENTY-80) NGW-IVsec: Attach company name field to request if it is a B2B order. --- src/Services/PaymentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 9f80ccb..676ab28 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -366,7 +366,7 @@ private function prepareRequest( 'isoCode2' ); - if ($billingAddress->companyName !== null) { + if ($this->basketService->isBasketB2B()) { $this->heidelpayRequest['NAME_COMPANY'] = $billingAddress->companyName; } From 15f0f7af91323cdd99e596368b3414465be1b884 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 12:52:03 +0100 Subject: [PATCH 03/68] [feature] (PLENTY-80) NGW-IVsec: Fix basket error. --- src/Services/PaymentService.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 676ab28..55d4728 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -20,7 +20,6 @@ use Heidelpay\Traits\Translator; use Plenty\Modules\Account\Address\Models\Address; use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; -use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; use Plenty\Modules\Order\Contracts\OrderRepositoryContract; @@ -104,10 +103,6 @@ class PaymentService * @var UrlServiceContract */ private $urlService; - /** - * @var BasketRepositoryContract - */ - private $basketRepository; /** * @var ContactRepositoryContract */ @@ -286,15 +281,12 @@ public function getPaymentMethodContent( $value = $this->urlService->generateURL(Routes::HANDLE_FORM_URL); + $basket = $this->basketService->getBasket(); if ($methodInstance->hasToBeInitialized()) { try { - $result = $this->sendPaymentRequest( - $this->basketRepository->load(), - $paymentMethod, - $methodInstance->getTransactionType(), - $mopId - ); - $value = $this->handleSyncResponse($type, $result); + $transactionType = $methodInstance->getTransactionType(); + $result = $this->sendPaymentRequest($basket, $paymentMethod, $transactionType, $mopId); + $value = $this->handleSyncResponse($type, $result); } catch (\RuntimeException $e) { $this->notification->error($clientErrorMessage, __METHOD__, [$type, $e->getMessage()], true); $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; @@ -303,7 +295,6 @@ public function getPaymentMethodContent( } } - $basket = $this->basketRepository->load(); $customerId = $basket->customerId; $contact = $this->contactRepo->findContactById($customerId); From af1e23c978827bce5af814c2ace2db0a5d3d8426 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 13:26:44 +0100 Subject: [PATCH 04/68] [feature] (PLENTY-80) NGW-IVsec: Allow only DE and AT as billing country. --- src/Methods/AbstractMethod.php | 16 ++++++++++++++++ src/Methods/InvoiceSecuredB2C.php | 1 + src/Methods/PaymentMethodContract.php | 5 +++++ src/Services/BasketService.php | 17 +++++++++++++++++ src/Services/BasketServiceContract.php | 7 +++++++ src/Services/PaymentService.php | 13 +------------ 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 2dac61f..62f0741 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -35,6 +35,7 @@ abstract class AbstractMethod extends PaymentMethodService implements PaymentMet const NEEDS_BASKET = false; const RENDER_INVOICE_DATA = false; const B2C_ONLY = false; + const COUNTRY_RESTRICTION = []; /** * @var PaymentHelper $helper @@ -98,6 +99,13 @@ public function isActive(): bool return false; } + // enable the payment method only if it is allowed for the given billing country + $countryRestrictions = $this->getCountryRestrictions(); + if (!empty($countryRestrictions) && + !in_array($this->basketService->getBillingCountryCode(), $countryRestrictions, true)) { + return false; + } + return true; } @@ -292,4 +300,12 @@ public function isB2cOnly(): bool { return static::B2C_ONLY; } + + /** + * {@inheritDoc} + */ + public function getCountryRestrictions(): array + { + return static::COUNTRY_RESTRICTION; + } } diff --git a/src/Methods/InvoiceSecuredB2C.php b/src/Methods/InvoiceSecuredB2C.php index 92d79fd..729e825 100755 --- a/src/Methods/InvoiceSecuredB2C.php +++ b/src/Methods/InvoiceSecuredB2C.php @@ -29,4 +29,5 @@ class InvoiceSecuredB2C extends AbstractMethod const NEEDS_BASKET = true; const RENDER_INVOICE_DATA = true; const B2C_ONLY = true; + const COUNTRY_RESTRICTION = ['DE', 'AT']; } diff --git a/src/Methods/PaymentMethodContract.php b/src/Methods/PaymentMethodContract.php index e8478c1..36164cb 100755 --- a/src/Methods/PaymentMethodContract.php +++ b/src/Methods/PaymentMethodContract.php @@ -149,4 +149,9 @@ public function renderInvoiceData(): bool; * Returns true if the payment method is meant for B2C orders. */ public function isB2cOnly(): bool; + + /** + * Returns an array with the countries the method is restricted to. + */ + public function getCountryRestrictions(): array; } diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 4d093a0..34126da 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -11,6 +11,7 @@ use Plenty\Modules\Basket\Models\BasketItem; use Plenty\Modules\Item\Item\Contracts\ItemRepositoryContract; use Plenty\Modules\Item\Item\Models\Item; +use Plenty\Modules\Order\Shipping\Countries\Contracts\CountryRepositoryContract; /** * Provides connection to heidelpay basketApi. @@ -50,9 +51,14 @@ class BasketService implements BasketServiceContract * @var BasketRepositoryContract */ private $basketRepo; + /** + * @var CountryRepositoryContract + */ + private $countryRepository; /** * BasketService constructor. + * @param CountryRepositoryContract $countryRepository * @param AddressRepositoryContract $addressRepository * @param BasketRepositoryContract $basketRepo * @param LibService $libraryService @@ -61,6 +67,7 @@ class BasketService implements BasketServiceContract * @param AuthHelper $authHelper */ public function __construct( + CountryRepositoryContract $countryRepository, AddressRepositoryContract $addressRepository, BasketRepositoryContract $basketRepo, LibService $libraryService, @@ -74,6 +81,7 @@ public function __construct( $this->itemRepo = $itemRepo; $this->addressRepository = $addressRepository; $this->basketRepo = $basketRepo; + $this->countryRepository = $countryRepository; } /** @@ -155,4 +163,13 @@ public function getBasket(): Basket { return $this->basketRepo->load(); } + + /** + * {@inheritDoc} + */ + public function getBillingCountryCode(): string + { + $billingAddress = $this->getCustomerAddressData()['billing']; + return $this->countryRepository->findIsoCode($billingAddress->countryId, 'isoCode2'); + } } diff --git a/src/Services/BasketServiceContract.php b/src/Services/BasketServiceContract.php index df3803e..6e6f0c4 100644 --- a/src/Services/BasketServiceContract.php +++ b/src/Services/BasketServiceContract.php @@ -60,4 +60,11 @@ public function isBasketB2B(): bool; * @return Basket */ public function getBasket(): Basket; + + /** + * Returns the country code as isoCode2. + * + * @return string + */ + public function getBillingCountryCode(): string; } \ No newline at end of file diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 55d4728..eadb22f 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -25,7 +25,6 @@ use Plenty\Modules\Order\Contracts\OrderRepositoryContract; use Plenty\Modules\Order\Property\Models\OrderProperty; use Plenty\Modules\Order\Property\Models\OrderPropertyType; -use Plenty\Modules\Order\Shipping\Countries\Contracts\CountryRepositoryContract; use Plenty\Modules\Payment\Contracts\PaymentRepositoryContract; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; @@ -55,10 +54,6 @@ class PaymentService * @var array */ private $heidelpayRequest = []; - /** - * @var CountryRepositoryContract - */ - private $countryRepository; /** * @var PaymentRepositoryContract */ @@ -115,7 +110,6 @@ class PaymentService /** * PaymentService constructor. * - * @param CountryRepositoryContract $countryRepository * @param LibService $libraryService * @param PaymentRepositoryContract $paymentRepository * @param TransactionRepositoryContract $transactionRepo @@ -131,7 +125,6 @@ class PaymentService * @param ContactRepositoryContract $contactRepo */ public function __construct( - CountryRepositoryContract $countryRepository, LibService $libraryService, PaymentRepositoryContract $paymentRepository, TransactionRepositoryContract $transactionRepo, @@ -146,7 +139,6 @@ public function __construct( BasketServiceContract $basketService, ContactRepositoryContract $contactRepo ) { - $this->countryRepository = $countryRepository; $this->libService = $libraryService; $this->paymentRepository = $paymentRepository; $this->transactionRepository = $transactionRepo; @@ -352,10 +344,7 @@ private function prepareRequest( $this->heidelpayRequest['ADDRESS_STREET'] = $this->getFullStreetAndHouseNumber($billingAddress); $this->heidelpayRequest['ADDRESS_ZIP'] = $billingAddress->postalCode; $this->heidelpayRequest['ADDRESS_CITY'] = $billingAddress->town; - $this->heidelpayRequest['ADDRESS_COUNTRY'] = $this->countryRepository->findIsoCode( - $billingAddress->countryId, - 'isoCode2' - ); + $this->heidelpayRequest['ADDRESS_COUNTRY'] = $this->basketService->getBillingCountryCode(); if ($this->basketService->isBasketB2B()) { $this->heidelpayRequest['NAME_COMPANY'] = $billingAddress->companyName; From 8565d51bc813a786dd5458f8a937799497074b67 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 14:58:29 +0100 Subject: [PATCH 05/68] [feature] (PLENTY-80) NGW-IVsec: Extend user guides to show payment information in customer backend. --- meta/documents/user_guide_de.md | 6 ++-- meta/documents/user_guide_en.md | 6 ++-- resources/views/content/InvoiceDetails.twig | 34 +++++++++------------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/meta/documents/user_guide_de.md b/meta/documents/user_guide_de.md index b34c34f..98e1f66 100755 --- a/meta/documents/user_guide_de.md +++ b/meta/documents/user_guide_de.md @@ -110,8 +110,10 @@ Dieses Modul stellt einen Container zur Verfügung, der Zahlungsinformationen (z Um diese Informationen auf der Buchungsbestätigungs-Seite darzustellen folgen Sie bitte folgenden Schritten. 1. wechseln Sie im Backend auf den Menüpunkt *CMS > Container-Verknüpfungen* 2. wählen Sie im Drop-Down-Menü das Plug-in Set, für welches Sie die Änderung vornehmen möchten aus -3. klappen Sie das Menü *Invoice Details (Heidelpay)* auf und aktivieren hier den Ceres-Container ``Order confirmation: Additional payment information`` -4. klicken Sie den speichern Button +3. klappen Sie das Menü *Invoice Details (Heidelpay)* auf +4. aktivieren sie den Ceres-Container ``Order confirmation: Additional payment information`` +5. aktivieren sie den Ceres-Container ``My account: Additional payment information`` +6. klicken Sie den speichern Button ![Container-Verknüpfung](../images/preview_4.png) ## Beschreibung der Zahlungsabläufe diff --git a/meta/documents/user_guide_en.md b/meta/documents/user_guide_en.md index 5f39641..ea63558 100755 --- a/meta/documents/user_guide_en.md +++ b/meta/documents/user_guide_en.md @@ -110,8 +110,10 @@ This modul provides for a data container to render additional payment informatio To show the information on your order confirmation page please follow these steps: 1. switch to the menu item *CMS > Container Links* 2. choose the corresponding plug-in set from the drop down -3. open the menu *Invoice Details (Heidelpay)* and enable the ceres container ``Order confirmation: Additional payment information`` -4. click the save button +3. open the menu *Invoice Details (Heidelpay)* +4. enable the ceres container ``Order confirmation: Additional payment information`` +5. enable the ceres container ``My account: Additional payment information`` +6. click the save button ![Container links](../images/preview_4.png) ## Workflow description diff --git a/resources/views/content/InvoiceDetails.twig b/resources/views/content/InvoiceDetails.twig index 816ef6e..c4b5957 100755 --- a/resources/views/content/InvoiceDetails.twig +++ b/resources/views/content/InvoiceDetails.twig @@ -1,22 +1,18 @@
+{{ trans("Heidelpay::template.pleaseTransferTheTotalTo") }}
- {{ trans("Heidelpay::template.pleaseTransferTheTotalTo") }} - -
-
{{ trans("Heidelpay::template.accountIban") }}:
-
{{ accountIBAN }}
-
-
-
{{ trans("Heidelpay::template.accountBic") }}:
-
{{ accountBIC }}
-
-
-
{{ trans("Heidelpay::template.accountHolder") }}:
-
{{ accountHolder }}
-
-
-
{{ trans("Heidelpay::template.accountUsage") }}:
-
{{ accountUsage }}
-
-
+
{{ trans("Heidelpay::template.accountIban") }}:
+
{{ accountIBAN }}
+
+
+
{{ trans("Heidelpay::template.accountBic") }}:
+
{{ accountBIC }}
+
+
+
{{ trans("Heidelpay::template.accountHolder") }}:
+
{{ accountHolder }}
+
+
+
{{ trans("Heidelpay::template.accountUsage") }}:
+
{{ accountUsage }}
From 611f006fa6afbec7fa3bdb86e3b8f8317cc10519 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 15:24:07 +0100 Subject: [PATCH 06/68] [feature] (PLENTY-80) NGW-IVsec: Add comment with account data to order. --- src/Helper/PaymentHelper.php | 2 +- src/Services/PaymentService.php | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index 1182c06..e2bb624 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -476,7 +476,7 @@ public function setBookingTextError(Payment $paymentObject, string $bookingError * @return Order * @throws \RuntimeException */ - private function getOrder(int $orderId): Order + public function getOrder(int $orderId): Order { $order = null; diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index eadb22f..56ca8b9 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -21,6 +21,8 @@ use Plenty\Modules\Account\Address\Models\Address; use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Models\Basket; +use Plenty\Modules\Comment\Contracts\CommentRepositoryContract; +use Plenty\Modules\Comment\Models\Comment; use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; use Plenty\Modules\Order\Contracts\OrderRepositoryContract; use Plenty\Modules\Order\Property\Models\OrderProperty; @@ -106,6 +108,10 @@ class PaymentService * @var BasketServiceContract */ private $basketService; + /** + * @var CommentRepositoryContract + */ + private $commentRepo; /** * PaymentService constructor. @@ -123,6 +129,7 @@ class PaymentService * @param UrlServiceContract $urlService * @param BasketServiceContract $basketService * @param ContactRepositoryContract $contactRepo + * @param CommentRepositoryContract $commentRepo */ public function __construct( LibService $libraryService, @@ -137,7 +144,8 @@ public function __construct( OrderRepositoryContract $orderRepo, UrlServiceContract $urlService, BasketServiceContract $basketService, - ContactRepositoryContract $contactRepo + ContactRepositoryContract $contactRepo, + CommentRepositoryContract $commentRepo ) { $this->libService = $libraryService; $this->paymentRepository = $paymentRepository; @@ -152,12 +160,13 @@ public function __construct( $this->urlService = $urlService; $this->contactRepo = $contactRepo; $this->basketService = $basketService; + $this->commentRepo = $commentRepo; } /** * Executes payment tasks after an order has been created. * - * @param string $paymentMethod + * @param string $paymentMethod * @param ExecutePayment $event * * @return array @@ -198,6 +207,23 @@ public function executePayment(string $paymentMethod, ExecutePayment $event): ar return ['error', 'Heidelpay::error.errorDuringPaymentExecution']; } + $accountIban = $transactionDetails['CONNECTOR.ACCOUNT_IBAN']; + $accountBic = $transactionDetails['CONNECTOR.ACCOUNT_BIC']; + $accountHolder = $transactionDetails['CONNECTOR.ACCOUNT_HOLDER']; + $accountUsage = $transactionDetails['CONNECTOR.ACCOUNT_USAGE'] ?? $transaction->shortId; + + // add payment info to order + $data = []; + $data['referenceType'] = Comment::REFERENCE_TYPE_ORDER; + $data['referenceValue'] = $orderId; + $data['text'] = + 'IBAN: ' . $accountIban . '; ' . + 'BIC: ' . $accountBic . '; ' . + 'Account Holder: ' . $accountHolder . '; ' . + 'Usage: ' . $accountUsage; + $data['isVisibleForContact'] = true; + $this->commentRepo->createComment($data); + try { $this->handleTransaction($transaction); } catch (\RuntimeException $e) { From cb6c745fed89c78b921cbd52a4f7e8ec7d742040 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 15:42:51 +0100 Subject: [PATCH 07/68] [feature] (PLENTY-80) NGW-IVsec: debug fetch comments, set comment, fetch comments again. --- src/Helper/PaymentHelper.php | 2 +- src/Services/PaymentService.php | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index e2bb624..f8bd384 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -486,7 +486,7 @@ public function getOrder(int $orderId): Order try {// Get the order by the given order ID $order = $authHelper->processUnguarded( function () use ($orderId) { - return $this->orderRepo->findOrderById($orderId); + return $this->orderRepo->findOrderById($orderId, ['comments']); } ); } catch (\Exception $e) { diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 56ca8b9..17adf69 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -207,23 +207,29 @@ public function executePayment(string $paymentMethod, ExecutePayment $event): ar return ['error', 'Heidelpay::error.errorDuringPaymentExecution']; } + $accountIban = $transactionDetails['CONNECTOR.ACCOUNT_IBAN']; $accountBic = $transactionDetails['CONNECTOR.ACCOUNT_BIC']; $accountHolder = $transactionDetails['CONNECTOR.ACCOUNT_HOLDER']; $accountUsage = $transactionDetails['CONNECTOR.ACCOUNT_USAGE'] ?? $transaction->shortId; // add payment info to order - $data = []; - $data['referenceType'] = Comment::REFERENCE_TYPE_ORDER; - $data['referenceValue'] = $orderId; - $data['text'] = - 'IBAN: ' . $accountIban . '; ' . - 'BIC: ' . $accountBic . '; ' . - 'Account Holder: ' . $accountHolder . '; ' . - 'Usage: ' . $accountUsage; + $order = $this->paymentHelper->getOrder($orderId); + $this->notification->error('before', __METHOD__, ['order' => $order]); + + $commentText = 'IBAN: ' . $accountIban . '; ' . 'BIC: ' . $accountBic . '; ' . + 'Account Holder: ' . $accountHolder . '; ' . 'Usage: ' . $accountUsage; + $this->notification->error('comment text', __METHOD__, ['Comment' => $commentText]); + $data = []; + $data['referenceType'] = Comment::REFERENCE_TYPE_ORDER; + $data['referenceValue'] = $orderId; + $data['text'] = $commentText; $data['isVisibleForContact'] = true; $this->commentRepo->createComment($data); + $order = $this->paymentHelper->getOrder($orderId); + $this->notification->error('after', __METHOD__, ['order' => $order]); + try { $this->handleTransaction($transaction); } catch (\RuntimeException $e) { From bfbe13e40e8c0c4ef559e4393ea4ce5d4d05c7eb Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 14 Mar 2019 17:38:19 +0100 Subject: [PATCH 08/68] [feature] (PLENTY-80) NGW-IVsec: Debug: Handle PDF-Generation event. --- src/Providers/HeidelpayServiceProvider.php | 26 +++++++++++++++---- src/Services/PaymentService.php | 29 +--------------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index c476eee..7163983 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -18,6 +18,7 @@ use Heidelpay\Services\PaymentService; use Heidelpay\Services\UrlService; use Heidelpay\Services\UrlServiceContract; +use Plenty\Modules\Order\Pdf\Events\OrderPdfGenerationEvent; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodContainer; @@ -58,16 +59,18 @@ public function register() * Boot the heidelpay Service Provider * Register payment methods, add event listeners, ... * - * @param PaymentHelper $paymentHelper - * @param PaymentMethodContainer $methodContainer - * @param PaymentService $paymentService - * @param Dispatcher $eventDispatcher + * @param PaymentHelper $paymentHelper + * @param PaymentMethodContainer $methodContainer + * @param PaymentService $paymentService + * @param Dispatcher $eventDispatcher + * @param NotificationServiceContract $notificationService */ public function boot( PaymentHelper $paymentHelper, PaymentMethodContainer $methodContainer, PaymentService $paymentService, - Dispatcher $eventDispatcher + Dispatcher $eventDispatcher, + NotificationServiceContract $notificationService ) { // loop through all of the plugin's available payment methods /** @var string $paymentMethodClass */ @@ -117,5 +120,18 @@ function (ExecutePayment $event) use ( } } ); + + // add payment information to the invoice pdf + $eventDispatcher->listen( + OrderPdfGenerationEvent::class, + function (OrderPdfGenerationEvent $event) use ($notificationService) { + $notificationService->error('OrderPdfGenerationEvent', + __METHOD__, + [ + 'Order' => $event->getOrder(), + 'DocType' => $event->getDocType() + ]); + } + ); } } diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 17adf69..286943e 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -22,7 +22,6 @@ use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Comment\Contracts\CommentRepositoryContract; -use Plenty\Modules\Comment\Models\Comment; use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; use Plenty\Modules\Order\Contracts\OrderRepositoryContract; use Plenty\Modules\Order\Property\Models\OrderProperty; @@ -129,7 +128,6 @@ class PaymentService * @param UrlServiceContract $urlService * @param BasketServiceContract $basketService * @param ContactRepositoryContract $contactRepo - * @param CommentRepositoryContract $commentRepo */ public function __construct( LibService $libraryService, @@ -144,8 +142,7 @@ public function __construct( OrderRepositoryContract $orderRepo, UrlServiceContract $urlService, BasketServiceContract $basketService, - ContactRepositoryContract $contactRepo, - CommentRepositoryContract $commentRepo + ContactRepositoryContract $contactRepo ) { $this->libService = $libraryService; $this->paymentRepository = $paymentRepository; @@ -160,7 +157,6 @@ public function __construct( $this->urlService = $urlService; $this->contactRepo = $contactRepo; $this->basketService = $basketService; - $this->commentRepo = $commentRepo; } /** @@ -207,29 +203,6 @@ public function executePayment(string $paymentMethod, ExecutePayment $event): ar return ['error', 'Heidelpay::error.errorDuringPaymentExecution']; } - - $accountIban = $transactionDetails['CONNECTOR.ACCOUNT_IBAN']; - $accountBic = $transactionDetails['CONNECTOR.ACCOUNT_BIC']; - $accountHolder = $transactionDetails['CONNECTOR.ACCOUNT_HOLDER']; - $accountUsage = $transactionDetails['CONNECTOR.ACCOUNT_USAGE'] ?? $transaction->shortId; - - // add payment info to order - $order = $this->paymentHelper->getOrder($orderId); - $this->notification->error('before', __METHOD__, ['order' => $order]); - - $commentText = 'IBAN: ' . $accountIban . '; ' . 'BIC: ' . $accountBic . '; ' . - 'Account Holder: ' . $accountHolder . '; ' . 'Usage: ' . $accountUsage; - $this->notification->error('comment text', __METHOD__, ['Comment' => $commentText]); - $data = []; - $data['referenceType'] = Comment::REFERENCE_TYPE_ORDER; - $data['referenceValue'] = $orderId; - $data['text'] = $commentText; - $data['isVisibleForContact'] = true; - $this->commentRepo->createComment($data); - - $order = $this->paymentHelper->getOrder($orderId); - $this->notification->error('after', __METHOD__, ['order' => $order]); - try { $this->handleTransaction($transaction); } catch (\RuntimeException $e) { From 1e024f4407974aee9c45b53bbcbe1e077b28f72e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 08:12:14 +0100 Subject: [PATCH 09/68] [feature] (PLENTY-80) NGW-IVsec: Remove customer page payment rendering from user guide. --- meta/documents/user_guide_de.md | 3 +-- meta/documents/user_guide_en.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/meta/documents/user_guide_de.md b/meta/documents/user_guide_de.md index 98e1f66..00c1121 100755 --- a/meta/documents/user_guide_de.md +++ b/meta/documents/user_guide_de.md @@ -112,8 +112,7 @@ Um diese Informationen auf der Buchungsbestätigungs-Seite darzustellen folgen S 2. wählen Sie im Drop-Down-Menü das Plug-in Set, für welches Sie die Änderung vornehmen möchten aus 3. klappen Sie das Menü *Invoice Details (Heidelpay)* auf 4. aktivieren sie den Ceres-Container ``Order confirmation: Additional payment information`` -5. aktivieren sie den Ceres-Container ``My account: Additional payment information`` -6. klicken Sie den speichern Button +5. klicken Sie den speichern Button ![Container-Verknüpfung](../images/preview_4.png) ## Beschreibung der Zahlungsabläufe diff --git a/meta/documents/user_guide_en.md b/meta/documents/user_guide_en.md index ea63558..763f95b 100755 --- a/meta/documents/user_guide_en.md +++ b/meta/documents/user_guide_en.md @@ -112,8 +112,7 @@ To show the information on your order confirmation page please follow these step 2. choose the corresponding plug-in set from the drop down 3. open the menu *Invoice Details (Heidelpay)* 4. enable the ceres container ``Order confirmation: Additional payment information`` -5. enable the ceres container ``My account: Additional payment information`` -6. click the save button +5. click the save button ![Container links](../images/preview_4.png) ## Workflow description From 6bcd82e2ae3021981b8230e9d58a788d207a9f7e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 08:19:08 +0100 Subject: [PATCH 10/68] [feature] (PLENTY-80) NGW-IVsec: Debug: throw error on pdf generation. --- src/Providers/HeidelpayServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 7163983..25a9387 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -125,6 +125,8 @@ function (ExecutePayment $event) use ( $eventDispatcher->listen( OrderPdfGenerationEvent::class, function (OrderPdfGenerationEvent $event) use ($notificationService) { + throw new \RuntimeException('OrderPdfGenerationEvent'); + $notificationService->error('OrderPdfGenerationEvent', __METHOD__, [ From 8fc6ad72e3ad568dee1dafcf27d9083ba9b95e60 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 08:25:42 +0100 Subject: [PATCH 11/68] [feature] (PLENTY-80) NGW-IVsec: Debug: throw error on pdf generation. --- src/Providers/HeidelpayServiceProvider.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 25a9387..2aedfbb 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -19,6 +19,7 @@ use Heidelpay\Services\UrlService; use Heidelpay\Services\UrlServiceContract; use Plenty\Modules\Order\Pdf\Events\OrderPdfGenerationEvent; +use Plenty\Modules\Order\Pdf\Models\OrderPdfGeneration; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodContainer; @@ -123,8 +124,8 @@ function (ExecutePayment $event) use ( // add payment information to the invoice pdf $eventDispatcher->listen( - OrderPdfGenerationEvent::class, - function (OrderPdfGenerationEvent $event) use ($notificationService) { + OrderPdfGeneration::class, + function (OrderPdfGeneration $event) use ($notificationService) { throw new \RuntimeException('OrderPdfGenerationEvent'); $notificationService->error('OrderPdfGenerationEvent', From f25c307a5d0835f87c69bc17b809d82cfef51cd3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 08:27:59 +0100 Subject: [PATCH 12/68] [feature] (PLENTY-80) NGW-IVsec: Debug: throw error on pdf generation. --- src/Providers/HeidelpayServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 2aedfbb..1b301d3 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -124,8 +124,8 @@ function (ExecutePayment $event) use ( // add payment information to the invoice pdf $eventDispatcher->listen( - OrderPdfGeneration::class, - function (OrderPdfGeneration $event) use ($notificationService) { + OrderPdfGenerationEvent::class, + function (OrderPdfGenerationEvent $event) use ($notificationService) { throw new \RuntimeException('OrderPdfGenerationEvent'); $notificationService->error('OrderPdfGenerationEvent', From 3e29ce57f67b380bc717179d756d1c2a54eb6053 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 08:55:26 +0100 Subject: [PATCH 13/68] [feature] (PLENTY-80) NGW-IVsec: Debug: throw error on pdf generation. --- meta/documents/user_guide_de.md | 2 +- meta/documents/user_guide_en.md | 2 +- src/Providers/HeidelpayServiceProvider.php | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/meta/documents/user_guide_de.md b/meta/documents/user_guide_de.md index 00c1121..bc3a181 100755 --- a/meta/documents/user_guide_de.md +++ b/meta/documents/user_guide_de.md @@ -145,4 +145,4 @@ Hier wird daraufhin eine Zahlung angelegt und mit der Buchung verknüpft. ## Technische Besonderheiten * Leider ist es nicht möglich die Bestellung im Nachhinein zu erzeugen, d. h. wenn zum Beispiel die Rückleitung in den Shop nach dem Bezahlen schief geht. Auch wenn die Zahlung erfolgreich im heidelpay backend gespeichert worden ist.\ -Durch die Fehlermeldung im Buchungstext von Zahlungen, die nicht zugeordnet werden konnten, ist es möglich diese Fehlerfälle zu erkennen und zu behandeln. \ No newline at end of file +Durch die Fehlermeldung im Buchungstext von Zahlungen, die nicht zugeordnet werden konnten, ist es möglich diese Fehlerfälle zu erkennen und zu behandeln. diff --git a/meta/documents/user_guide_en.md b/meta/documents/user_guide_en.md index 763f95b..245b6f1 100755 --- a/meta/documents/user_guide_en.md +++ b/meta/documents/user_guide_en.md @@ -148,4 +148,4 @@ The shop module will then create a new payment and link it to the corresponding ## Known Issues * Unfortunately there is no way for us to create the order if the initial order creation fails, even if the payment has been successfully booked in our backend.\ -However you will be able to tell there has been an error when there are unassigned payments in your plenty backend showing an error in the booking text. \ No newline at end of file +However you will be able to tell there has been an error when there are unassigned payments in your plenty backend showing an error in the booking text. diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 1b301d3..add524c 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -19,7 +19,6 @@ use Heidelpay\Services\UrlService; use Heidelpay\Services\UrlServiceContract; use Plenty\Modules\Order\Pdf\Events\OrderPdfGenerationEvent; -use Plenty\Modules\Order\Pdf\Models\OrderPdfGeneration; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodContainer; @@ -126,14 +125,13 @@ function (ExecutePayment $event) use ( $eventDispatcher->listen( OrderPdfGenerationEvent::class, function (OrderPdfGenerationEvent $event) use ($notificationService) { - throw new \RuntimeException('OrderPdfGenerationEvent'); - $notificationService->error('OrderPdfGenerationEvent', __METHOD__, [ 'Order' => $event->getOrder(), 'DocType' => $event->getDocType() - ]); + ],true + ); } ); } From eba9088c8eb4483b66961cd03c0a1c9e3be74d4c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 09:33:20 +0100 Subject: [PATCH 14/68] [feature] (PLENTY-80) NGW-IVsec: Debug: Add dummy text to invoice pdf. --- src/Providers/HeidelpayServiceProvider.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index add524c..4def19a 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -18,6 +18,7 @@ use Heidelpay\Services\PaymentService; use Heidelpay\Services\UrlService; use Heidelpay\Services\UrlServiceContract; +use Plenty\Modules\Document\Models\Document; use Plenty\Modules\Order\Pdf\Events\OrderPdfGenerationEvent; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; @@ -124,14 +125,26 @@ function (ExecutePayment $event) use ( // add payment information to the invoice pdf $eventDispatcher->listen( OrderPdfGenerationEvent::class, - function (OrderPdfGenerationEvent $event) use ($notificationService) { + function (OrderPdfGenerationEvent $event) use ( + $notificationService, + $paymentHelper + ) { + $order = $event->getOrder(); + $docType = $event->getDocType(); + $notificationService->error('OrderPdfGenerationEvent', __METHOD__, [ - 'Order' => $event->getOrder(), - 'DocType' => $event->getDocType() - ],true + 'Order' => $order, + 'DocType' => $docType + ], true ); + + if ($docType !== Document::INVOICE) { + return; + } + + $event->addOrderPdfGeneration('Bitte überweisen Sie auf folgendes Konto: iugherogherogherogiherioh'); } ); } From 122876117db1e13759a67c68e21d391214926386 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 10:03:08 +0100 Subject: [PATCH 15/68] [feature] (PLENTY-80) NGW-IVsec: Debug: Add dummy text to invoice pdf. --- src/Providers/HeidelpayServiceProvider.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 4def19a..57955aa 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -20,6 +20,7 @@ use Heidelpay\Services\UrlServiceContract; use Plenty\Modules\Document\Models\Document; use Plenty\Modules\Order\Pdf\Events\OrderPdfGenerationEvent; +use Plenty\Modules\Order\Pdf\Models\OrderPdfGeneration; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodContainer; @@ -144,7 +145,12 @@ function (OrderPdfGenerationEvent $event) use ( return; } - $event->addOrderPdfGeneration('Bitte überweisen Sie auf folgendes Konto: iugherogherogherogiherioh'); + /** @var OrderPdfGeneration $orderPdfGeneration */ + $orderPdfGeneration = pluginApp(OrderPdfGeneration::class); + $orderPdfGeneration->language = 'de'; + $orderPdfGeneration->advice = 'Bitte überweisen Sie auf folgendes Konto: iugherogherogherogiherioh'; + + $event->addOrderPdfGeneration($orderPdfGeneration); } ); } From 778d56e81ccd8f56058c05de2044ee5d3d55f57f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 10:43:51 +0100 Subject: [PATCH 16/68] [refactor] (PLENTY-80) NGW-IVsec: Add order service. --- src/Helper/PaymentHelper.php | 50 +++----------- src/Providers/HeidelpayServiceProvider.php | 6 +- src/Services/OrderService.php | 76 ++++++++++++++++++++++ src/Services/OrderServiceContract.php | 37 +++++++++++ 4 files changed, 127 insertions(+), 42 deletions(-) create mode 100644 src/Services/OrderService.php create mode 100644 src/Services/OrderServiceContract.php diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index f8bd384..d611104 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -15,14 +15,13 @@ use Heidelpay\Methods\Sofort; use Heidelpay\Models\Transaction; use Heidelpay\Services\ArraySerializerService; -use Plenty\Modules\Authorization\Services\AuthHelper; +use Heidelpay\Services\OrderServiceContract; use Plenty\Modules\Basket\Events\Basket\AfterBasketChanged; use Plenty\Modules\Basket\Events\Basket\AfterBasketCreate; use Plenty\Modules\Basket\Events\BasketItem\AfterBasketItemAdd; use Plenty\Modules\Frontend\Events\FrontendLanguageChanged; use Plenty\Modules\Frontend\Events\FrontendShippingCountryChanged; use Plenty\Modules\Helper\Services\WebstoreHelper; -use Plenty\Modules\Order\Contracts\OrderRepositoryContract; use Plenty\Modules\Order\Models\Order; use Plenty\Modules\Payment\Contracts\PaymentOrderRelationRepositoryContract; use Plenty\Modules\Payment\Contracts\PaymentPropertyRepositoryContract; @@ -53,8 +52,6 @@ class PaymentHelper /** @var PaymentMethodRepositoryContract $paymentMethodRepo */ protected $paymentMethodRepo; - /** @var OrderRepositoryContract */ - private $orderRepo; /** @var PaymentOrderRelationRepositoryContract */ private $paymentOrderRelationRepo; /** @var MainConfigContract */ @@ -63,29 +60,33 @@ class PaymentHelper private $methodConfig; /** @var PaymentPropertyRepositoryContract */ private $paymentPropertyRepo; + /** + * @var OrderServiceContract + */ + private $orderService; /** * @param PaymentMethodRepositoryContract $paymentMethodRepo - * @param OrderRepositoryContract $orderRepository * @param PaymentOrderRelationRepositoryContract $paymentOrderRepo * @param MainConfigContract $mainConfig * @param MethodConfigContract $methodConfig * @param PaymentPropertyRepositoryContract $propertyRepo + * @param OrderServiceContract $orderService */ public function __construct( PaymentMethodRepositoryContract $paymentMethodRepo, - OrderRepositoryContract $orderRepository, PaymentOrderRelationRepositoryContract $paymentOrderRepo, MainConfigContract $mainConfig, MethodConfigContract $methodConfig, - PaymentPropertyRepositoryContract $propertyRepo + PaymentPropertyRepositoryContract $propertyRepo, + OrderServiceContract $orderService ) { $this->paymentMethodRepo = $paymentMethodRepo; - $this->orderRepo = $orderRepository; $this->paymentOrderRelationRepo = $paymentOrderRepo; $this->mainConfig = $mainConfig; $this->methodConfig = $methodConfig; $this->paymentPropertyRepo = $propertyRepo; + $this->orderService = $orderService; } /** @@ -287,7 +288,7 @@ public function mapHeidelpayTransactionType(string $paymentCode): string public function assignPlentyPaymentToPlentyOrder(Payment $payment, int $orderId): Order { /** @var Order $order */ - $order = $this->getOrder($orderId); + $order = $this->orderService->getOrder($orderId); $additionalInfo = ['Order' => $order, 'Payment' => $payment]; $this->getLogger(__METHOD__)->debug('Heidelpay::payment.debugAssignPaymentToOrder', $additionalInfo); @@ -469,37 +470,6 @@ public function setBookingTextError(Payment $paymentObject, string $bookingError return $this; } - /** - * Fetches the Order object to the given orderId. - * - * @param int $orderId - * @return Order - * @throws \RuntimeException - */ - public function getOrder(int $orderId): Order - { - $order = null; - - /** @var AuthHelper $authHelper */ - $authHelper = pluginApp(AuthHelper::class); - - try {// Get the order by the given order ID - $order = $authHelper->processUnguarded( - function () use ($orderId) { - return $this->orderRepo->findOrderById($orderId, ['comments']); - } - ); - } catch (\Exception $e) { - // no need to handle here - } - - // Check whether the order exists - if (!$order instanceof Order) { - throw new \RuntimeException('payment.warningOrderDoesNotExist'); - } - return $order; - } - /** * Returns the property with of the given type. * diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 57955aa..133bb3e 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -15,6 +15,8 @@ use Heidelpay\Services\BasketServiceContract; use Heidelpay\Services\NotificationService; use Heidelpay\Services\NotificationServiceContract; +use Heidelpay\Services\OrderService; +use Heidelpay\Services\OrderServiceContract; use Heidelpay\Services\PaymentService; use Heidelpay\Services\UrlService; use Heidelpay\Services\UrlServiceContract; @@ -55,6 +57,7 @@ public function register() $app->bind(OrderTxnIdRelationRepositoryContract::class, OrderTxnIdRelationRepository::class); $app->bind(UrlServiceContract::class, UrlService::class); $app->bind(BasketServiceContract::class, BasketService::class); + $app->bind(OrderServiceContract::class, OrderService::class); } /** @@ -127,8 +130,7 @@ function (ExecutePayment $event) use ( $eventDispatcher->listen( OrderPdfGenerationEvent::class, function (OrderPdfGenerationEvent $event) use ( - $notificationService, - $paymentHelper + $notificationService ) { $order = $event->getOrder(); $docType = $event->getDocType(); diff --git a/src/Services/OrderService.php b/src/Services/OrderService.php new file mode 100644 index 0000000..c771dfc --- /dev/null +++ b/src/Services/OrderService.php @@ -0,0 +1,76 @@ +orderRepo = $orderRepository; + } + + + /** + * Returns the language code of the given order or 'DE' as default. + * + * @param Order $order + * @return string + */ + public function getLanguage(Order $order): string + { + /** @var OrderProperty $property */ + foreach ($order->properties as $property) { + if ($property->typeId === OrderPropertyType::DOCUMENT_LANGUAGE) { + return $property->value; + } + } + + return 'DE'; + } + + /** + * Fetches the Order object to the given orderId. + * + * @param int $orderId + * @return Order + * @throws \RuntimeException + */ + public function getOrder(int $orderId): Order + { + $order = null; + + /** @var AuthHelper $authHelper */ + $authHelper = pluginApp(AuthHelper::class); + + try {// Get the order by the given order ID + $order = $authHelper->processUnguarded( + function () use ($orderId) { + return $this->orderRepo->findOrderById($orderId, ['comments']); + } + ); + } catch (\Exception $e) { + // no need to handle here + } + + // Check whether the order exists + if (!$order instanceof Order) { + throw new \RuntimeException('payment.warningOrderDoesNotExist'); + } + return $order; + } +} diff --git a/src/Services/OrderServiceContract.php b/src/Services/OrderServiceContract.php new file mode 100644 index 0000000..3d3dff5 --- /dev/null +++ b/src/Services/OrderServiceContract.php @@ -0,0 +1,37 @@ + + * + * @package heidelpay/${Package} + */ + +namespace Heidelpay\Services; + +use Plenty\Modules\Order\Models\Order; + +interface OrderServiceContract +{ + /** + * Returns the language code of the given order or 'DE' as default. + * + * @param Order $order + * @return string + */ + public function getLanguage(Order $order): string; + + /** + * Fetches the Order object to the given orderId. + * + * @param int $orderId + * @return Order + * @throws \RuntimeException + */ + public function getOrder(int $orderId): Order; +} From c1f0f88db248ea7a2cbbcc02476056c757069c1b Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 10:54:35 +0100 Subject: [PATCH 17/68] [feature] (PLENTY-80) NGW-IVsec: Add translation of invoice advice text. --- src/Providers/HeidelpayServiceProvider.php | 14 +++++++++----- src/Services/NotificationService.php | 7 +++---- src/Services/NotificationServiceContract.php | 10 ++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 133bb3e..6751ecc 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -69,13 +69,15 @@ public function register() * @param PaymentService $paymentService * @param Dispatcher $eventDispatcher * @param NotificationServiceContract $notificationService + * @param OrderServiceContract $orderService */ public function boot( PaymentHelper $paymentHelper, PaymentMethodContainer $methodContainer, PaymentService $paymentService, Dispatcher $eventDispatcher, - NotificationServiceContract $notificationService + NotificationServiceContract $notificationService, + OrderServiceContract $orderService ) { // loop through all of the plugin's available payment methods /** @var string $paymentMethodClass */ @@ -130,7 +132,7 @@ function (ExecutePayment $event) use ( $eventDispatcher->listen( OrderPdfGenerationEvent::class, function (OrderPdfGenerationEvent $event) use ( - $notificationService + $notificationService, $orderService ) { $order = $event->getOrder(); $docType = $event->getDocType(); @@ -148,9 +150,11 @@ function (OrderPdfGenerationEvent $event) use ( } /** @var OrderPdfGeneration $orderPdfGeneration */ - $orderPdfGeneration = pluginApp(OrderPdfGeneration::class); - $orderPdfGeneration->language = 'de'; - $orderPdfGeneration->advice = 'Bitte überweisen Sie auf folgendes Konto: iugherogherogherogiherioh'; + $orderPdfGeneration = pluginApp(OrderPdfGeneration::class); + $language = $orderService->getLanguage($order); + $orderPdfGeneration->language = $language; + $orderPdfGeneration->advice = + $notificationService->getTranslation('Heidelpay::template.pleaseTransferTheTotalTo', [], $language); $event->addOrderPdfGeneration($orderPdfGeneration); } diff --git a/src/Services/NotificationService.php b/src/Services/NotificationService.php index 0d9f29f..dabb8c5 100755 --- a/src/Services/NotificationService.php +++ b/src/Services/NotificationService.php @@ -148,12 +148,11 @@ protected function notify($level, $message, $method, array $logData, $justLog = } /** - * @param $message - * @return mixed + * {@inheritDoc} */ - protected function getTranslation($message) + public function getTranslation($message, $parameters = [], $locale = null) { - return $this->translator->trans($message); + return $this->translator->trans($message, $parameters, $locale); } /** diff --git a/src/Services/NotificationServiceContract.php b/src/Services/NotificationServiceContract.php index 80e2122..6f5ed9e 100755 --- a/src/Services/NotificationServiceContract.php +++ b/src/Services/NotificationServiceContract.php @@ -73,4 +73,14 @@ public function error($message, $method = 'no context given', array $logData = [ * @param array $logData */ public function critical($message, $method = 'no context given', array $logData = []); + + /** + * Translates the given message using the given locale. + * + * @param $message + * @param array $parameters + * @param string $locale + * @return mixed + */ + public function getTranslation($message, $parameters = [], $locale = null); } From 406b8a4170b0efb0ea74226736415fb9e3c3f5ca Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 12:09:27 +0100 Subject: [PATCH 18/68] [refactor] (PLENTY-80) NGW-IVsec: Add actual payment details to invoice pdf if they are present. --- src/Helper/PaymentHelper.php | 78 +++++++++++++++++++++- src/Providers/HeidelpayServiceProvider.php | 20 +++++- src/Providers/InvoiceDetailsProvider.php | 23 +------ src/Services/OrderService.php | 36 ++++++---- src/Services/OrderServiceContract.php | 9 +++ 5 files changed, 127 insertions(+), 39 deletions(-) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index d611104..82bff0e 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -13,6 +13,9 @@ use Heidelpay\Methods\InvoiceSecuredB2C; use Heidelpay\Methods\PaymentMethodContract; use Heidelpay\Methods\Sofort; +use Heidelpay\Models\Contracts\OrderTxnIdRelationRepositoryContract; +use Heidelpay\Models\Contracts\TransactionRepositoryContract; +use Heidelpay\Models\OrderTxnIdRelation; use Heidelpay\Models\Transaction; use Heidelpay\Services\ArraySerializerService; use Heidelpay\Services\OrderServiceContract; @@ -60,10 +63,14 @@ class PaymentHelper private $methodConfig; /** @var PaymentPropertyRepositoryContract */ private $paymentPropertyRepo; + /** @var OrderServiceContract */ + private $orderService; + /** @var OrderTxnIdRelationRepositoryContract */ + private $orderTxnIdRelationRepo; /** - * @var OrderServiceContract + * @var TransactionRepositoryContract */ - private $orderService; + private $transactionRepo; /** * @param PaymentMethodRepositoryContract $paymentMethodRepo @@ -72,6 +79,8 @@ class PaymentHelper * @param MethodConfigContract $methodConfig * @param PaymentPropertyRepositoryContract $propertyRepo * @param OrderServiceContract $orderService + * @param OrderTxnIdRelationRepositoryContract $orderTxnIdRelationRepo + * @param TransactionRepositoryContract $transactionRepo */ public function __construct( PaymentMethodRepositoryContract $paymentMethodRepo, @@ -79,7 +88,9 @@ public function __construct( MainConfigContract $mainConfig, MethodConfigContract $methodConfig, PaymentPropertyRepositoryContract $propertyRepo, - OrderServiceContract $orderService + OrderServiceContract $orderService, + OrderTxnIdRelationRepositoryContract $orderTxnIdRelationRepo, + TransactionRepositoryContract $transactionRepo ) { $this->paymentMethodRepo = $paymentMethodRepo; $this->paymentOrderRelationRepo = $paymentOrderRepo; @@ -87,6 +98,8 @@ public function __construct( $this->methodConfig = $methodConfig; $this->paymentPropertyRepo = $propertyRepo; $this->orderService = $orderService; + $this->orderTxnIdRelationRepo = $orderTxnIdRelationRepo; + $this->transactionRepo = $transactionRepo; } /** @@ -488,4 +501,63 @@ public function getPaymentProperty(Payment $paymentObject, int $typeId): Payment return null; } + + /** + * Returns an array holding the bank details for the given order. + * The array will be empty when no details are available. + * + * @param Order $order + * @return array + */ + public function getPaymentDetailsForOrder(Order $order): array + { + $relation = $this->orderTxnIdRelationRepo->getOrderTxnIdRelationByOrderId($order->id); + if ($relation instanceof OrderTxnIdRelation) { + return $this->getPaymentDetailsByTxnId($relation->txnId); + } + + return []; + } + + /** + * Returns an array holding the bank details for the given txnId. + * The array will be empty when no details are available. + * + * @param string $txnId + * @return array + */ + public function getPaymentDetailsByTxnId($txnId): array + { + $transactions = $this->transactionRepo->getTransactionsByTxnId($txnId); + $paymentDetails = []; + + foreach ($transactions as $transaction) { + /** @var Transaction $transaction */ + if ($transaction->transactionType === TransactionType::HP_AUTHORIZE) { + $details = $transaction->transactionDetails; + if (!isset( + $details['CONNECTOR.ACCOUNT_IBAN'], + $details['CONNECTOR.ACCOUNT_IBAN'], + $details['CONNECTOR.ACCOUNT_IBAN'], + $details['CONNECTOR.ACCOUNT_IBAN'] + )) { + break; + } + + $accountIBAN = $details['CONNECTOR.ACCOUNT_IBAN']; + $accountBIC = $details['CONNECTOR.ACCOUNT_BIC']; + $accountHolder = $details['CONNECTOR.ACCOUNT_HOLDER']; + $accountUsage = $details['CONNECTOR.ACCOUNT_USAGE'] ?? $transaction->shortId; + + $paymentDetails = [ + 'accountIBAN' => $accountIBAN, + 'accountBIC' => $accountBIC, + 'accountHolder' => $accountHolder, + 'accountUsage' => $accountUsage + ]; + } + } + + return $paymentDetails; + } } diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 6751ecc..1e66db3 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -132,7 +132,7 @@ function (ExecutePayment $event) use ( $eventDispatcher->listen( OrderPdfGenerationEvent::class, function (OrderPdfGenerationEvent $event) use ( - $notificationService, $orderService + $notificationService, $paymentHelper, $orderService ) { $order = $event->getOrder(); $docType = $event->getDocType(); @@ -153,8 +153,22 @@ function (OrderPdfGenerationEvent $event) use ( $orderPdfGeneration = pluginApp(OrderPdfGeneration::class); $language = $orderService->getLanguage($order); $orderPdfGeneration->language = $language; - $orderPdfGeneration->advice = - $notificationService->getTranslation('Heidelpay::template.pleaseTransferTheTotalTo', [], $language); + + $paymentDetails = $paymentHelper->getPaymentDetailsForOrder($order); + + if (!isset($paymentDetails['accountIBAN'], $paymentDetails['accountBIC'], $paymentDetails['accountHolder'], $paymentDetails['accountUsage'])) { + // do nothing if no payment details are defined, + return; + } + + $adviceParts = [ + $notificationService->getTranslation('Heidelpay::template.pleaseTransferTheTotalTo', [], $language), + $notificationService->getTranslation('Heidelpay::template.accountIban', [], $language) . ': ' . $paymentDetails['accountIBAN'], + $notificationService->getTranslation('Heidelpay::template.accountBic', [], $language) . ': ' . $paymentDetails['accountBIC'], + $notificationService->getTranslation('Heidelpay::template.accountHolder', [], $language) . ': ' . $paymentDetails['accountHolder'], + $notificationService->getTranslation('Heidelpay::template.accountUsage', [], $language) . ': ' . $paymentDetails['accountUsage'] + ]; + $orderPdfGeneration->advice = implode(PHP_EOL, $adviceParts); $event->addOrderPdfGeneration($orderPdfGeneration); } diff --git a/src/Providers/InvoiceDetailsProvider.php b/src/Providers/InvoiceDetailsProvider.php index 4b74bdd..a812d83 100755 --- a/src/Providers/InvoiceDetailsProvider.php +++ b/src/Providers/InvoiceDetailsProvider.php @@ -4,7 +4,6 @@ use Heidelpay\Constants\SessionKeys; use Heidelpay\Helper\PaymentHelper; use Heidelpay\Methods\PaymentMethodContract; -use Heidelpay\Models\Contracts\TransactionRepositoryContract; use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; use Plenty\Plugin\Templates\Twig; @@ -13,7 +12,6 @@ class InvoiceDetailsProvider public function call( Twig $twig, FrontendSessionStorageFactoryContract $sessionStorage, - TransactionRepositoryContract $transactionRepos, PaymentHelper $helper ): string { $mopId = $sessionStorage->getOrder()->methodOfPayment; @@ -25,22 +23,7 @@ public function call( } $txnId = $sessionStorage->getPlugin()->getValue(SessionKeys::SESSION_KEY_TXN_ID); - $transaction = $transactionRepos->getTransactionsByTxnId($txnId)[0]; - - $details = $transaction->transactionDetails; - $accountIBAN = $details['CONNECTOR.ACCOUNT_IBAN']; - $accountBIC = $details['CONNECTOR.ACCOUNT_BIC']; - $accountHolder = $details['CONNECTOR.ACCOUNT_HOLDER']; - $accountUsage = $details['CONNECTOR.ACCOUNT_USAGE'] ?? $transaction->shortId; - - return $twig->render( - 'Heidelpay::content/InvoiceDetails', - [ - 'accountIBAN' => $accountIBAN, - 'accountBIC' => $accountBIC, - 'accountHolder' => $accountHolder, - 'accountUsage' => $accountUsage - ] - ); + $paymentDetails = $helper->getPaymentDetailsByTxnId($txnId); + return $twig->render('Heidelpay::content/InvoiceDetails', $paymentDetails); } -} \ No newline at end of file +} diff --git a/src/Services/OrderService.php b/src/Services/OrderService.php index c771dfc..a4ab6a2 100644 --- a/src/Services/OrderService.php +++ b/src/Services/OrderService.php @@ -2,6 +2,7 @@ namespace Heidelpay\Services; +use Heidelpay\Models\Contracts\OrderTxnIdRelationRepositoryContract; use Plenty\Modules\Authorization\Services\AuthHelper; use Plenty\Modules\Order\Contracts\OrderRepositoryContract; use Plenty\Modules\Order\Models\Order; @@ -14,22 +15,26 @@ class OrderService implements OrderServiceContract * @var OrderRepositoryContract */ private $orderRepo; + /** + * @var OrderTxnIdRelationRepositoryContract + */ + private $orderTxnIdRelationRepo; /** * OrderHelper constructor. * @param OrderRepositoryContract $orderRepository + * @param OrderTxnIdRelationRepositoryContract $orderTxnIdRelationRepo */ - public function __construct(OrderRepositoryContract $orderRepository) - { - $this->orderRepo = $orderRepository; + public function __construct( + OrderRepositoryContract $orderRepository, + OrderTxnIdRelationRepositoryContract $orderTxnIdRelationRepo + ) { + $this->orderRepo = $orderRepository; + $this->orderTxnIdRelationRepo = $orderTxnIdRelationRepo; } - /** - * Returns the language code of the given order or 'DE' as default. - * - * @param Order $order - * @return string + * {@inheritDoc} */ public function getLanguage(Order $order): string { @@ -44,11 +49,7 @@ public function getLanguage(Order $order): string } /** - * Fetches the Order object to the given orderId. - * - * @param int $orderId - * @return Order - * @throws \RuntimeException + * {@inheritDoc} */ public function getOrder(int $orderId): Order { @@ -73,4 +74,13 @@ function () use ($orderId) { } return $order; } + + /** + * {@inheritDoc} + */ + public function getOrderByTxnId($txnId): Order + { + $orderId = $this->orderTxnIdRelationRepo->getOrderIdByTxnId($txnId); + return $this->getOrder($orderId); + } } diff --git a/src/Services/OrderServiceContract.php b/src/Services/OrderServiceContract.php index 3d3dff5..b4a2835 100644 --- a/src/Services/OrderServiceContract.php +++ b/src/Services/OrderServiceContract.php @@ -34,4 +34,13 @@ public function getLanguage(Order $order): string; * @throws \RuntimeException */ public function getOrder(int $orderId): Order; + + /** + * Returns the order object corresponding to the given txnId. + * + * @param $txnId + * @return Order + * @throws \RuntimeException + */ + public function getOrderByTxnId($txnId): Order; } From 816571f67e66126f926ef3bb2e3e13328847d047 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 12:21:07 +0100 Subject: [PATCH 19/68] [refactor] (PLENTY-80) NGW-IVsec: Add actual payment details to invoice pdf if they are present. --- src/Providers/HeidelpayServiceProvider.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 1e66db3..7e5509a 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -137,18 +137,14 @@ function (OrderPdfGenerationEvent $event) use ( $order = $event->getOrder(); $docType = $event->getDocType(); - $notificationService->error('OrderPdfGenerationEvent', - __METHOD__, - [ - 'Order' => $order, - 'DocType' => $docType - ], true - ); + $notificationService->error('OrderPdfGenerationEvent1', __METHOD__, ['Order' => $order, 'DocType' => $docType], true); if ($docType !== Document::INVOICE) { return; } + $notificationService->error('OrderPdfGenerationEvent2', __METHOD__, ['Order' => $order, 'DocType' => $docType], true); + /** @var OrderPdfGeneration $orderPdfGeneration */ $orderPdfGeneration = pluginApp(OrderPdfGeneration::class); $language = $orderService->getLanguage($order); @@ -156,10 +152,13 @@ function (OrderPdfGenerationEvent $event) use ( $paymentDetails = $paymentHelper->getPaymentDetailsForOrder($order); + $notificationService->error('OrderPdfGenerationEvent3', __METHOD__, ['$paymentDetails' => $paymentDetails], true); + if (!isset($paymentDetails['accountIBAN'], $paymentDetails['accountBIC'], $paymentDetails['accountHolder'], $paymentDetails['accountUsage'])) { // do nothing if no payment details are defined, return; } + $notificationService->error('OrderPdfGenerationEvent4', __METHOD__, ['$paymentDetails' => $paymentDetails], true); $adviceParts = [ $notificationService->getTranslation('Heidelpay::template.pleaseTransferTheTotalTo', [], $language), @@ -170,6 +169,9 @@ function (OrderPdfGenerationEvent $event) use ( ]; $orderPdfGeneration->advice = implode(PHP_EOL, $adviceParts); + $notificationService->error('OrderPdfGenerationEvent5', __METHOD__, ['$orderPdfGeneration' => $orderPdfGeneration], true); + + $event->addOrderPdfGeneration($orderPdfGeneration); } ); From cb5c508a77aaa3b3c3e3173da01a1d877896f104 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 12:27:06 +0100 Subject: [PATCH 20/68] [refactor] (PLENTY-80) NGW-IVsec: Add actual payment details to invoice pdf if they are present. --- src/Helper/PaymentHelper.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index 82bff0e..06d9eee 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -512,11 +512,12 @@ public function getPaymentProperty(Payment $paymentObject, int $typeId): Payment public function getPaymentDetailsForOrder(Order $order): array { $relation = $this->orderTxnIdRelationRepo->getOrderTxnIdRelationByOrderId($order->id); + if ($relation instanceof OrderTxnIdRelation) { return $this->getPaymentDetailsByTxnId($relation->txnId); } - return []; + return ['error' => 'getPaymentDetailsForOrder']; } /** @@ -529,7 +530,7 @@ public function getPaymentDetailsForOrder(Order $order): array public function getPaymentDetailsByTxnId($txnId): array { $transactions = $this->transactionRepo->getTransactionsByTxnId($txnId); - $paymentDetails = []; + $paymentDetails = ['error' => 'getPaymentDetailsByTxnId']; foreach ($transactions as $transaction) { /** @var Transaction $transaction */ From 3327ca66bdb0ee3749249a5265924dc9bfac3c71 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 12:33:19 +0100 Subject: [PATCH 21/68] [refactor] (PLENTY-80) NGW-IVsec: Debug: show all transactions. --- src/Helper/PaymentHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index 06d9eee..b63fdf9 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -532,9 +532,11 @@ public function getPaymentDetailsByTxnId($txnId): array $transactions = $this->transactionRepo->getTransactionsByTxnId($txnId); $paymentDetails = ['error' => 'getPaymentDetailsByTxnId']; + return $transactions; + foreach ($transactions as $transaction) { /** @var Transaction $transaction */ - if ($transaction->transactionType === TransactionType::HP_AUTHORIZE) { + if ($transaction->transactionType === TransactionType::AUTHORIZE) { $details = $transaction->transactionDetails; if (!isset( $details['CONNECTOR.ACCOUNT_IBAN'], From 130862b1d43600bfc5a2ee3e25876dccd135e332 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 12:36:53 +0100 Subject: [PATCH 22/68] [refactor] (PLENTY-80) NGW-IVsec: Fix fetching transaction for invoice generation. --- src/Helper/PaymentHelper.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index b63fdf9..262f4ff 100755 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -517,7 +517,7 @@ public function getPaymentDetailsForOrder(Order $order): array return $this->getPaymentDetailsByTxnId($relation->txnId); } - return ['error' => 'getPaymentDetailsForOrder']; + return []; } /** @@ -530,9 +530,7 @@ public function getPaymentDetailsForOrder(Order $order): array public function getPaymentDetailsByTxnId($txnId): array { $transactions = $this->transactionRepo->getTransactionsByTxnId($txnId); - $paymentDetails = ['error' => 'getPaymentDetailsByTxnId']; - - return $transactions; + $paymentDetails = []; foreach ($transactions as $transaction) { /** @var Transaction $transaction */ From 075364ad479770215e243990ca37c0d4e0ffc72c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 14:40:32 +0100 Subject: [PATCH 23/68] [refactor] (PLENTY-80) NGW-IVsec: Fix error loading checkout as guest. --- src/Providers/HeidelpayServiceProvider.php | 10 ---------- src/Services/BasketService.php | 6 ++++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 7e5509a..796db34 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -137,14 +137,10 @@ function (OrderPdfGenerationEvent $event) use ( $order = $event->getOrder(); $docType = $event->getDocType(); - $notificationService->error('OrderPdfGenerationEvent1', __METHOD__, ['Order' => $order, 'DocType' => $docType], true); - if ($docType !== Document::INVOICE) { return; } - $notificationService->error('OrderPdfGenerationEvent2', __METHOD__, ['Order' => $order, 'DocType' => $docType], true); - /** @var OrderPdfGeneration $orderPdfGeneration */ $orderPdfGeneration = pluginApp(OrderPdfGeneration::class); $language = $orderService->getLanguage($order); @@ -152,13 +148,10 @@ function (OrderPdfGenerationEvent $event) use ( $paymentDetails = $paymentHelper->getPaymentDetailsForOrder($order); - $notificationService->error('OrderPdfGenerationEvent3', __METHOD__, ['$paymentDetails' => $paymentDetails], true); - if (!isset($paymentDetails['accountIBAN'], $paymentDetails['accountBIC'], $paymentDetails['accountHolder'], $paymentDetails['accountUsage'])) { // do nothing if no payment details are defined, return; } - $notificationService->error('OrderPdfGenerationEvent4', __METHOD__, ['$paymentDetails' => $paymentDetails], true); $adviceParts = [ $notificationService->getTranslation('Heidelpay::template.pleaseTransferTheTotalTo', [], $language), @@ -169,9 +162,6 @@ function (OrderPdfGenerationEvent $event) use ( ]; $orderPdfGeneration->advice = implode(PHP_EOL, $adviceParts); - $notificationService->error('OrderPdfGenerationEvent5', __METHOD__, ['$orderPdfGeneration' => $orderPdfGeneration], true); - - $event->addOrderPdfGeneration($orderPdfGeneration); } ); diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 34126da..45fd1a4 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -132,7 +132,8 @@ public function getCustomerAddressData(): array $basket = $this->getBasket(); $addresses = []; - $addresses['billing'] = $this->addressRepository->findAddressById($basket->customerInvoiceAddressId); + $addresses['billing'] = $basket->customerInvoiceAddressId ? + $this->addressRepository->findAddressById($basket->customerInvoiceAddressId) : null; // if the shipping address is -99 or null, it is matching the billing address. if ($basket->customerShippingAddressId === null || $basket->customerShippingAddressId === -99) { @@ -170,6 +171,7 @@ public function getBasket(): Basket public function getBillingCountryCode(): string { $billingAddress = $this->getCustomerAddressData()['billing']; - return $this->countryRepository->findIsoCode($billingAddress->countryId, 'isoCode2'); + return $billingAddress ? + $this->countryRepository->findIsoCode($billingAddress->countryId, 'isoCode2') : ''; } } From 1dac297f23ae5c3b7a7c517c8a18c45c53f18e4c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:02:25 +0100 Subject: [PATCH 24/68] [refactor] (PLENTY-80) NGW-IVsec: Fix error loading checkout as guest. --- src/Methods/AbstractMethod.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 62f0741..89b46a3 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -99,12 +99,12 @@ public function isActive(): bool return false; } - // enable the payment method only if it is allowed for the given billing country - $countryRestrictions = $this->getCountryRestrictions(); - if (!empty($countryRestrictions) && - !in_array($this->basketService->getBillingCountryCode(), $countryRestrictions, true)) { - return false; - } +// // enable the payment method only if it is allowed for the given billing country +// $countryRestrictions = $this->getCountryRestrictions(); +// if (!empty($countryRestrictions) && +// !in_array($this->basketService->getBillingCountryCode(), $countryRestrictions, true)) { +// return false; +// } return true; } From 877b5dfb694979058469d92710e631d42130f87d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:05:42 +0100 Subject: [PATCH 25/68] [refactor] (PLENTY-80) NGW-IVsec: Fix error loading checkout as guest. --- src/Services/BasketService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 45fd1a4..a6f4d89 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -152,7 +152,7 @@ public function isBasketB2B(): bool { $billingAddress = $this->getCustomerAddressData()['billing']; - return $billingAddress->gender === null; + return $billingAddress ? $billingAddress->gender === null : true; } /** From 802785ed66c080618ca4ee1fdd2c03151edaabdf Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:12:02 +0100 Subject: [PATCH 26/68] [refactor] (PLENTY-80) NGW-IVsec: Fix error loading checkout as guest. --- src/Methods/AbstractMethod.php | 6 +++--- src/Services/BasketService.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 89b46a3..267de37 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -95,9 +95,9 @@ public function isActive(): bool } // enable the payment method only if it is enabled for the current transaction (B2C||B2B) - if ($this->isB2cOnly() && $this->basketService->isBasketB2B()) { - return false; - } +// if ($this->isB2cOnly() && $this->basketService->isBasketB2B()) { +// return false; +// } // // enable the payment method only if it is allowed for the given billing country // $countryRestrictions = $this->getCountryRestrictions(); diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index a6f4d89..bdf83d4 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -152,7 +152,7 @@ public function isBasketB2B(): bool { $billingAddress = $this->getCustomerAddressData()['billing']; - return $billingAddress ? $billingAddress->gender === null : true; + return $billingAddress ? $billingAddress->gender === null : false; } /** From 02fdb8eaf97c93e32fd7dca9dd7ab68681d90fe3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:31:05 +0100 Subject: [PATCH 27/68] [refactor] (PLENTY-80) NGW-IVsec: debug: add debug output --- src/Providers/HeidelpayServiceProvider.php | 6 +++++- src/Services/PaymentService.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 796db34..b542e77 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -95,12 +95,16 @@ public function boot( GetPaymentMethodContent::class, function (GetPaymentMethodContent $event) use ( $paymentHelper, - $paymentService + $paymentService, + $notificationService ) { $mop = $event->getMop(); + $notificationService->error('1', __METHOD__, ['event' => $event]); $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mop); + $notificationService->error('2', __METHOD__, ['method' => $paymentMethod]); if (!empty($paymentMethod)) { + $notificationService->error('3', __METHOD__, ['method' => $paymentMethod]); list($type, $value) = $paymentService->getPaymentMethodContent($paymentMethod, $mop); $event->setValue($value); diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 286943e..51c6b26 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -269,6 +269,7 @@ public function getPaymentMethodContent( $value = $clientErrorMessage; return [$type, $value]; } + $this->notification->error('3',__METHOD__, [$methodInstance]); $type = $methodInstance->getReturnType(); @@ -279,6 +280,7 @@ public function getPaymentMethodContent( $value = $this->urlService->generateURL(Routes::HANDLE_FORM_URL); $basket = $this->basketService->getBasket(); + $this->notification->error('4',__METHOD__, [$basket]); if ($methodInstance->hasToBeInitialized()) { try { $transactionType = $methodInstance->getTransactionType(); @@ -293,9 +295,11 @@ public function getPaymentMethodContent( } $customerId = $basket->customerId; + $this->notification->error('5',__METHOD__, ['customerId' => $customerId]); $contact = $this->contactRepo->findContactById($customerId); $birthday = explode('-', substr($contact->birthdayAt, 0, 10)); + $this->notification->error('6',__METHOD__, ['contact' => $contact]); if ($type === GetPaymentMethodContent::RETURN_TYPE_HTML) { // $value should contain the payment frame url (also form url) From 03461535f14133e5e5caf9301ff8d617b8662e70 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:35:14 +0100 Subject: [PATCH 28/68] [refactor] (PLENTY-80) NGW-IVsec: debug: add debug output --- src/Services/PaymentService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 51c6b26..54a3805 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -297,8 +297,8 @@ public function getPaymentMethodContent( $customerId = $basket->customerId; $this->notification->error('5',__METHOD__, ['customerId' => $customerId]); - $contact = $this->contactRepo->findContactById($customerId); - $birthday = explode('-', substr($contact->birthdayAt, 0, 10)); + $contact = $customerId ? $this->contactRepo->findContactById($customerId) : null; + $birthday = $contact ? explode('-', substr($contact->birthdayAt, 0, 10)): null; $this->notification->error('6',__METHOD__, ['contact' => $contact]); if ($type === GetPaymentMethodContent::RETURN_TYPE_HTML) { From ec426cf187e769689f7b77d359c58116bbda4f99 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:38:46 +0100 Subject: [PATCH 29/68] [refactor] (PLENTY-80) NGW-IVsec: remove debug outputs. --- src/Providers/HeidelpayServiceProvider.php | 3 --- src/Services/PaymentService.php | 5 ----- 2 files changed, 8 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index b542e77..e5feb6c 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -99,12 +99,9 @@ function (GetPaymentMethodContent $event) use ( $notificationService ) { $mop = $event->getMop(); - $notificationService->error('1', __METHOD__, ['event' => $event]); $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mop); - $notificationService->error('2', __METHOD__, ['method' => $paymentMethod]); if (!empty($paymentMethod)) { - $notificationService->error('3', __METHOD__, ['method' => $paymentMethod]); list($type, $value) = $paymentService->getPaymentMethodContent($paymentMethod, $mop); $event->setValue($value); diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 54a3805..76fd577 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -269,7 +269,6 @@ public function getPaymentMethodContent( $value = $clientErrorMessage; return [$type, $value]; } - $this->notification->error('3',__METHOD__, [$methodInstance]); $type = $methodInstance->getReturnType(); @@ -280,7 +279,6 @@ public function getPaymentMethodContent( $value = $this->urlService->generateURL(Routes::HANDLE_FORM_URL); $basket = $this->basketService->getBasket(); - $this->notification->error('4',__METHOD__, [$basket]); if ($methodInstance->hasToBeInitialized()) { try { $transactionType = $methodInstance->getTransactionType(); @@ -295,11 +293,8 @@ public function getPaymentMethodContent( } $customerId = $basket->customerId; - $this->notification->error('5',__METHOD__, ['customerId' => $customerId]); - $contact = $customerId ? $this->contactRepo->findContactById($customerId) : null; $birthday = $contact ? explode('-', substr($contact->birthdayAt, 0, 10)): null; - $this->notification->error('6',__METHOD__, ['contact' => $contact]); if ($type === GetPaymentMethodContent::RETURN_TYPE_HTML) { // $value should contain the payment frame url (also form url) From 2f129a41612cf5d3b4f487ce2bd04b16a0f6b147 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 15:55:39 +0100 Subject: [PATCH 30/68] [refactor] (PLENTY-80) NGW-IVsec: Reenable possible error sources. --- src/Methods/AbstractMethod.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 267de37..62f0741 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -95,16 +95,16 @@ public function isActive(): bool } // enable the payment method only if it is enabled for the current transaction (B2C||B2B) -// if ($this->isB2cOnly() && $this->basketService->isBasketB2B()) { -// return false; -// } - -// // enable the payment method only if it is allowed for the given billing country -// $countryRestrictions = $this->getCountryRestrictions(); -// if (!empty($countryRestrictions) && -// !in_array($this->basketService->getBillingCountryCode(), $countryRestrictions, true)) { -// return false; -// } + if ($this->isB2cOnly() && $this->basketService->isBasketB2B()) { + return false; + } + + // enable the payment method only if it is allowed for the given billing country + $countryRestrictions = $this->getCountryRestrictions(); + if (!empty($countryRestrictions) && + !in_array($this->basketService->getBillingCountryCode(), $countryRestrictions, true)) { + return false; + } return true; } From 020fab37449fd28f5af1d04d4b9bb2c235390459 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 16:09:42 +0100 Subject: [PATCH 31/68] [refactor] (PLENTY-80) NGW-IVsec: Fix twig layout. --- resources/views/content/InvoiceDetails.twig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/views/content/InvoiceDetails.twig b/resources/views/content/InvoiceDetails.twig index c4b5957..518c053 100755 --- a/resources/views/content/InvoiceDetails.twig +++ b/resources/views/content/InvoiceDetails.twig @@ -1,18 +1,18 @@
{{ trans("Heidelpay::template.pleaseTransferTheTotalTo") }}
-
{{ trans("Heidelpay::template.accountIban") }}:
-
{{ accountIBAN }}
+
{{ trans("Heidelpay::template.accountIban") }}:
+
{{ accountIBAN }}
-
{{ trans("Heidelpay::template.accountBic") }}:
-
{{ accountBIC }}
+
{{ trans("Heidelpay::template.accountBic") }}:
+
{{ accountBIC }}
-
{{ trans("Heidelpay::template.accountHolder") }}:
-
{{ accountHolder }}
+
{{ trans("Heidelpay::template.accountHolder") }}:
+
{{ accountHolder }}
-
{{ trans("Heidelpay::template.accountUsage") }}:
-
{{ accountUsage }}
+
{{ trans("Heidelpay::template.accountUsage") }}:
+
{{ accountUsage }}
From c35edd6e7728172595d183f8854b249f2ab83cc3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 15 Mar 2019 16:20:14 +0100 Subject: [PATCH 32/68] [refactor] (PLENTY-80) NGW-IVsec: Fix twig layout. --- resources/views/invoiceSecuredB2CForm.twig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/invoiceSecuredB2CForm.twig b/resources/views/invoiceSecuredB2CForm.twig index f54d577..97fe089 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -3,11 +3,11 @@ {% block content %}
-
+
-
+
-
+
{% include "Heidelpay::partials/cancelSubmitButtons" %}
{% endblock %} {% block scripts %} -{% endblock %} \ No newline at end of file +{% endblock %} From d4e0d3a94ad0ec17e44b5e702a9458e1e09f7f23 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 08:50:30 +0100 Subject: [PATCH 33/68] [refactor] (PLENTY-80) NGW-IVsec: Refactor rendering bank data on invoice. --- src/Providers/HeidelpayServiceProvider.php | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index e5feb6c..5d9b3a1 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -7,6 +7,7 @@ use Heidelpay\Configs\MethodConfig; use Heidelpay\Configs\MethodConfigContract; use Heidelpay\Helper\PaymentHelper; +use Heidelpay\Methods\AbstractMethod; use Heidelpay\Models\Contracts\OrderTxnIdRelationRepositoryContract; use Heidelpay\Models\Contracts\TransactionRepositoryContract; use Heidelpay\Models\Repositories\OrderTxnIdRelationRepository; @@ -21,6 +22,7 @@ use Heidelpay\Services\UrlService; use Heidelpay\Services\UrlServiceContract; use Plenty\Modules\Document\Models\Document; +use Plenty\Modules\Order\Models\Order; use Plenty\Modules\Order\Pdf\Events\OrderPdfGenerationEvent; use Plenty\Modules\Order\Pdf\Models\OrderPdfGeneration; use Plenty\Modules\Payment\Events\Checkout\ExecutePayment; @@ -95,8 +97,7 @@ public function boot( GetPaymentMethodContent::class, function (GetPaymentMethodContent $event) use ( $paymentHelper, - $paymentService, - $notificationService + $paymentService ) { $mop = $event->getMop(); $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mop); @@ -135,8 +136,13 @@ function (ExecutePayment $event) use ( function (OrderPdfGenerationEvent $event) use ( $notificationService, $paymentHelper, $orderService ) { + /** @var Order $order */ $order = $event->getOrder(); $docType = $event->getDocType(); + $mop = $order->methodOfPaymentId; + + /** @var AbstractMethod $paymentMethod */ + $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mop); if ($docType !== Document::INVOICE) { return; @@ -149,17 +155,21 @@ function (OrderPdfGenerationEvent $event) use ( $paymentDetails = $paymentHelper->getPaymentDetailsForOrder($order); - if (!isset($paymentDetails['accountIBAN'], $paymentDetails['accountBIC'], $paymentDetails['accountHolder'], $paymentDetails['accountUsage'])) { - // do nothing if no payment details are defined, + if (!$paymentMethod->renderInvoiceData()) { + // do nothing if invoice data does not need to be rendered return; } $adviceParts = [ $notificationService->getTranslation('Heidelpay::template.pleaseTransferTheTotalTo', [], $language), - $notificationService->getTranslation('Heidelpay::template.accountIban', [], $language) . ': ' . $paymentDetails['accountIBAN'], - $notificationService->getTranslation('Heidelpay::template.accountBic', [], $language) . ': ' . $paymentDetails['accountBIC'], - $notificationService->getTranslation('Heidelpay::template.accountHolder', [], $language) . ': ' . $paymentDetails['accountHolder'], - $notificationService->getTranslation('Heidelpay::template.accountUsage', [], $language) . ': ' . $paymentDetails['accountUsage'] + $notificationService->getTranslation('Heidelpay::template.accountIban', [], $language) . ': ' . + $paymentDetails['accountIBAN'], + $notificationService->getTranslation('Heidelpay::template.accountBic', [], $language) . ': ' . + $paymentDetails['accountBIC'], + $notificationService->getTranslation('Heidelpay::template.accountHolder', [], $language) . ': ' . + $paymentDetails['accountHolder'], + $notificationService->getTranslation('Heidelpay::template.accountUsage', [], $language) . ': ' . + $paymentDetails['accountUsage'] ]; $orderPdfGeneration->advice = implode(PHP_EOL, $adviceParts); From b5f8a62e88e3d3f6fe570e12e713bb31ec332289 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 09:39:54 +0100 Subject: [PATCH 34/68] [refactor] (PLENTY-80) NGW-IVsec: Show IVsec only if billing and shipping address match. --- src/Methods/AbstractMethod.php | 5 +++++ src/Services/BasketService.php | 25 +++++++++++++++++++++++++ src/Services/BasketServiceContract.php | 7 ++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 62f0741..0f683aa 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -106,6 +106,11 @@ public function isActive(): bool return false; } + // show payment only if the billing and shipping address matches + if (!$this->basketService->shippingMatchesBillingAddress()) { + return false; + } + return true; } diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index bdf83d4..2bfff1b 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -123,6 +123,31 @@ function () use ($basketItem) { } /** + * {@inheritDoc} + */ + public function shippingMatchesBillingAddress(): bool + { + $basket = $this->getBasket(); + if ($basket->customerShippingAddressId === null || $basket->customerShippingAddressId === -99) { + return true; + } + + $addresses = $this->getCustomerAddressData(); + $billingAddress = $addresses['billing']; + $shippingAddress = $addresses['shipping']; + + return $billingAddress->gender === $shippingAddress->gender && + $billingAddress->street === $shippingAddress->street && + $billingAddress->houseNumber === $shippingAddress->houseNumber && + $billingAddress->postalCode === $shippingAddress->postalCode && + $billingAddress->town === $shippingAddress->town && + $billingAddress->country === $shippingAddress->country + ( + ($this->isBasketB2B() && $billingAddress->careOf === $shippingAddress->careOf) || + (!$this->isBasketB2B() && $billingAddress->lastName === $shippingAddress->lastName) + ); + } + /** * Gathers address data (billing/invoice and shipping) and returns them as an array. * * @return Address[] diff --git a/src/Services/BasketServiceContract.php b/src/Services/BasketServiceContract.php index 6e6f0c4..d42d2e7 100644 --- a/src/Services/BasketServiceContract.php +++ b/src/Services/BasketServiceContract.php @@ -67,4 +67,9 @@ public function getBasket(): Basket; * @return string */ public function getBillingCountryCode(): string; -} \ No newline at end of file + + /** + * Returns true if the shipping and billing address are equal. + */ + public function shippingMatchesBillingAddress(): bool; +} From 99feead489b3680fc6a2149c9e158915dcdd1ad7 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 09:56:00 +0100 Subject: [PATCH 35/68] [refactor] (PLENTY-80) NGW-IVsec: Show IVsec only if billing and shipping address match. --- src/Methods/AbstractMethod.php | 11 ++++++++++- src/Methods/InvoiceSecuredB2C.php | 1 + src/Methods/PaymentMethodContract.php | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 0f683aa..9a74e6b 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -36,6 +36,7 @@ abstract class AbstractMethod extends PaymentMethodService implements PaymentMet const RENDER_INVOICE_DATA = false; const B2C_ONLY = false; const COUNTRY_RESTRICTION = []; + const ADDRESSES_MUST_MATCH = false; /** * @var PaymentHelper $helper @@ -107,7 +108,7 @@ public function isActive(): bool } // show payment only if the billing and shipping address matches - if (!$this->basketService->shippingMatchesBillingAddress()) { + if ($this->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { return false; } @@ -313,4 +314,12 @@ public function getCountryRestrictions(): array { return static::COUNTRY_RESTRICTION; } + + /** + * {@inheritDoc} + */ + public function needsMatchingAddresses(): bool + { + return static::ADDRESSES_MUST_MATCH; + } } diff --git a/src/Methods/InvoiceSecuredB2C.php b/src/Methods/InvoiceSecuredB2C.php index 729e825..f1d833e 100755 --- a/src/Methods/InvoiceSecuredB2C.php +++ b/src/Methods/InvoiceSecuredB2C.php @@ -30,4 +30,5 @@ class InvoiceSecuredB2C extends AbstractMethod const RENDER_INVOICE_DATA = true; const B2C_ONLY = true; const COUNTRY_RESTRICTION = ['DE', 'AT']; + const ADDRESSES_MUST_MATCH = true; } diff --git a/src/Methods/PaymentMethodContract.php b/src/Methods/PaymentMethodContract.php index 36164cb..0332d63 100755 --- a/src/Methods/PaymentMethodContract.php +++ b/src/Methods/PaymentMethodContract.php @@ -154,4 +154,11 @@ public function isB2cOnly(): bool; * Returns an array with the countries the method is restricted to. */ public function getCountryRestrictions(): array; + + /** + * Returns true if the shipping and billing address have to match for this payment method. + * + * @return bool + */ + public function needsMatchingAddresses(): bool; } From 6b1637ff528ae0528b16eb97d0c9b904455666b9 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 10:26:30 +0100 Subject: [PATCH 36/68] [refactor] (PLENTY-80) NGW-IVsec: Add error if addresses do not match. --- resources/lang/de/payment.properties | 3 ++- resources/lang/en/payment.properties | 3 ++- src/Methods/AbstractMethod.php | 10 +++++----- src/Services/PaymentService.php | 6 ++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/resources/lang/de/payment.properties b/resources/lang/de/payment.properties index c58f178..12e34bd 100755 --- a/resources/lang/de/payment.properties +++ b/resources/lang/de/payment.properties @@ -11,4 +11,5 @@ errorBookingTextIsMissing = "PaymentProperty::TYPE_BOOKING_TEXT ist nicht gesetz errorTransactionTypeUndefined = "Transaction type ist nicht definiert" debugPaymentFound = "Plenty Payment gefunden" debugHandleIncomingPayment = "Eingehende Zahlungsinformationen wird verarbeitet." -warningOrderDoesNotExist = "Die Bestellung existiert (noch) nicht." \ No newline at end of file +warningOrderDoesNotExist = "Die Bestellung existiert (noch) nicht." +addressesShouldMatch = "Rechnungs- und Versandadresse müssen gleich sein." diff --git a/resources/lang/en/payment.properties b/resources/lang/en/payment.properties index dd57823..b0dd225 100755 --- a/resources/lang/en/payment.properties +++ b/resources/lang/en/payment.properties @@ -11,4 +11,5 @@ errorBookingTextIsMissing = "PaymentProperty::TYPE_BOOKING_TEXT is not set" errorTransactionTypeUndefined = "Transaction type is undefined" debugPaymentFound = "Plenty Payment found" debugHandleIncomingPayment = "Handle incoming payment information." -warningOrderDoesNotExist = "Order does not exist (yet)." \ No newline at end of file +warningOrderDoesNotExist = "Order does not exist (yet)." +addressesShouldMatch = "Invoice and shipping address must match." diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 9a74e6b..cac329d 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -5,6 +5,7 @@ use Heidelpay\Configs\MethodConfigContract; use Heidelpay\Helper\PaymentHelper; use Heidelpay\Services\BasketServiceContract; +use Heidelpay\Services\NotificationServiceContract; use Plenty\Modules\Payment\Events\Checkout\GetPaymentMethodContent; use Plenty\Modules\Payment\Method\Contracts\PaymentMethodService; use Plenty\Plugin\Application; @@ -51,6 +52,10 @@ abstract class AbstractMethod extends PaymentMethodService implements PaymentMet * @var BasketServiceContract */ private $basketService; + /** + * @var NotificationServiceContract + */ + private $notificationService; /** * AbstractMethod constructor. @@ -107,11 +112,6 @@ public function isActive(): bool return false; } - // show payment only if the billing and shipping address matches - if ($this->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - return false; - } - return true; } diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 76fd577..a7d9763 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -263,15 +263,17 @@ public function getPaymentMethodContent( /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); - if (!$methodInstance instanceof PaymentMethodContract) { $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; $value = $clientErrorMessage; return [$type, $value]; } - $type = $methodInstance->getReturnType(); + if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { + return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; + } + $type = $methodInstance->getReturnType(); if ($type === GetPaymentMethodContent::RETURN_TYPE_CONTINUE) { return [$type, $value]; } From 32b6f120c269f23bad776b0cd0830d5c9cde954c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 10:28:02 +0100 Subject: [PATCH 37/68] [refactor] (PLENTY-80) NGW-IVsec: Debug add notification on address match error. --- src/Services/PaymentService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index a7d9763..705d345 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,6 +270,10 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { + $this->notification->error('payment.addressesShouldMatch', + __METHOD__, + ['Addresses' => $this->basketService->getCustomerAddressData()], + true); return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; } From 4636bb8984d4d44884a67dca13f01c0a3daa8054 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 10:43:10 +0100 Subject: [PATCH 38/68] [refactor] (PLENTY-80) NGW-IVsec: Debug add notification on address match error. --- src/Services/BasketService.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 2bfff1b..379f90b 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -137,14 +137,15 @@ public function shippingMatchesBillingAddress(): bool $shippingAddress = $addresses['shipping']; return $billingAddress->gender === $shippingAddress->gender && - $billingAddress->street === $shippingAddress->street && - $billingAddress->houseNumber === $shippingAddress->houseNumber && + $billingAddress->address1 === $shippingAddress->address1 && + $billingAddress->address2 === $shippingAddress->address2 && $billingAddress->postalCode === $shippingAddress->postalCode && $billingAddress->town === $shippingAddress->town && - $billingAddress->country === $shippingAddress->country + $billingAddress->countryId === $shippingAddress->countryId ( - ($this->isBasketB2B() && $billingAddress->careOf === $shippingAddress->careOf) || - (!$this->isBasketB2B() && $billingAddress->lastName === $shippingAddress->lastName) + ($this->isBasketB2B() && $billingAddress->name1 === $shippingAddress->name1) || + (!$this->isBasketB2B() && $billingAddress->name2 === $shippingAddress->name2 + && $billingAddress->name3 === $shippingAddress->name3) ); } /** From c42066826b95113cba5b8e32ce7ba422bcef77b7 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 10:51:06 +0100 Subject: [PATCH 39/68] [refactor] (PLENTY-80) NGW-IVsec: Remove country check. --- src/Services/BasketService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 379f90b..9f26939 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -140,8 +140,7 @@ public function shippingMatchesBillingAddress(): bool $billingAddress->address1 === $shippingAddress->address1 && $billingAddress->address2 === $shippingAddress->address2 && $billingAddress->postalCode === $shippingAddress->postalCode && - $billingAddress->town === $shippingAddress->town && - $billingAddress->countryId === $shippingAddress->countryId + $billingAddress->town === $shippingAddress->town ( ($this->isBasketB2B() && $billingAddress->name1 === $shippingAddress->name1) || (!$this->isBasketB2B() && $billingAddress->name2 === $shippingAddress->name2 From 9a1164248f88ac5737d607e1724ed5d3cb6b1c73 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 10:59:07 +0100 Subject: [PATCH 40/68] [refactor] (PLENTY-80) NGW-IVsec: Remove country town for now. --- src/Services/BasketService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 9f26939..d392717 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -140,7 +140,6 @@ public function shippingMatchesBillingAddress(): bool $billingAddress->address1 === $shippingAddress->address1 && $billingAddress->address2 === $shippingAddress->address2 && $billingAddress->postalCode === $shippingAddress->postalCode && - $billingAddress->town === $shippingAddress->town ( ($this->isBasketB2B() && $billingAddress->name1 === $shippingAddress->name1) || (!$this->isBasketB2B() && $billingAddress->name2 === $shippingAddress->name2 From 112c87ef0e0cdc2157800b5cc25596999fc3599c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:04:44 +0100 Subject: [PATCH 41/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index d392717..38b91e5 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -137,13 +137,13 @@ public function shippingMatchesBillingAddress(): bool $shippingAddress = $addresses['shipping']; return $billingAddress->gender === $shippingAddress->gender && - $billingAddress->address1 === $shippingAddress->address1 && - $billingAddress->address2 === $shippingAddress->address2 && + strcasecmp($billingAddress->address1, $shippingAddress->address1) && + strcasecmp($billingAddress->address2, $shippingAddress->address2) && $billingAddress->postalCode === $shippingAddress->postalCode && ( - ($this->isBasketB2B() && $billingAddress->name1 === $shippingAddress->name1) || - (!$this->isBasketB2B() && $billingAddress->name2 === $shippingAddress->name2 - && $billingAddress->name3 === $shippingAddress->name3) + ($this->isBasketB2B() && strcasecmp($billingAddress->name1, $shippingAddress->name1)) || + (!$this->isBasketB2B() && strcasecmp($billingAddress->name2, $shippingAddress->name2) + && strcasecmp($billingAddress->name3, $shippingAddress->name3)) ); } /** From 08f8ea4a26093d8ecb7135e5a56a45c5c9c0dd23 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:09:04 +0100 Subject: [PATCH 42/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 38b91e5..252d421 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -137,13 +137,13 @@ public function shippingMatchesBillingAddress(): bool $shippingAddress = $addresses['shipping']; return $billingAddress->gender === $shippingAddress->gender && - strcasecmp($billingAddress->address1, $shippingAddress->address1) && - strcasecmp($billingAddress->address2, $shippingAddress->address2) && + $this->strCompare($billingAddress, $shippingAddress) && + $this->strCompare($billingAddress->address2, $shippingAddress->address2) && $billingAddress->postalCode === $shippingAddress->postalCode && ( - ($this->isBasketB2B() && strcasecmp($billingAddress->name1, $shippingAddress->name1)) || - (!$this->isBasketB2B() && strcasecmp($billingAddress->name2, $shippingAddress->name2) - && strcasecmp($billingAddress->name3, $shippingAddress->name3)) + ($this->isBasketB2B() && $this->strCompare($billingAddress->name1, $shippingAddress->name1)) || + (!$this->isBasketB2B() && $this->strCompare($billingAddress->name2, $shippingAddress->name2) + && $this->strCompare($billingAddress->name3, $shippingAddress->name3)) ); } /** @@ -198,4 +198,16 @@ public function getBillingCountryCode(): string return $billingAddress ? $this->countryRepository->findIsoCode($billingAddress->countryId, 'isoCode2') : ''; } + + /** + * Returns true if the strings match case insensitive. + * + * @param Address $billingAddress + * @param Address $shippingAddress + * @return bool + */ + private function strCompare(Address $billingAddress, Address $shippingAddress): bool + { + return strtolower($billingAddress->address1) === strtolower($shippingAddress->address1); + } } From 1073a3cc44f74f2de9491ec713a8f3ec38aa70c0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:14:07 +0100 Subject: [PATCH 43/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 252d421..f0c39cd 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -202,12 +202,12 @@ public function getBillingCountryCode(): string /** * Returns true if the strings match case insensitive. * - * @param Address $billingAddress - * @param Address $shippingAddress + * @param string $string1 + * @param string $string2 * @return bool */ - private function strCompare(Address $billingAddress, Address $shippingAddress): bool + private function strCompare($string1, $string2): bool { - return strtolower($billingAddress->address1) === strtolower($shippingAddress->address1); + return strtolower($string1) === strtolower($string2); } } From f92368bfe36fcddc3307f5c8d9c39cefe0f8d877 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:19:22 +0100 Subject: [PATCH 44/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index f0c39cd..acb657e 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -137,7 +137,7 @@ public function shippingMatchesBillingAddress(): bool $shippingAddress = $addresses['shipping']; return $billingAddress->gender === $shippingAddress->gender && - $this->strCompare($billingAddress, $shippingAddress) && + $this->strCompare($billingAddress->address1, $shippingAddress->address1) && $this->strCompare($billingAddress->address2, $shippingAddress->address2) && $billingAddress->postalCode === $shippingAddress->postalCode && ( From c2cfe87ba2eee756ade64a3e6e3e3cecbb747c12 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:26:14 +0100 Subject: [PATCH 45/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index acb657e..ce30f4d 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -140,6 +140,7 @@ public function shippingMatchesBillingAddress(): bool $this->strCompare($billingAddress->address1, $shippingAddress->address1) && $this->strCompare($billingAddress->address2, $shippingAddress->address2) && $billingAddress->postalCode === $shippingAddress->postalCode && + $billingAddress->town === $shippingAddress->town ( ($this->isBasketB2B() && $this->strCompare($billingAddress->name1, $shippingAddress->name1)) || (!$this->isBasketB2B() && $this->strCompare($billingAddress->name2, $shippingAddress->name2) @@ -157,7 +158,7 @@ public function getCustomerAddressData(): array $addresses = []; $addresses['billing'] = $basket->customerInvoiceAddressId ? - $this->addressRepository->findAddressById($basket->customerInvoiceAddressId) : null; + $this->addressRepository->findAddressById($basket->customerInvoiceAddressId)->toArray() : null; // if the shipping address is -99 or null, it is matching the billing address. if ($basket->customerShippingAddressId === null || $basket->customerShippingAddressId === -99) { @@ -165,7 +166,8 @@ public function getCustomerAddressData(): array return $addresses; } - $addresses['shipping'] = $this->addressRepository->findAddressById($basket->customerShippingAddressId); + $addresses['shipping'] = + $this->addressRepository->findAddressById($basket->customerShippingAddressId)->toArray(); return $addresses; } From 773fd57a8313c69814cc9cdb1509ea97069b5b0c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:36:40 +0100 Subject: [PATCH 46/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index ce30f4d..c65b031 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -133,18 +133,19 @@ public function shippingMatchesBillingAddress(): bool } $addresses = $this->getCustomerAddressData(); - $billingAddress = $addresses['billing']; - $shippingAddress = $addresses['shipping']; - - return $billingAddress->gender === $shippingAddress->gender && - $this->strCompare($billingAddress->address1, $shippingAddress->address1) && - $this->strCompare($billingAddress->address2, $shippingAddress->address2) && - $billingAddress->postalCode === $shippingAddress->postalCode && - $billingAddress->town === $shippingAddress->town + $billingAddress = $addresses['billing']->toArray(); + $shippingAddress = $addresses['shipping']->toArray(); + + return $billingAddress['gender'] === $shippingAddress['gender'] && + $this->strCompare($billingAddress['address1'], $shippingAddress['address1']) && + $this->strCompare($billingAddress['address2'], $shippingAddress['address2']) && + $billingAddress['postalCode'] === $shippingAddress['postalCode'] && + $billingAddress['town'] === $shippingAddress['town']&& + $billingAddress['country'] === $shippingAddress['country'] ( - ($this->isBasketB2B() && $this->strCompare($billingAddress->name1, $shippingAddress->name1)) || - (!$this->isBasketB2B() && $this->strCompare($billingAddress->name2, $shippingAddress->name2) - && $this->strCompare($billingAddress->name3, $shippingAddress->name3)) + ($this->isBasketB2B() && $this->strCompare($billingAddress['name1'], $shippingAddress['name1'])) || + (!$this->isBasketB2B() && $this->strCompare($billingAddress['name2'], $shippingAddress['name2']) + && $this->strCompare($billingAddress['name3'], $shippingAddress['name3'])) ); } /** @@ -158,7 +159,7 @@ public function getCustomerAddressData(): array $addresses = []; $addresses['billing'] = $basket->customerInvoiceAddressId ? - $this->addressRepository->findAddressById($basket->customerInvoiceAddressId)->toArray() : null; + $this->addressRepository->findAddressById($basket->customerInvoiceAddressId) : null; // if the shipping address is -99 or null, it is matching the billing address. if ($basket->customerShippingAddressId === null || $basket->customerShippingAddressId === -99) { @@ -166,8 +167,7 @@ public function getCustomerAddressData(): array return $addresses; } - $addresses['shipping'] = - $this->addressRepository->findAddressById($basket->customerShippingAddressId)->toArray(); + $addresses['shipping'] = $this->addressRepository->findAddressById($basket->customerShippingAddressId); return $addresses; } From 979453beac1055062e2711941ad591bfa7bbd165 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:41:13 +0100 Subject: [PATCH 47/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index c65b031..5007626 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -140,8 +140,8 @@ public function shippingMatchesBillingAddress(): bool $this->strCompare($billingAddress['address1'], $shippingAddress['address1']) && $this->strCompare($billingAddress['address2'], $shippingAddress['address2']) && $billingAddress['postalCode'] === $shippingAddress['postalCode'] && - $billingAddress['town'] === $shippingAddress['town']&& - $billingAddress['country'] === $shippingAddress['country'] + $this->strCompare($billingAddress['town'], $shippingAddress['town']) && + $this->strCompare($billingAddress['country'], $shippingAddress['country']) ( ($this->isBasketB2B() && $this->strCompare($billingAddress['name1'], $shippingAddress['name1'])) || (!$this->isBasketB2B() && $this->strCompare($billingAddress['name2'], $shippingAddress['name2']) From 986b15ce19abd79a9fb47b124d43f3bb85a935ba Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 11:55:31 +0100 Subject: [PATCH 48/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 5007626..7eb93e4 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -141,7 +141,7 @@ public function shippingMatchesBillingAddress(): bool $this->strCompare($billingAddress['address2'], $shippingAddress['address2']) && $billingAddress['postalCode'] === $shippingAddress['postalCode'] && $this->strCompare($billingAddress['town'], $shippingAddress['town']) && - $this->strCompare($billingAddress['country'], $shippingAddress['country']) + $billingAddress['countryId'] && $shippingAddress['countryId'] ( ($this->isBasketB2B() && $this->strCompare($billingAddress['name1'], $shippingAddress['name1'])) || (!$this->isBasketB2B() && $this->strCompare($billingAddress['name2'], $shippingAddress['name2']) From 3bfb1a039143f2a704c6141163979d32e787ade5 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 12:09:35 +0100 Subject: [PATCH 49/68] [refactor] (PLENTY-80) NGW-IVsec: Address comparison. --- src/Services/BasketServiceContract.php | 2 +- src/Services/PaymentService.php | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Services/BasketServiceContract.php b/src/Services/BasketServiceContract.php index d42d2e7..33c0f78 100644 --- a/src/Services/BasketServiceContract.php +++ b/src/Services/BasketServiceContract.php @@ -62,7 +62,7 @@ public function isBasketB2B(): bool; public function getBasket(): Basket; /** - * Returns the country code as isoCode2. + * Returns the country code of the billing address as isoCode2. * * @return string */ diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 705d345..cfd93cb 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,10 +270,15 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - $this->notification->error('payment.addressesShouldMatch', - __METHOD__, - ['Addresses' => $this->basketService->getCustomerAddressData()], - true); + $this->notification->error( + 'payment.addressesShouldMatch', + __METHOD__, + [ + 'billing' => $this->basketService->getCustomerAddressData()['billing']->toArray(), + 'shipping' => $this->basketService->getCustomerAddressData()['shipping']->toArray() + ], + true + ); return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; } From c1b2242e2a09fe9a8cbef68d9afc61f76dd3db82 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 12:17:09 +0100 Subject: [PATCH 50/68] [refactor] (PLENTY-80) NGW-IVsec: debug remove country comparison. --- src/Services/BasketService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 7eb93e4..e80b9ae 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -141,7 +141,6 @@ public function shippingMatchesBillingAddress(): bool $this->strCompare($billingAddress['address2'], $shippingAddress['address2']) && $billingAddress['postalCode'] === $shippingAddress['postalCode'] && $this->strCompare($billingAddress['town'], $shippingAddress['town']) && - $billingAddress['countryId'] && $shippingAddress['countryId'] ( ($this->isBasketB2B() && $this->strCompare($billingAddress['name1'], $shippingAddress['name1'])) || (!$this->isBasketB2B() && $this->strCompare($billingAddress['name2'], $shippingAddress['name2']) From d3a42c62acfaff95437964c34d0ee8f597f00d55 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 12:28:35 +0100 Subject: [PATCH 51/68] [refactor] (PLENTY-80) NGW-IVsec: debug remove country comparison. --- src/Services/BasketService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index e80b9ae..c7f5111 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -141,6 +141,7 @@ public function shippingMatchesBillingAddress(): bool $this->strCompare($billingAddress['address2'], $shippingAddress['address2']) && $billingAddress['postalCode'] === $shippingAddress['postalCode'] && $this->strCompare($billingAddress['town'], $shippingAddress['town']) && + $billingAddress['countryId'] === $shippingAddress['countryId'] && ( ($this->isBasketB2B() && $this->strCompare($billingAddress['name1'], $shippingAddress['name1'])) || (!$this->isBasketB2B() && $this->strCompare($billingAddress['name2'], $shippingAddress['name2']) From 6524f7d5022ecf629aa804e1ec65c4d779eed136 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 12:40:43 +0100 Subject: [PATCH 52/68] [refactor] (PLENTY-80) NGW-IVsec: debug remove country comparison. --- src/Services/BasketService.php | 1 - src/Services/PaymentService.php | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index c7f5111..e80b9ae 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -141,7 +141,6 @@ public function shippingMatchesBillingAddress(): bool $this->strCompare($billingAddress['address2'], $shippingAddress['address2']) && $billingAddress['postalCode'] === $shippingAddress['postalCode'] && $this->strCompare($billingAddress['town'], $shippingAddress['town']) && - $billingAddress['countryId'] === $shippingAddress['countryId'] && ( ($this->isBasketB2B() && $this->strCompare($billingAddress['name1'], $shippingAddress['name1'])) || (!$this->isBasketB2B() && $this->strCompare($billingAddress['name2'], $shippingAddress['name2']) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index cfd93cb..f6c3223 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,12 +270,15 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { + $billingArray = $this->basketService->getCustomerAddressData()['billing']->toArray(); + $shippingArray = $this->basketService->getCustomerAddressData()['shipping']->toArray(); $this->notification->error( 'payment.addressesShouldMatch', __METHOD__, - [ - 'billing' => $this->basketService->getCustomerAddressData()['billing']->toArray(), - 'shipping' => $this->basketService->getCustomerAddressData()['shipping']->toArray() + ['billing' => $billingArray, + 'shipping' => $shippingArray, + 'billingcountry' => $billingArray['countryId'], + 'shippingcountry' => $shippingArray['countryId'] ], true ); From a4bddf33a1763406bcb96d525a01c9bc49e1eab4 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 12:44:10 +0100 Subject: [PATCH 53/68] [refactor] (PLENTY-80) NGW-IVsec: debug remove country comparison. --- src/Services/PaymentService.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index f6c3223..f53e6d9 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -276,9 +276,7 @@ public function getPaymentMethodContent( 'payment.addressesShouldMatch', __METHOD__, ['billing' => $billingArray, - 'shipping' => $shippingArray, - 'billingcountry' => $billingArray['countryId'], - 'shippingcountry' => $shippingArray['countryId'] + 'shipping' => $shippingArray ], true ); From 451297c3b6714ee2f4d4f0acf451dd7b40e9b5bd Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 13:40:32 +0100 Subject: [PATCH 54/68] Revert "[refactor] (PLENTY-80) NGW-IVsec: debug remove country comparison." This reverts commit a4bddf33 --- src/Services/PaymentService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index f53e6d9..f6c3223 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -276,7 +276,9 @@ public function getPaymentMethodContent( 'payment.addressesShouldMatch', __METHOD__, ['billing' => $billingArray, - 'shipping' => $shippingArray + 'shipping' => $shippingArray, + 'billingcountry' => $billingArray['countryId'], + 'shippingcountry' => $shippingArray['countryId'] ], true ); From 8bf0473a0549b00e0488104657bca3a9d2c64b57 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 13:41:01 +0100 Subject: [PATCH 55/68] Revert "[refactor] (PLENTY-80) NGW-IVsec: debug remove country comparison." This reverts commit a4bddf33 --- src/Services/PaymentService.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index f6c3223..cfd93cb 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,15 +270,12 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - $billingArray = $this->basketService->getCustomerAddressData()['billing']->toArray(); - $shippingArray = $this->basketService->getCustomerAddressData()['shipping']->toArray(); $this->notification->error( 'payment.addressesShouldMatch', __METHOD__, - ['billing' => $billingArray, - 'shipping' => $shippingArray, - 'billingcountry' => $billingArray['countryId'], - 'shippingcountry' => $shippingArray['countryId'] + [ + 'billing' => $this->basketService->getCustomerAddressData()['billing']->toArray(), + 'shipping' => $this->basketService->getCustomerAddressData()['shipping']->toArray() ], true ); From 4ec56ab6ba780faf6df712329231b126aa0c08f2 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 13:57:21 +0100 Subject: [PATCH 56/68] [refactor] (PLENTY-80) NGW-IVsec: debug change error message. --- src/Services/PaymentService.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index cfd93cb..7f3623d 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,16 +270,7 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - $this->notification->error( - 'payment.addressesShouldMatch', - __METHOD__, - [ - 'billing' => $this->basketService->getCustomerAddressData()['billing']->toArray(), - 'shipping' => $this->basketService->getCustomerAddressData()['shipping']->toArray() - ], - true - ); - return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; + return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'payment.addressesShouldMatch']; } $type = $methodInstance->getReturnType(); From 706ec1889f66694371ffa23aba29723fb578bd0e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 14:37:25 +0100 Subject: [PATCH 57/68] [feature] (PLENTY-80) NGW-IVsec: Show client error message when addresses do not match. --- src/Services/PaymentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 7f3623d..9348d0a 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,7 +270,7 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'payment.addressesShouldMatch']; + return [GetPaymentMethodContent::RETURN_TYPE_ERROR, $clientErrorMessage]; } $type = $methodInstance->getReturnType(); From 8e7730175dffdee1a74b4f6f91ad3d995a8ed252 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 14:44:19 +0100 Subject: [PATCH 58/68] [feature] (PLENTY-80) NGW-IVsec: Show client error message when addresses do not match. --- src/Services/PaymentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 9348d0a..a7d9763 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -270,7 +270,7 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - return [GetPaymentMethodContent::RETURN_TYPE_ERROR, $clientErrorMessage]; + return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; } $type = $methodInstance->getReturnType(); From 3a3c3734ef37588f5eaa5f18097dc698892b3daf Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 15:07:56 +0100 Subject: [PATCH 59/68] [feature] (PLENTY-80) NGW-IVsec: Add information on invoice pdf-generation to the user guides. --- meta/documents/user_guide_de.md | 6 ++++-- meta/documents/user_guide_en.md | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/meta/documents/user_guide_de.md b/meta/documents/user_guide_de.md index bc3a181..1558f63 100755 --- a/meta/documents/user_guide_de.md +++ b/meta/documents/user_guide_de.md @@ -113,6 +113,7 @@ Um diese Informationen auf der Buchungsbestätigungs-Seite darzustellen folgen S 3. klappen Sie das Menü *Invoice Details (Heidelpay)* auf 4. aktivieren sie den Ceres-Container ``Order confirmation: Additional payment information`` 5. klicken Sie den speichern Button + ![Container-Verknüpfung](../images/preview_4.png) ## Beschreibung der Zahlungsabläufe @@ -134,10 +135,11 @@ Wenn die Zahlung erfolgreich ist, wird die Bestellung im Backend direkt als beza Wenn die Zahlung fehlschlägt, wird die Bestellung nicht erzeugt und der Kunde wird wieder auf die Checkout-Seite des Shops geleitet. ### Gesicherter Rechnungskauf B2C -Um die Sicherung zu aktivieren müssen Sie im hIP eine Finalisierung (FIN) ausführen.\ +* Um die Sicherung zu aktivieren müssen Sie im hIP eine Finalisierung (FIN) ausführen.\ Ab diesem Zeitpunkt startet der vertraglich festgelegte Versicherungzeitraum innerhalb dessen die Zahlung durch den Kunden erwartet wird.\ -Wenn der Kunde die Überweisung tätigt erscheint diese im hIP als Receipt (REC) und wird an die Push-URL ihres Shops gesendet.\ +* Wenn der Kunde die Überweisung tätigt erscheint diese im hIP als Receipt (REC) und wird an die Push-URL ihres Shops gesendet.\ Hier wird daraufhin eine Zahlung angelegt und mit der Buchung verknüpft. +* Die Überweisungsinformationen werden automatisch beim Erstellen auf die PDF-Rechnung gedruckt. ### Alle Zahlarten * Zahlungen im Plenty-Backend enthalten die txnId (heidelpay Bestellnummer), die shortId (die eindeutige id der Transaktion d. h. Receipt, Debit oder Capture) und den Hinweis, dass es sich um eine durch heidelpay angelegte Zahlung handelt. diff --git a/meta/documents/user_guide_en.md b/meta/documents/user_guide_en.md index 245b6f1..0d6f58e 100755 --- a/meta/documents/user_guide_en.md +++ b/meta/documents/user_guide_en.md @@ -113,6 +113,7 @@ To show the information on your order confirmation page please follow these step 3. open the menu *Invoice Details (Heidelpay)* 4. enable the ceres container ``Order confirmation: Additional payment information`` 5. click the save button + ![Container links](../images/preview_4.png) ## Workflow description @@ -136,11 +137,12 @@ If the payment is successful, the order is immediately marked paid in your backe If the payment fails, the order is not created and the customer will be redirected to the checkout page. ### Invoice secured B2C -In order to start the insurance of a Payment you need to trigger a finalize transaction (FIN) from the hIP.\ +* In order to start the insurance of a Payment you need to trigger a finalize transaction (FIN) from the hIP.\ This starts the insurance period in which the customer has to transfert the total amount of the order.\ -This period is determined within your contract with heidelpay.\ -As soon as the customer transferred the total amount a receipt transaction (REC) appears within the hIP and is sent to the pushUrl of your shop.\ +* This period is determined within your contract with heidelpay.\ +As soon as the customer transferred the total amount a receipt transaction (REC) appears within the hIP and is sent to the pushUrl of your shop. The shop module will then create a new payment and link it to the corresponding order. +* The bank information for the customer will be written on the invoice pdf automatically on creation. ### All payment methods * Payments contain the txnId (which is the heidelpay orderId), the shortId (the id of the transaction which lead to the payment i.e. Receipt, Debit or Capture) and the origin (i.e. heidelpay). From ef48ae9c3899a3809921c86b379bfceefd552834 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 18 Mar 2019 15:27:10 +0100 Subject: [PATCH 60/68] [feature] (PLENTY-80) NGW-IVsec: Fix error generating the invoice pdf. --- src/Providers/HeidelpayServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Providers/HeidelpayServiceProvider.php b/src/Providers/HeidelpayServiceProvider.php index 5d9b3a1..35f7bbb 100755 --- a/src/Providers/HeidelpayServiceProvider.php +++ b/src/Providers/HeidelpayServiceProvider.php @@ -139,10 +139,10 @@ function (OrderPdfGenerationEvent $event) use ( /** @var Order $order */ $order = $event->getOrder(); $docType = $event->getDocType(); - $mop = $order->methodOfPaymentId; + $mopId = $order->methodOfPaymentId; /** @var AbstractMethod $paymentMethod */ - $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mop); + $paymentMethod = $paymentHelper->getPaymentMethodInstanceByMopId($mopId); if ($docType !== Document::INVOICE) { return; From 5ba055e85d7124e79fbef80c0937638a1e0b8e4c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 08:35:49 +0100 Subject: [PATCH 61/68] [feature] (PLENTY-80) NGW-IVsec: Translate errorCode message. --- src/Services/PaymentService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index a7d9763..a1a6bf8 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -259,7 +259,7 @@ public function getPaymentMethodContent( ): array { $value = ''; - $clientErrorMessage = 'Heidelpay::payment.errorInternalErrorTryAgainLater'; + $clientErrorMessage = $this->translator->trans('Heidelpay::payment.errorInternalErrorTryAgainLater'); /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); @@ -270,7 +270,9 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; + $value = $this->translator->trans('Heidelpay::payment.addressesShouldMatch'); + $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; + return [$type, $value]; } $type = $methodInstance->getReturnType(); From 7c95f7a6b10207cae998998bf1c9e7bf62f662f8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:00:24 +0100 Subject: [PATCH 62/68] [feature] (PLENTY-80) NGW-IVsec: Debug: Show notification. --- src/Controllers/ResponseController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index b5222e9..38b8518 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -215,6 +215,7 @@ public function handleSyncRequest( __METHOD__, ['Message' => $e->getMessage()] ); + $this->notification->error('test'); return $this->response->redirectTo('checkout'); } From 64de4bfbbaf81217728e7602054002ccccb45930 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:07:22 +0100 Subject: [PATCH 63/68] [feature] (PLENTY-80) NGW-IVsec: Debug: Show notification. --- src/Services/PaymentService.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index a1a6bf8..68e2201 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -259,7 +259,10 @@ public function getPaymentMethodContent( ): array { $value = ''; + $this->notification->error('test 1'); + $clientErrorMessage = $this->translator->trans('Heidelpay::payment.errorInternalErrorTryAgainLater'); + $this->notification->error('test 2',__METHOD__,['error' => $clientErrorMessage]); /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); @@ -270,8 +273,12 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - $value = $this->translator->trans('Heidelpay::payment.addressesShouldMatch'); $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; + $this->notification->error('test 3'); + + $value = $this->translator->trans('Heidelpay::payment.addressesShouldMatch'); + $this->notification->error('test 4',__METHOD__,['error' => $value]); + return [$type, $value]; } From 04df169a2968f6073b76c6690b367e32049902db Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:15:41 +0100 Subject: [PATCH 64/68] [feature] (PLENTY-80) NGW-IVsec: Debug: Show translation. --- src/Services/PaymentService.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 68e2201..a5f11aa 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -258,11 +258,7 @@ public function getPaymentMethodContent( int $mopId ): array { $value = ''; - - $this->notification->error('test 1'); - - $clientErrorMessage = $this->translator->trans('Heidelpay::payment.errorInternalErrorTryAgainLater'); - $this->notification->error('test 2',__METHOD__,['error' => $clientErrorMessage]); + $clientErrorMessage = $this->notification->getTranslation('Heidelpay::payment.errorInternalErrorTryAgainLater'); /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); @@ -274,11 +270,7 @@ public function getPaymentMethodContent( if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; - $this->notification->error('test 3'); - - $value = $this->translator->trans('Heidelpay::payment.addressesShouldMatch'); - $this->notification->error('test 4',__METHOD__,['error' => $value]); - + $value = $this->notification->getTranslation('Heidelpay::payment.addressesShouldMatch'); return [$type, $value]; } From 9fd0dd786918599137de8edbe9ba9aa80d059588 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:22:37 +0100 Subject: [PATCH 65/68] [revert] (PLENTY-80) NGW-IVsec: Revert notification. --- src/Controllers/ResponseController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 38b8518..b5222e9 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -215,7 +215,6 @@ public function handleSyncRequest( __METHOD__, ['Message' => $e->getMessage()] ); - $this->notification->error('test'); return $this->response->redirectTo('checkout'); } From 4c1f8c471832cd7ffdc6bf58f32ef63c42289de0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:25:51 +0100 Subject: [PATCH 66/68] Revert "[feature] (PLENTY-80) NGW-IVsec: Debug: Show translation." This reverts commit 04df169a --- src/Services/PaymentService.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index a5f11aa..68e2201 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -258,7 +258,11 @@ public function getPaymentMethodContent( int $mopId ): array { $value = ''; - $clientErrorMessage = $this->notification->getTranslation('Heidelpay::payment.errorInternalErrorTryAgainLater'); + + $this->notification->error('test 1'); + + $clientErrorMessage = $this->translator->trans('Heidelpay::payment.errorInternalErrorTryAgainLater'); + $this->notification->error('test 2',__METHOD__,['error' => $clientErrorMessage]); /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); @@ -270,7 +274,11 @@ public function getPaymentMethodContent( if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; - $value = $this->notification->getTranslation('Heidelpay::payment.addressesShouldMatch'); + $this->notification->error('test 3'); + + $value = $this->translator->trans('Heidelpay::payment.addressesShouldMatch'); + $this->notification->error('test 4',__METHOD__,['error' => $value]); + return [$type, $value]; } From 80eff2d4d64e4fca1d29f121b28396850840f296 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:32:40 +0100 Subject: [PATCH 67/68] Revert "[feature] (PLENTY-80) NGW-IVsec: Translate errorCode message." This reverts commit 5ba055e8 --- src/Services/PaymentService.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 68e2201..a7d9763 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -259,10 +259,7 @@ public function getPaymentMethodContent( ): array { $value = ''; - $this->notification->error('test 1'); - - $clientErrorMessage = $this->translator->trans('Heidelpay::payment.errorInternalErrorTryAgainLater'); - $this->notification->error('test 2',__METHOD__,['error' => $clientErrorMessage]); + $clientErrorMessage = 'Heidelpay::payment.errorInternalErrorTryAgainLater'; /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); @@ -273,13 +270,7 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - $type = GetPaymentMethodContent::RETURN_TYPE_ERROR; - $this->notification->error('test 3'); - - $value = $this->translator->trans('Heidelpay::payment.addressesShouldMatch'); - $this->notification->error('test 4',__METHOD__,['error' => $value]); - - return [$type, $value]; + return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; } $type = $methodInstance->getReturnType(); From b710c9c0c59f1a94ba9c05e1890186a8ea9e8e7d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 19 Mar 2019 09:39:22 +0100 Subject: [PATCH 68/68] [change] (PLENTY-80) NGW-IVsec: Add error message translation. --- src/Services/PaymentService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index a7d9763..4d2787d 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -259,7 +259,7 @@ public function getPaymentMethodContent( ): array { $value = ''; - $clientErrorMessage = 'Heidelpay::payment.errorInternalErrorTryAgainLater'; + $clientErrorMessage = $this->notification->getTranslation('Heidelpay::payment.errorInternalErrorTryAgainLater'); /** @var AbstractMethod $methodInstance */ $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); @@ -270,7 +270,8 @@ public function getPaymentMethodContent( } if ($methodInstance->needsMatchingAddresses() && !$this->basketService->shippingMatchesBillingAddress()) { - return [GetPaymentMethodContent::RETURN_TYPE_ERROR, 'Heidelpay::payment.addressesShouldMatch']; + $value = $this->notification->getTranslation('Heidelpay::payment.addressesShouldMatch'); + return [GetPaymentMethodContent::RETURN_TYPE_ERROR, $value]; } $type = $methodInstance->getReturnType();