From ef6773659079aa0c56c6300d85c2e4832fefb33d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 5 Mar 2019 17:38:11 +0100 Subject: [PATCH 01/70] [feature] (PLENTY-88) NGW-IVsec: Debug log address and basket. --- src/Controllers/ResponseController.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 1237c65..299d58f 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -10,10 +10,12 @@ use Heidelpay\Services\PaymentService; use Heidelpay\Services\UrlServiceContract; use Heidelpay\Traits\Translator; +use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; use Plenty\Plugin\Http\Response; +use Symfony\Component\HttpFoundation\Response as BaseResponse; /** * Processes the transaction/payment responses coming from the heidelpay payment system. @@ -178,9 +180,9 @@ public function processPush(): Response * the heidelpay API redirects to the processAsyncResponse url using GET instead of POST. * This method is for handling this behaviour. * - * @return \Symfony\Component\HttpFoundation\Response + * @return BaseResponse */ - public function emergencyRedirect(): \Symfony\Component\HttpFoundation\Response + public function emergencyRedirect(): BaseResponse { $this->notification->warning('response.warningResponseCalledInInvalidContext', __METHOD__); return $this->response->redirectTo('checkout'); @@ -190,12 +192,18 @@ public function emergencyRedirect(): \Symfony\Component\HttpFoundation\Response * Handles form requests which do not need any further action by the client. * * @param BasketRepositoryContract $basketRepo - * @return \Symfony\Component\HttpFoundation\Response + * @param AddressRepositoryContract $addressRepo + * @return BaseResponse */ - public function handleSyncRequest(BasketRepositoryContract $basketRepo): \Symfony\Component\HttpFoundation\Response - { + public function handleSyncRequest( + BasketRepositoryContract $basketRepo, + AddressRepositoryContract $addressRepo + ): BaseResponse { $basket = $basketRepo->load(); - $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, ['basket' => $basket]); + + $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); + + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, ['basket' => $basket, 'invoice address' => $invoiceAddress]); return $this->response->redirectTo('place-order'); } From 900a98e8ee77db9079d733175875d60fb0e0a333 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 5 Mar 2019 17:39:28 +0100 Subject: [PATCH 02/70] [feature] (PLENTY-88) NGW-IVsec: Enable sync requests to payment api. --- src/Methods/AbstractMethod.php | 12 ++++++++++++ src/Methods/InvoiceSecuredB2C.php | 1 + src/Methods/PaymentMethodContract.php | 8 ++++++++ src/Services/PaymentService.php | 10 +++++----- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index 30d351f..e2b01a3 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -31,6 +31,7 @@ abstract class AbstractMethod extends PaymentMethodService implements PaymentMet const RETURN_TYPE = GetPaymentMethodContent::RETURN_TYPE_REDIRECT_URL; const INITIALIZE_PAYMENT = true; const FORM_TEMPLATE = ''; + const NEEDS_CUSTOMER_INPUT = true; /** * @var PaymentHelper $helper @@ -244,4 +245,15 @@ public function getFormTemplate(): string { return static::FORM_TEMPLATE; } + + /** + * Returns true if the customer has to be redirected to enter additional information (e.g. 3D-secure, sofort, etc.). + * This determines whether a synchronous or asynchronous request is performed. + * + * @return bool + */ + public function needsCustomerInput(): bool + { + return static::NEEDS_CUSTOMER_INPUT; + } } diff --git a/src/Methods/InvoiceSecuredB2C.php b/src/Methods/InvoiceSecuredB2C.php index 36d5c88..75855be 100755 --- a/src/Methods/InvoiceSecuredB2C.php +++ b/src/Methods/InvoiceSecuredB2C.php @@ -23,4 +23,5 @@ class InvoiceSecuredB2C extends AbstractMethod const RETURN_TYPE = GetPaymentMethodContent::RETURN_TYPE_HTML; const INITIALIZE_PAYMENT = false; const FORM_TEMPLATE = 'Heidelpay::invoiceSecuredB2CForm'; + const NEEDS_CUSTOMER_INPUT = false; } diff --git a/src/Methods/PaymentMethodContract.php b/src/Methods/PaymentMethodContract.php index 6f424c6..c38ab67 100755 --- a/src/Methods/PaymentMethodContract.php +++ b/src/Methods/PaymentMethodContract.php @@ -122,4 +122,12 @@ public function hasToBeInitialized(): bool; * @return string */ public function getFormTemplate(): string; + + /** + * Returns true if the customer has to be redirected to enter additional information (e.g. 3D-secure, sofort, etc.). + * This determines whether a synchronous or asynchronous request is performed. + * + * @return bool + */ + public function needsCustomerInput(): bool; } diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index dc36cc8..9b3d0a2 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -326,6 +326,9 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI /** @var SecretService $secretService */ $secretService = pluginApp(SecretService::class); + /** @var PaymentMethodContract $methodInstance */ + $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); + // set authentication data $heidelpayAuth = $this->paymentHelper->getHeidelpayAuthenticationConfig($paymentMethod); $this->heidelpayRequest = array_merge($this->heidelpayRequest, $heidelpayAuth); @@ -361,7 +364,7 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest['PRESENTATION_AMOUNT'] = $basketArray['basketAmount']; $this->heidelpayRequest['PRESENTATION_CURRENCY'] = $basketArray['currency']; - $this->heidelpayRequest['FRONTEND_ENABLED'] = 'TRUE'; + $this->heidelpayRequest['FRONTEND_ENABLED'] = $methodInstance->needsCustomerInput() ? 'TRUE' : 'FALSE'; $this->heidelpayRequest['FRONTEND_LANGUAGE'] = $this->sessionStorageFactory->getLocaleSettings()->language; $this->heidelpayRequest['FRONTEND_RESPONSE_URL'] = $this->urlService->generateURL(Routes::RESPONSE_URL); @@ -397,10 +400,7 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI } // general - $methodInstance = $this->paymentHelper->getPaymentMethodInstance($paymentMethod); - if (null !== $methodInstance) { - $this->heidelpayRequest['FRONTEND_CSS_PATH'] = $this->methodConfig->getIFrameCssPath($methodInstance); - } + $this->heidelpayRequest['FRONTEND_CSS_PATH'] = $this->methodConfig->getIFrameCssPath($methodInstance); } // From 8e9658833aefbbd0aef1bc5665c72a173ba2c5ac Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 11:46:24 +0100 Subject: [PATCH 03/70] [feature] (PLENTY-88) NGW-IVsec: Debug form data. --- src/Controllers/ResponseController.php | 16 +++++++++++++--- src/Providers/HeidelpayRouteServiceProvider.php | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 299d58f..55cdb34 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -201,9 +201,19 @@ public function handleSyncRequest( ): BaseResponse { $basket = $basketRepo->load(); - $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); - - $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, ['basket' => $basket, 'invoice address' => $invoiceAddress]); + $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); + $invoiceAddressArray = $invoiceAddress->toArray(); +// $invoiceAddressArray[''] = +// $invoiceAddressAfter = $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress['id']); + + + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, + [ + 'basket' => $basket, + 'invoice address' => $invoiceAddress, + 'invoice address array' => $invoiceAddressArray, + 'post data' => $this->request->all()] + ); return $this->response->redirectTo('place-order'); } diff --git a/src/Providers/HeidelpayRouteServiceProvider.php b/src/Providers/HeidelpayRouteServiceProvider.php index 5ffd3b6..41e7f65 100755 --- a/src/Providers/HeidelpayRouteServiceProvider.php +++ b/src/Providers/HeidelpayRouteServiceProvider.php @@ -32,7 +32,6 @@ public function map(Router $router) $router->get(Routes::RESPONSE_URL, 'Heidelpay\Controllers\ResponseController@emergencyRedirect'); $router->post(Routes::RESPONSE_URL, 'Heidelpay\Controllers\ResponseController@processAsyncResponse'); $router->post(Routes::PUSH_NOTIFICATION_URL, 'Heidelpay\Controllers\ResponseController@processPush'); - $router->get(Routes::HANDLE_FORM_URL, 'Heidelpay\Controllers\ResponseController@emergencyRedirect'); $router->post(Routes::HANDLE_FORM_URL, 'Heidelpay\Controllers\ResponseController@handleSyncRequest'); // redirects in success or cancellation/failure cases From a091b6cc777f3c830bee817d12fe08c4965b7251 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 11:51:41 +0100 Subject: [PATCH 04/70] [feature] (PLENTY-88) NGW-IVsec: Debug alter invoice address data. --- src/Controllers/ResponseController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 55cdb34..427df87 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -203,16 +203,19 @@ public function handleSyncRequest( $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); $invoiceAddressArray = $invoiceAddress->toArray(); -// $invoiceAddressArray[''] = -// $invoiceAddressAfter = $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress['id']); + $invoiceAddressArray['gender'] = 'female'; + $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress['id']); + $invoiceAddressAfter = $addressRepo->findAddressById($basket->customerInvoiceAddressId); $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, [ 'basket' => $basket, 'invoice address' => $invoiceAddress, + 'invoice address after' => $invoiceAddressAfter, 'invoice address array' => $invoiceAddressArray, - 'post data' => $this->request->all()] + 'post data' => $this->request->all() + ] ); return $this->response->redirectTo('place-order'); From 04753002a59c71eed39925bddd71e22ea7fe261d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 12:09:51 +0100 Subject: [PATCH 05/70] [feature] (PLENTY-88) NGW-IVsec: Debug alter invoice address data. --- src/Controllers/ResponseController.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 427df87..4e6c6f5 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -11,6 +11,7 @@ use Heidelpay\Services\UrlServiceContract; use Heidelpay\Traits\Translator; use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; +use Plenty\Modules\Account\Address\Models\Address; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; @@ -201,19 +202,14 @@ public function handleSyncRequest( ): BaseResponse { $basket = $basketRepo->load(); - $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); - $invoiceAddressArray = $invoiceAddress->toArray(); - $invoiceAddressArray['gender'] = 'female'; - $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress['id']); - $invoiceAddressAfter = $addressRepo->findAddressById($basket->customerInvoiceAddressId); - + $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); + $invoiceAddressAfter = $addressRepo->updateAddress(['gender' => 'female'], $invoiceAddress->id); $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, [ 'basket' => $basket, 'invoice address' => $invoiceAddress, 'invoice address after' => $invoiceAddressAfter, - 'invoice address array' => $invoiceAddressArray, 'post data' => $this->request->all() ] ); From d653f2283c6f51ff07c1499297495cfec33263e8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 12:31:25 +0100 Subject: [PATCH 06/70] [feature] (PLENTY-88) NGW-IVsec: Debug alter invoice address data. --- src/Controllers/ResponseController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 4e6c6f5..c7ff605 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -11,7 +11,6 @@ use Heidelpay\Services\UrlServiceContract; use Heidelpay\Traits\Translator; use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; -use Plenty\Modules\Account\Address\Models\Address; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; @@ -203,7 +202,9 @@ public function handleSyncRequest( $basket = $basketRepo->load(); $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); - $invoiceAddressAfter = $addressRepo->updateAddress(['gender' => 'female'], $invoiceAddress->id); + $invoiceAddressArray = $invoiceAddress->toArray(); + $invoiceAddressArray['gender'] = 'female'; + $invoiceAddressAfter = $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress->id); $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, [ From 93390a63bb0f5993e22a94b5912032731ddbda35 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 13:12:44 +0100 Subject: [PATCH 07/70] [feature] (PLENTY-88) NGW-IVsec: Debug alter invoice address data. --- resources/views/invoiceSecuredB2CForm.twig | 8 ++++---- src/Controllers/ResponseController.php | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/resources/views/invoiceSecuredB2CForm.twig b/resources/views/invoiceSecuredB2CForm.twig index d61e86c..1280c4c 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -8,7 +8,7 @@
- @@ -23,7 +23,7 @@
- @@ -41,7 +41,7 @@
- @@ -52,7 +52,7 @@
- {% set minYear = "now -80 years"|date("Y") %} {% set maxYear = "now -18 years"|date("Y") %} diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index c7ff605..5faf033 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -5,13 +5,16 @@ use Heidelpay\Constants\Routes; use Heidelpay\Exceptions\SecurityHashInvalidException; use Heidelpay\Models\Transaction; +use Heidelpay\PhpPaymentApi\PushMapping\Contact; use Heidelpay\Services\Database\TransactionService; use Heidelpay\Services\NotificationServiceContract; use Heidelpay\Services\PaymentService; use Heidelpay\Services\UrlServiceContract; use Heidelpay\Traits\Translator; use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; +use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; +use Plenty\Modules\CustomerContract\Contracts\CustomerContractRepositoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; use Plenty\Plugin\Http\Response; @@ -193,11 +196,13 @@ public function emergencyRedirect(): BaseResponse * * @param BasketRepositoryContract $basketRepo * @param AddressRepositoryContract $addressRepo + * @param ContactRepositoryContract $contactRepo * @return BaseResponse */ public function handleSyncRequest( BasketRepositoryContract $basketRepo, - AddressRepositoryContract $addressRepo + AddressRepositoryContract $addressRepo, + ContactRepositoryContract $contactRepo ): BaseResponse { $basket = $basketRepo->load(); @@ -206,12 +211,21 @@ public function handleSyncRequest( $invoiceAddressArray['gender'] = 'female'; $invoiceAddressAfter = $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress->id); +// $customer = $customerContractRepo->get($basket->customerId); + + $contact = $contactRepo->findContactById($basket->customerId); + $contactArray = $contact->toArray(); + $contactArray['birthdayAt'] = strtotime('1982-11-25'); + $contactAfter = $contactRepo->updateContact($contactArray, $basket->customerId); + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, [ 'basket' => $basket, 'invoice address' => $invoiceAddress, 'invoice address after' => $invoiceAddressAfter, - 'post data' => $this->request->all() + 'post data' => $this->request->all(), + 'contact' => $contact, + 'contact after' => $contactAfter ] ); From 9a3c60f5a2c72d42f3f076cb7e3174c360875e47 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 15:36:34 +0100 Subject: [PATCH 08/70] [feature] (PLENTY-88) NGW-IVsec: Update customer data with provided data from form. --- src/Controllers/ResponseController.php | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 5faf033..1c95635 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -5,7 +5,6 @@ use Heidelpay\Constants\Routes; use Heidelpay\Exceptions\SecurityHashInvalidException; use Heidelpay\Models\Transaction; -use Heidelpay\PhpPaymentApi\PushMapping\Contact; use Heidelpay\Services\Database\TransactionService; use Heidelpay\Services\NotificationServiceContract; use Heidelpay\Services\PaymentService; @@ -14,7 +13,6 @@ use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; -use Plenty\Modules\CustomerContract\Contracts\CustomerContractRepositoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; use Plenty\Plugin\Http\Response; @@ -204,31 +202,34 @@ public function handleSyncRequest( AddressRepositoryContract $addressRepo, ContactRepositoryContract $contactRepo ): BaseResponse { - $basket = $basketRepo->load(); - $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId); - $invoiceAddressArray = $invoiceAddress->toArray(); - $invoiceAddressArray['gender'] = 'female'; - $invoiceAddressAfter = $addressRepo->updateAddress($invoiceAddressArray, $invoiceAddress->id); + if (!$this->request->exists('customer_salutation') || !$this->request->exists('customer_dob_day') || + !$this->request->exists('customer_dob_month') || !$this->request->exists('customer_dob_year')) + { + $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__); + return $this->response->redirectTo('checkout'); + } + + $salutation = $this->request->get('customer_salutation'); + $dateOfBirth = implode('-', + [ + $this->request->get('customer_dob_year'), + $this->request->get('customer_dob_month'), + $this->request->get('customer_dob_day') + ]); -// $customer = $customerContractRepo->get($basket->customerId); + $basket = $basketRepo->load(); + $customerId = $basket->customerId; - $contact = $contactRepo->findContactById($basket->customerId); - $contactArray = $contact->toArray(); - $contactArray['birthdayAt'] = strtotime('1982-11-25'); - $contactAfter = $contactRepo->updateContact($contactArray, $basket->customerId); + $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId)->toArray(); + $invoiceAddress['gender'] = $salutation === 'mrs' ? 'female' : 'male'; + $addressRepo->updateAddress($invoiceAddress, $invoiceAddress['id']); - $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, - [ - 'basket' => $basket, - 'invoice address' => $invoiceAddress, - 'invoice address after' => $invoiceAddressAfter, - 'post data' => $this->request->all(), - 'contact' => $contact, - 'contact after' => $contactAfter - ] - ); + $contact = $contactRepo->findContactById($customerId)->toArray(); + $contact['birthdayAt'] = strtotime($dateOfBirth); + $contactRepo->updateContact($contact, $customerId); + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__); return $this->response->redirectTo('place-order'); } // From 008234906cc7f60b212680bcea5e6b0669cdbdb0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 15:53:11 +0100 Subject: [PATCH 09/70] [feature] (PLENTY-88) NGW-IVsec: Debug get additional information in form request. Where can i find the mop? --- src/Controllers/ResponseController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 1c95635..a3894b5 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -13,6 +13,7 @@ use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; +use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; use Plenty\Plugin\Http\Response; @@ -195,12 +196,14 @@ public function emergencyRedirect(): BaseResponse * @param BasketRepositoryContract $basketRepo * @param AddressRepositoryContract $addressRepo * @param ContactRepositoryContract $contactRepo + * @param FrontendSessionStorageFactoryContract $frontendSessionStorage * @return BaseResponse */ public function handleSyncRequest( BasketRepositoryContract $basketRepo, AddressRepositoryContract $addressRepo, - ContactRepositoryContract $contactRepo + ContactRepositoryContract $contactRepo, + FrontendSessionStorageFactoryContract $frontendSessionStorage ): BaseResponse { if (!$this->request->exists('customer_salutation') || !$this->request->exists('customer_dob_day') || @@ -229,7 +232,14 @@ public function handleSyncRequest( $contact['birthdayAt'] = strtotime($dateOfBirth); $contactRepo->updateContact($contact, $customerId); - $this->notification->success('payment.infoPaymentSuccessful', __METHOD__); + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, [ + $basket, + $frontendSessionStorage->getOrder(), + $frontendSessionStorage->getCustomer(), + $frontendSessionStorage->getForum(), + $frontendSessionStorage->getLocaleSettings(), + $frontendSessionStorage->getPlugin() + ]); return $this->response->redirectTo('place-order'); } // From 9f84a548a8705083431cf493672d7ca9daa83799 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 16:44:58 +0100 Subject: [PATCH 10/70] [feature] (PLENTY-88) NGW-IVsec: Perform sync request. --- src/Controllers/ResponseController.php | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index a3894b5..be53584 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -4,6 +4,8 @@ use Heidelpay\Constants\Routes; use Heidelpay\Exceptions\SecurityHashInvalidException; +use Heidelpay\Helper\PaymentHelper; +use Heidelpay\Methods\PaymentMethodContract; use Heidelpay\Models\Transaction; use Heidelpay\Services\Database\TransactionService; use Heidelpay\Services\NotificationServiceContract; @@ -13,7 +15,6 @@ use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; -use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; use Plenty\Plugin\Http\Response; @@ -196,14 +197,15 @@ public function emergencyRedirect(): BaseResponse * @param BasketRepositoryContract $basketRepo * @param AddressRepositoryContract $addressRepo * @param ContactRepositoryContract $contactRepo - * @param FrontendSessionStorageFactoryContract $frontendSessionStorage + * @param PaymentHelper $paymentHelper * @return BaseResponse + * @throws \RuntimeException */ public function handleSyncRequest( BasketRepositoryContract $basketRepo, AddressRepositoryContract $addressRepo, ContactRepositoryContract $contactRepo, - FrontendSessionStorageFactoryContract $frontendSessionStorage + PaymentHelper $paymentHelper ): BaseResponse { if (!$this->request->exists('customer_salutation') || !$this->request->exists('customer_dob_day') || @@ -232,14 +234,22 @@ public function handleSyncRequest( $contact['birthdayAt'] = strtotime($dateOfBirth); $contactRepo->updateContact($contact, $customerId); - $this->notification->success('payment.infoPaymentSuccessful', __METHOD__, [ + $mopId = $basket->methodOfPaymentId; + $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mopId); + $methodInstance = $paymentHelper->getPaymentMethodInstanceByMopId($mopId); + if (!$methodInstance instanceof PaymentMethodContract) { + $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__); + return $this->response->redirectTo('checkout'); + } + + $this->paymentService->sendPaymentRequest( $basket, - $frontendSessionStorage->getOrder(), - $frontendSessionStorage->getCustomer(), - $frontendSessionStorage->getForum(), - $frontendSessionStorage->getLocaleSettings(), - $frontendSessionStorage->getPlugin() - ]); + $paymentMethod, + $methodInstance->getTransactionType(), + $mopId + ); + + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__); return $this->response->redirectTo('place-order'); } // From 9a312d35821a31172cf9b14feb715f65d9d1194f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 6 Mar 2019 17:03:36 +0100 Subject: [PATCH 11/70] [feature] (PLENTY-88) NGW-IVsec: Add payment transaction type and transaction lib file. --- .../lib/invoiceSecuredTransactionRequest.php | 61 +++++++++++++++++++ src/Methods/InvoiceSecuredB2C.php | 2 + 2 files changed, 63 insertions(+) create mode 100755 resources/lib/invoiceSecuredTransactionRequest.php diff --git a/resources/lib/invoiceSecuredTransactionRequest.php b/resources/lib/invoiceSecuredTransactionRequest.php new file mode 100755 index 0000000..2aecd49 --- /dev/null +++ b/resources/lib/invoiceSecuredTransactionRequest.php @@ -0,0 +1,61 @@ + + * + * @package heidelpay\plentymarkets-gateway\external-lib-callbacks + */ + +use Heidelpay\PhpPaymentApi\Request; + +/** @var array $requestParams */ +$requestParams = SdkRestApi::getParam('request'); +$transactionType = SdkRestApi::getParam('transactionType'); + +$paymentMethod = new \Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod(); +$paymentMethod->setRequest(Request::fromPost($requestParams)); + +$responseArray = null; + +$refId = SdkRestApi::getParam('referenceId') ?: null; +$paymentFrameOrigin = $paymentMethod->getRequest()->getFrontend()->getPaymentFrameOrigin(); +$preventAsyncRedirect = $paymentMethod->getRequest()->getFrontend()->getPreventAsyncRedirect(); +$cssPath = $paymentMethod->getRequest()->getFrontend()->getCssPath(); + +try { + if (!is_callable([$paymentMethod, $transactionType])) { + throw new \Exception('Invalid transaction type for InvoiceB2CSecured payment method (' . $transactionType . ')!'); + } + + if ($refId !== null) { + $response = $paymentMethod->{$transactionType}( + $refId, + $paymentFrameOrigin, + $preventAsyncRedirect, + $cssPath + ); + } else { + $response = $paymentMethod->{$transactionType}($paymentFrameOrigin, $preventAsyncRedirect, $cssPath); + } +} catch (\Exception $e) { + $responseArray = [ + 'exceptionCode' => $e->getCode(), + 'exceptionMsg' => $e->getMessage(), + 'exceptionTrace' => $e->getTraceAsString(), + ]; +} + +// return the responseArray, if an exception has been thrown. +// else, return an array containing response results. +return $responseArray ?? [ + 'response' => $paymentMethod->getResponse()->toArray(), + 'isSuccess' => $paymentMethod->getResponse()->isSuccess(), + 'isPending' => $paymentMethod->getResponse()->isPending(), + 'isError' => $paymentMethod->getResponse()->isError(), +]; diff --git a/src/Methods/InvoiceSecuredB2C.php b/src/Methods/InvoiceSecuredB2C.php index 75855be..e46c24c 100755 --- a/src/Methods/InvoiceSecuredB2C.php +++ b/src/Methods/InvoiceSecuredB2C.php @@ -1,6 +1,7 @@ Date: Wed, 6 Mar 2019 17:23:01 +0100 Subject: [PATCH 12/70] [feature] (PLENTY-88) NGW-IVsec: Fix lib name. --- ...sactionRequest.php => invoiceSecuredB2CTransactionRequest.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename resources/lib/{invoiceSecuredTransactionRequest.php => invoiceSecuredB2CTransactionRequest.php} (100%) diff --git a/resources/lib/invoiceSecuredTransactionRequest.php b/resources/lib/invoiceSecuredB2CTransactionRequest.php similarity index 100% rename from resources/lib/invoiceSecuredTransactionRequest.php rename to resources/lib/invoiceSecuredB2CTransactionRequest.php From 05d2a8738b3de7aa8881581c6bf4b040afcc897f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 08:59:11 +0100 Subject: [PATCH 13/70] [feature] (PLENTY-88) NGW-IVsec: Add NOK handling to sync response. --- src/Controllers/ResponseController.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index be53584..aacc4e2 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -242,13 +242,24 @@ public function handleSyncRequest( return $this->response->redirectTo('checkout'); } - $this->paymentService->sendPaymentRequest( + $response = $this->paymentService->sendPaymentRequest( $basket, $paymentMethod, $methodInstance->getTransactionType(), $mopId ); + if ($response['isError'] === true) { + $errorMsg = ''; + if (isset($response['response']['PROCESSING.REASON'], $response['response']['PROCESSING.RETURN'])) { + $responseObj = $response['response']; + $errorMsg = $responseObj['PROCESSING.REASON'] . ': ' . $responseObj['PROCESSING.RETURN']; + } + + $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__, ['Message' => $errorMsg]); + return $this->response->redirectTo('checkout'); + } + $this->notification->success('payment.infoPaymentSuccessful', __METHOD__); return $this->response->redirectTo('place-order'); } From 238c0e7a9dd125846fb0448b8c087b33d247da28 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 09:13:01 +0100 Subject: [PATCH 14/70] [feature] (PLENTY-88) NGW-IVsec: Sort request and response array by key. --- resources/lib/invoiceSecuredB2CTransactionRequest.php | 11 +++++++---- src/Services/LibService.php | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/lib/invoiceSecuredB2CTransactionRequest.php b/resources/lib/invoiceSecuredB2CTransactionRequest.php index 2aecd49..55c69ee 100755 --- a/resources/lib/invoiceSecuredB2CTransactionRequest.php +++ b/resources/lib/invoiceSecuredB2CTransactionRequest.php @@ -53,9 +53,12 @@ // return the responseArray, if an exception has been thrown. // else, return an array containing response results. +$responseObj = $paymentMethod->getResponse(); +$responseArray = $responseObj->toArray(); +ksort($responseArray); return $responseArray ?? [ - 'response' => $paymentMethod->getResponse()->toArray(), - 'isSuccess' => $paymentMethod->getResponse()->isSuccess(), - 'isPending' => $paymentMethod->getResponse()->isPending(), - 'isError' => $paymentMethod->getResponse()->isError(), + 'response' => $responseArray, + 'isSuccess' => $responseObj->isSuccess(), + 'isPending' => $responseObj->isPending(), + 'isError' => $responseObj->isError(), ]; diff --git a/src/Services/LibService.php b/src/Services/LibService.php index 3bb0966..ae49016 100755 --- a/src/Services/LibService.php +++ b/src/Services/LibService.php @@ -61,6 +61,7 @@ private function executeLibCall($libCall, array $params, $pluginName = Plugin::N { $libName = $pluginName . '::' . $libCall; $result = $this->libCall->call($libName, $params); + ksort($params); $logData = ['LibCall' => $libName, 'Parameters' => $params, 'Result' => $result]; $this->notification->debug('request.debugLibCallResult', __METHOD__, $logData); From 1bf7782415c2353971fb4230040be81996acb5ff Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 10:24:38 +0100 Subject: [PATCH 15/70] [feature] (PLENTY-88) NGW-IVsec: Sort request and response array by key. --- resources/lib/invoiceSecuredB2CTransactionRequest.php | 4 ++-- src/Services/LibService.php | 1 - src/Services/PaymentService.php | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/lib/invoiceSecuredB2CTransactionRequest.php b/resources/lib/invoiceSecuredB2CTransactionRequest.php index 55c69ee..aa18467 100755 --- a/resources/lib/invoiceSecuredB2CTransactionRequest.php +++ b/resources/lib/invoiceSecuredB2CTransactionRequest.php @@ -44,7 +44,7 @@ $response = $paymentMethod->{$transactionType}($paymentFrameOrigin, $preventAsyncRedirect, $cssPath); } } catch (\Exception $e) { - $responseArray = [ + $errorResponse = [ 'exceptionCode' => $e->getCode(), 'exceptionMsg' => $e->getMessage(), 'exceptionTrace' => $e->getTraceAsString(), @@ -56,7 +56,7 @@ $responseObj = $paymentMethod->getResponse(); $responseArray = $responseObj->toArray(); ksort($responseArray); -return $responseArray ?? [ +return $errorResponse ?? [ 'response' => $responseArray, 'isSuccess' => $responseObj->isSuccess(), 'isPending' => $responseObj->isPending(), diff --git a/src/Services/LibService.php b/src/Services/LibService.php index ae49016..3bb0966 100755 --- a/src/Services/LibService.php +++ b/src/Services/LibService.php @@ -61,7 +61,6 @@ private function executeLibCall($libCall, array $params, $pluginName = Plugin::N { $libName = $pluginName . '::' . $libCall; $result = $this->libCall->call($libName, $params); - ksort($params); $logData = ['LibCall' => $libName, 'Parameters' => $params, 'Result' => $result]; $this->notification->debug('request.debugLibCallResult', __METHOD__, $logData); diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 9b3d0a2..8c5688c 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -401,6 +401,8 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI // general $this->heidelpayRequest['FRONTEND_CSS_PATH'] = $this->methodConfig->getIFrameCssPath($methodInstance); + + ksort($this->heidelpayRequest); } // From 209b0c79f5c47ce6c1dfe21883c8a9ed0f352cc3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 10:55:29 +0100 Subject: [PATCH 16/70] [feature] (PLENTY-88) NGW-IVsec: Debug add additional output. --- src/Controllers/ResponseController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index aacc4e2..477bc15 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -208,6 +208,8 @@ public function handleSyncRequest( PaymentHelper $paymentHelper ): BaseResponse { + $this->notification->error('number 1', __METHOD__); + if (!$this->request->exists('customer_salutation') || !$this->request->exists('customer_dob_day') || !$this->request->exists('customer_dob_month') || !$this->request->exists('customer_dob_year')) { @@ -215,6 +217,8 @@ public function handleSyncRequest( return $this->response->redirectTo('checkout'); } + $this->notification->error('number 2', __METHOD__); + $salutation = $this->request->get('customer_salutation'); $dateOfBirth = implode('-', [ @@ -230,10 +234,14 @@ public function handleSyncRequest( $invoiceAddress['gender'] = $salutation === 'mrs' ? 'female' : 'male'; $addressRepo->updateAddress($invoiceAddress, $invoiceAddress['id']); + $this->notification->error('number 3', __METHOD__); + $contact = $contactRepo->findContactById($customerId)->toArray(); $contact['birthdayAt'] = strtotime($dateOfBirth); $contactRepo->updateContact($contact, $customerId); + $this->notification->error('number 4', __METHOD__); + $mopId = $basket->methodOfPaymentId; $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mopId); $methodInstance = $paymentHelper->getPaymentMethodInstanceByMopId($mopId); @@ -242,6 +250,9 @@ public function handleSyncRequest( return $this->response->redirectTo('checkout'); } + + $this->notification->error('number 5', __METHOD__); + $response = $this->paymentService->sendPaymentRequest( $basket, $paymentMethod, From c6dbd8ba3e746bfacbcd1050f89729ee36bba722 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 12:30:13 +0100 Subject: [PATCH 17/70] [feature] (PLENTY-88) NGW-IVsec: Add salutation, birthday and basket to sync request. --- src/Controllers/ResponseController.php | 87 +++++++++++++++++--------- src/Methods/AbstractMethod.php | 9 +++ src/Methods/InvoiceSecuredB2C.php | 1 + src/Methods/PaymentMethodContract.php | 7 +++ src/Services/PaymentService.php | 23 +++++-- 5 files changed, 91 insertions(+), 36 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 477bc15..81d3d1b 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -75,6 +75,7 @@ public function __construct( $this->urlService = $urlService; } + // /** * Creates a transaction object and returns bool to indicate success. * @@ -111,6 +112,58 @@ private function createAndHandleTransaction($response, $responseObject): bool return true; } + + + /** + * Returns the salutation from the post request. + * + * @return string + * @throws \RuntimeException + */ + private function getSalutation(): string + { + if ($this->request->exists('customer_salutation')) { + switch ($this->request->get('customer_salutation')) { + case 'mr': + return 'male'; + break; + case 'mrs': + return 'female'; + break; + default: + // do nothing, an exception will be thrown later on + break; + } + } + + throw new \RuntimeException('Salutation not set!'); + } + + /** + * Returns the date of birth from the request. + * + * @return string + * @throws \RuntimeException + */ + private function getDateOfBirth(): string + { + if ($this->request->exists('customer_dob_day') && + $this->request->exists('customer_dob_month') && + $this->request->exists('customer_dob_year')) { + return strtotime(implode( + '-', + [ + $this->request->get('customer_dob_year'), + $this->request->get('customer_dob_month'), + $this->request->get('customer_dob_day') + ] + )); + } + + throw new \RuntimeException('Date of birth not set!'); + } + // + // /** * Process the incoming POST response and return the redirect url depending on the response result. @@ -207,52 +260,25 @@ public function handleSyncRequest( ContactRepositoryContract $contactRepo, PaymentHelper $paymentHelper ): BaseResponse { - - $this->notification->error('number 1', __METHOD__); - - if (!$this->request->exists('customer_salutation') || !$this->request->exists('customer_dob_day') || - !$this->request->exists('customer_dob_month') || !$this->request->exists('customer_dob_year')) - { - $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__); - return $this->response->redirectTo('checkout'); - } - - $this->notification->error('number 2', __METHOD__); - - $salutation = $this->request->get('customer_salutation'); - $dateOfBirth = implode('-', - [ - $this->request->get('customer_dob_year'), - $this->request->get('customer_dob_month'), - $this->request->get('customer_dob_day') - ]); - $basket = $basketRepo->load(); $customerId = $basket->customerId; $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId)->toArray(); - $invoiceAddress['gender'] = $salutation === 'mrs' ? 'female' : 'male'; + $invoiceAddress['gender'] = $this->getSalutation(); $addressRepo->updateAddress($invoiceAddress, $invoiceAddress['id']); - $this->notification->error('number 3', __METHOD__); - $contact = $contactRepo->findContactById($customerId)->toArray(); - $contact['birthdayAt'] = strtotime($dateOfBirth); + $contact['birthdayAt'] = $this->getDateOfBirth(); $contactRepo->updateContact($contact, $customerId); - $this->notification->error('number 4', __METHOD__); - $mopId = $basket->methodOfPaymentId; - $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mopId); + $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mopId); $methodInstance = $paymentHelper->getPaymentMethodInstanceByMopId($mopId); if (!$methodInstance instanceof PaymentMethodContract) { $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__); return $this->response->redirectTo('checkout'); } - - $this->notification->error('number 5', __METHOD__); - $response = $this->paymentService->sendPaymentRequest( $basket, $paymentMethod, @@ -266,7 +292,6 @@ public function handleSyncRequest( $responseObj = $response['response']; $errorMsg = $responseObj['PROCESSING.REASON'] . ': ' . $responseObj['PROCESSING.RETURN']; } - $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__, ['Message' => $errorMsg]); return $this->response->redirectTo('checkout'); } diff --git a/src/Methods/AbstractMethod.php b/src/Methods/AbstractMethod.php index e2b01a3..0c8bd72 100755 --- a/src/Methods/AbstractMethod.php +++ b/src/Methods/AbstractMethod.php @@ -32,6 +32,7 @@ abstract class AbstractMethod extends PaymentMethodService implements PaymentMet const INITIALIZE_PAYMENT = true; const FORM_TEMPLATE = ''; const NEEDS_CUSTOMER_INPUT = true; + const NEEDS_BASKET = false; /** * @var PaymentHelper $helper @@ -256,4 +257,12 @@ public function needsCustomerInput(): bool { return static::NEEDS_CUSTOMER_INPUT; } + + /** + * {@inheritDoc} + */ + public function needsBasket(): bool + { + return static::NEEDS_BASKET; + } } diff --git a/src/Methods/InvoiceSecuredB2C.php b/src/Methods/InvoiceSecuredB2C.php index e46c24c..6e932e8 100755 --- a/src/Methods/InvoiceSecuredB2C.php +++ b/src/Methods/InvoiceSecuredB2C.php @@ -26,4 +26,5 @@ class InvoiceSecuredB2C extends AbstractMethod const INITIALIZE_PAYMENT = false; const FORM_TEMPLATE = 'Heidelpay::invoiceSecuredB2CForm'; const NEEDS_CUSTOMER_INPUT = false; + const NEEDS_BASKET = true; } diff --git a/src/Methods/PaymentMethodContract.php b/src/Methods/PaymentMethodContract.php index c38ab67..e7d04cd 100755 --- a/src/Methods/PaymentMethodContract.php +++ b/src/Methods/PaymentMethodContract.php @@ -130,4 +130,11 @@ public function getFormTemplate(): string; * @return bool */ public function needsCustomerInput(): bool; + + /** + * Returns true if a basket id has to be requested. + * + * @return bool + */ + public function needsBasket(): bool; } diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 8c5688c..81d1b5b 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -375,12 +375,10 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest['FRONTEND_PREVENT_ASYNC_REDIRECT'] = 'false'; } - if (false) { - $this->heidelpayRequest['NAME_SALUTATION'] = $addresses['billing']->gender === 'male' - ? Salutation::MR - : Salutation::MRS; + $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($addresses['billing']->gender); + $this->heidelpayRequest['NAME_BIRTHDATE'] = $addresses['billing']->birthday; - $this->heidelpayRequest['NAME_BIRTHDATE'] = $addresses['billing']->birthday; + if ($methodInstance->needsBasket()) { $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); } @@ -720,5 +718,20 @@ protected function assignTxnIdToOrder(string $txnId, int $orderId) $this->orderRepo->updateOrder($order->toArray(), $order->id); } + /** + * Returns the salutation for the given gender. + * + * @param array $gender + * @return mixed + */ + private function mapGenderToSalutation(array $gender) + { + $salutation = Salutation::MRS; + if ($gender === 'female') { + $salutation = Salutation::MRS; + } + return $salutation; + } + // } From affddefb6a424e37cb2cff7591e3ca9e3044cb5e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 12:35:33 +0100 Subject: [PATCH 18/70] [feature] (PLENTY-88) NGW-IVsec: Fix type error. --- 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 81d1b5b..c93fd99 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -721,10 +721,10 @@ protected function assignTxnIdToOrder(string $txnId, int $orderId) /** * Returns the salutation for the given gender. * - * @param array $gender + * @param string $gender * @return mixed */ - private function mapGenderToSalutation(array $gender) + private function mapGenderToSalutation($gender) { $salutation = Salutation::MRS; if ($gender === 'female') { From 992ada2ca8c5ff8e3f4e143212c32b9133e6b473 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 12:39:21 +0100 Subject: [PATCH 19/70] [feature] (PLENTY-88) NGW-IVsec: Disable basket for now. --- src/Services/PaymentService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index c93fd99..0db0473 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -378,9 +378,9 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($addresses['billing']->gender); $this->heidelpayRequest['NAME_BIRTHDATE'] = $addresses['billing']->birthday; - if ($methodInstance->needsBasket()) { - $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); - } +// if ($methodInstance->needsBasket()) { +// $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); +// } // shop + module information $this->heidelpayRequest['CRITERION_STORE_ID'] = $this->paymentHelper->getWebstoreId(); From 54793f67580435b54acef28c4ddfaddb8944bd5f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:03:50 +0100 Subject: [PATCH 20/70] [feature] (PLENTY-88) NGW-IVsec: Rename invoiceAddress to billingAddress. --- src/Controllers/ResponseController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 81d3d1b..5e7b6f3 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -263,9 +263,9 @@ public function handleSyncRequest( $basket = $basketRepo->load(); $customerId = $basket->customerId; - $invoiceAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId)->toArray(); - $invoiceAddress['gender'] = $this->getSalutation(); - $addressRepo->updateAddress($invoiceAddress, $invoiceAddress['id']); + $billingAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId)->toArray(); + $billingAddress['gender'] = $this->getSalutation(); + $addressRepo->updateAddress($billingAddress, $billingAddress['id']); $contact = $contactRepo->findContactById($customerId)->toArray(); $contact['birthdayAt'] = $this->getDateOfBirth(); From acdc583a3fc0aa1e340e57f4afeaaa66ae3dfb0d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:04:26 +0100 Subject: [PATCH 21/70] [feature] (PLENTY-88) NGW-IVsec: Fix code style issue. --- src/Services/PaymentService.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 0db0473..efd9b7c 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -334,21 +334,22 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest = array_merge($this->heidelpayRequest, $heidelpayAuth); // set customer personal information & address data - $addresses = $this->getCustomerAddressData($basket); + $addresses = $this->getCustomerAddressData($basket); + $billingAddress = $addresses['billing']; $this->heidelpayRequest['IDENTIFICATION_SHOPPERID'] = $basketArray['customerId']; - $this->heidelpayRequest['NAME_GIVEN'] = $addresses['billing']->firstName; - $this->heidelpayRequest['NAME_FAMILY'] = $addresses['billing']->lastName; - $this->heidelpayRequest['CONTACT_EMAIL'] = $addresses['billing']->email; - $this->heidelpayRequest['ADDRESS_STREET'] = $this->getFullStreetAndHouseNumber($addresses['billing']); - $this->heidelpayRequest['ADDRESS_ZIP'] = $addresses['billing']->postalCode; - $this->heidelpayRequest['ADDRESS_CITY'] = $addresses['billing']->town; - $this->heidelpayRequest['ADDRESS_COUNTRY'] = $this->countryRepository->findIsoCode( - $addresses['billing']->countryId, + $this->heidelpayRequest['NAME_GIVEN'] = $billingAddress->firstName; + $this->heidelpayRequest['NAME_FAMILY'] = $billingAddress->lastName; + $this->heidelpayRequest['CONTACT_EMAIL'] = $billingAddress->email; + $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' ); - if ($addresses['billing']->companyName !== null) { - $this->heidelpayRequest['NAME_COMPANY'] = $addresses['billing']->companyName; + if ($billingAddress->companyName !== null) { + $this->heidelpayRequest['NAME_COMPANY'] = $billingAddress->companyName; } $this->heidelpayRequest['IDENTIFICATION_TRANSACTIONID'] = $transactionId; @@ -375,8 +376,8 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest['FRONTEND_PREVENT_ASYNC_REDIRECT'] = 'false'; } - $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($addresses['billing']->gender); - $this->heidelpayRequest['NAME_BIRTHDATE'] = $addresses['billing']->birthday; + $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($billingAddress->gender); + $this->heidelpayRequest['NAME_BIRTHDATE'] = $billingAddress->birthday; // if ($methodInstance->needsBasket()) { // $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); From 54e66c6679e5f0e280cbf1d3065cd05ca1eb765b Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:10:04 +0100 Subject: [PATCH 22/70] [feature] (PLENTY-88) NGW-IVsec: Set birthdate correctly. --- src/Services/PaymentService.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index efd9b7c..18f438c 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -21,6 +21,7 @@ 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; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Frontend\Session\Storage\Contracts\FrontendSessionStorageFactoryContract; @@ -113,6 +114,10 @@ class PaymentService * @var BasketRepositoryContract */ private $basketRepository; + /** + * @var ContactRepositoryContract + */ + private $contactRepo; /** * PaymentService constructor. @@ -131,6 +136,7 @@ class PaymentService * @param OrderRepositoryContract $orderRepo * @param UrlServiceContract $urlService * @param BasketRepositoryContract $basketRepository + * @param ContactRepositoryContract $contactRepo */ public function __construct( AddressRepositoryContract $addressRepository, @@ -146,7 +152,8 @@ public function __construct( OrderTxnIdRelationRepositoryContract $orderTxnIdRepo, OrderRepositoryContract $orderRepo, UrlServiceContract $urlService, - BasketRepositoryContract $basketRepository + BasketRepositoryContract $basketRepository, + ContactRepositoryContract $contactRepo ) { $this->addressRepository = $addressRepository; $this->countryRepository = $countryRepository; @@ -162,6 +169,7 @@ public function __construct( $this->orderRepo = $orderRepo; $this->urlService = $urlService; $this->basketRepository = $basketRepository; + $this->contactRepo = $contactRepo; } /** @@ -334,8 +342,8 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest = array_merge($this->heidelpayRequest, $heidelpayAuth); // set customer personal information & address data - $addresses = $this->getCustomerAddressData($basket); - $billingAddress = $addresses['billing']; + $addresses = $this->getCustomerAddressData($basket); + $billingAddress = $addresses['billing']; $this->heidelpayRequest['IDENTIFICATION_SHOPPERID'] = $basketArray['customerId']; $this->heidelpayRequest['NAME_GIVEN'] = $billingAddress->firstName; $this->heidelpayRequest['NAME_FAMILY'] = $billingAddress->lastName; @@ -376,8 +384,11 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest['FRONTEND_PREVENT_ASYNC_REDIRECT'] = 'false'; } + $customerId = $basket->customerId; + $contact = $this->contactRepo->findContactById($customerId); + $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($billingAddress->gender); - $this->heidelpayRequest['NAME_BIRTHDATE'] = $billingAddress->birthday; + $this->heidelpayRequest['NAME_BIRTHDATE'] = (new \DateTime($contact->birthdayAt))->format('Y-m-d'); // if ($methodInstance->needsBasket()) { // $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); From f45de643eece760979aeb36600c5a649b2bf16f4 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:19:55 +0100 Subject: [PATCH 23/70] [feature] (PLENTY-88) NGW-IVsec: Fix birthday error. --- 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 18f438c..1460df9 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -388,7 +388,7 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $contact = $this->contactRepo->findContactById($customerId); $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($billingAddress->gender); - $this->heidelpayRequest['NAME_BIRTHDATE'] = (new \DateTime($contact->birthdayAt))->format('Y-m-d'); + $this->heidelpayRequest['NAME_BIRTHDATE'] = $contact->birthdayAt; // if ($methodInstance->needsBasket()) { // $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); From fcbe98038863b02c5aa208d4f17a6b69928da29a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:27:32 +0100 Subject: [PATCH 24/70] [feature] (PLENTY-88) NGW-IVsec: Fix default ivsec channelid. --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 72bb36e..0562aa7 100755 --- a/config.json +++ b/config.json @@ -346,7 +346,7 @@ "required": false, "label": "Config.invoicesecuredb2cChannelIdLabel", "options": { - "defaultValue": "31HA07BC81895ACFE22C154CBC521922" + "defaultValue": "31HA07BC8129FBA7AF65934626B0F907" } }, "invoicesecuredb2c.minAmount": { From f1f23bf86344462e73facd079e058c662fceba11 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:36:01 +0100 Subject: [PATCH 25/70] [feature] (PLENTY-88) NGW-IVsec: Fix birhdate format. --- 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 1460df9..8f06c20 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -388,7 +388,7 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $contact = $this->contactRepo->findContactById($customerId); $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($billingAddress->gender); - $this->heidelpayRequest['NAME_BIRTHDATE'] = $contact->birthdayAt; + $this->heidelpayRequest['NAME_BIRTHDATE'] = explode('T', $contact->birthdayAt)[0]; // if ($methodInstance->needsBasket()) { // $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); From 202d981e984606440eb6c5b7e68886ff867a9ac1 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 13:54:14 +0100 Subject: [PATCH 26/70] [feature] (PLENTY-88) NGW-IVsec: Fix birhdate format. --- 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 8f06c20..5ec619d 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -388,7 +388,7 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $contact = $this->contactRepo->findContactById($customerId); $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($billingAddress->gender); - $this->heidelpayRequest['NAME_BIRTHDATE'] = explode('T', $contact->birthdayAt)[0]; + $this->heidelpayRequest['NAME_BIRTHDATE'] = substr($contact->birthdayAt, 0, 10); // if ($methodInstance->needsBasket()) { // $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); From 59b57f682d4798ec3cefcaccd42f1387ce99658f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 14:24:53 +0100 Subject: [PATCH 27/70] [feature] (PLENTY-88) NGW-IVsec: Fix error response logging. --- src/Controllers/ResponseController.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 5e7b6f3..300df13 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -287,11 +287,8 @@ public function handleSyncRequest( ); if ($response['isError'] === true) { - $errorMsg = ''; - if (isset($response['response']['PROCESSING.REASON'], $response['response']['PROCESSING.RETURN'])) { - $responseObj = $response['response']; - $errorMsg = $responseObj['PROCESSING.REASON'] . ': ' . $responseObj['PROCESSING.RETURN']; - } + $responseObj = $response['response']; + $errorMsg = ($responseObj['PROCESSING.REASON'] ?? '') . ': ' . ($responseObj['PROCESSING.RETURN'] ?? ''); $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__, ['Message' => $errorMsg]); return $this->response->redirectTo('checkout'); } From b1807246fab459bcc84b0003e39d4461351ad538 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 15:08:51 +0100 Subject: [PATCH 28/70] [feature] (PLENTY-88) NGW-IVsec: Set default values in twig. --- resources/views/invoiceSecuredB2CForm.twig | 28 +++++++++------------- src/Services/PaymentService.php | 14 ++++++++++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/resources/views/invoiceSecuredB2CForm.twig b/resources/views/invoiceSecuredB2CForm.twig index 1280c4c..5b06084 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -24,18 +24,14 @@
@@ -56,11 +52,9 @@ {% set minYear = "now -80 years"|date("Y") %} {% set maxYear = "now -18 years"|date("Y") %} -
    - {% for year in maxYear..minYear %} - - {% endfor %} -
+ {% for year in maxYear..minYear %} + + {% endfor %}
diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 5ec619d..8bfc522 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -309,9 +309,21 @@ public function getPaymentMethodContent( } } + $basket = $this->basketRepository->load(); + $customerId = $basket->customerId; + $contact = $this->contactRepo->findContactById($customerId); + $birthday = explode('-', substr($contact->birthdayAt, 0, 10)); + if ($type === GetPaymentMethodContent::RETURN_TYPE_HTML) { // $value should contain the payment frame url (also form url) - $value = $this->renderPaymentForm($methodInstance->getFormTemplate(), ['submit_action' => $value]); + $parameters = [ + 'submit_action' => $value, + 'customer_dob_day' => $birthday[2] ?? '', + 'customer_dob_month' => $birthday[1] ?? '', + 'customer_dob_year' => $birthday[0] ?? '', + 'customer_salutation' => $contact->gender + ]; + $value = $this->renderPaymentForm($methodInstance->getFormTemplate(), $parameters); } return [$type, $value]; From efe315cdc3a0e181d133f1b98234573c36fae63a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 15:29:06 +0100 Subject: [PATCH 29/70] [feature] (PLENTY-88) NGW-IVsec: Set default values in twig. --- 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 5b06084..d2d6ed7 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -24,13 +24,13 @@
From 2b253f28679af7c8876fe1e83fa593a3147ed9c4 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 15:34:48 +0100 Subject: [PATCH 30/70] [feature] (PLENTY-88) NGW-IVsec: Set default values in twig. --- resources/views/invoiceSecuredB2CForm.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/invoiceSecuredB2CForm.twig b/resources/views/invoiceSecuredB2CForm.twig index d2d6ed7..f17b94a 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -27,7 +27,7 @@ {% for day in 1..31 %} - {{ day = '%02d'|format(day) }} + {% set day = '%02d'|format(day) %} From 5c9a0654d6879ca6e2a0d2b6ca14bc5b5049141d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 7 Mar 2019 15:46:50 +0100 Subject: [PATCH 31/70] [feature] (PLENTY-88) NGW-IVsec: Set default values in twig. --- resources/views/invoiceSecuredB2CForm.twig | 26 +++++++++++++--------- src/Services/PaymentService.php | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/resources/views/invoiceSecuredB2CForm.twig b/resources/views/invoiceSecuredB2CForm.twig index f17b94a..ec069f4 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -9,9 +9,9 @@
@@ -38,22 +38,28 @@
diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 8bfc522..b532d6e 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -321,7 +321,7 @@ public function getPaymentMethodContent( 'customer_dob_day' => $birthday[2] ?? '', 'customer_dob_month' => $birthday[1] ?? '', 'customer_dob_year' => $birthday[0] ?? '', - 'customer_salutation' => $contact->gender + 'customer_gender' => $contact->gender ]; $value = $this->renderPaymentForm($methodInstance->getFormTemplate(), $parameters); } From 2884b488596f4fb6e68850fa8c06b4de5c9c8cda Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 08:50:37 +0100 Subject: [PATCH 32/70] [feature] (PLENTY-88) NGW-IVsec: Refactor applying salutation and birthdate to request. --- resources/views/invoiceSecuredB2CForm.twig | 4 +- src/Controllers/ResponseController.php | 30 ++------------ src/Services/PaymentService.php | 48 +++++++++------------- 3 files changed, 25 insertions(+), 57 deletions(-) diff --git a/resources/views/invoiceSecuredB2CForm.twig b/resources/views/invoiceSecuredB2CForm.twig index ec069f4..f54d577 100755 --- a/resources/views/invoiceSecuredB2CForm.twig +++ b/resources/views/invoiceSecuredB2CForm.twig @@ -10,8 +10,8 @@
diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 300df13..d9953d5 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -12,8 +12,6 @@ use Heidelpay\Services\PaymentService; use Heidelpay\Services\UrlServiceContract; use Heidelpay\Traits\Translator; -use Plenty\Modules\Account\Address\Contracts\AddressRepositoryContract; -use Plenty\Modules\Account\Contact\Contracts\ContactRepositoryContract; use Plenty\Modules\Basket\Contracts\BasketRepositoryContract; use Plenty\Plugin\Controller; use Plenty\Plugin\Http\Request; @@ -123,17 +121,7 @@ private function createAndHandleTransaction($response, $responseObject): bool private function getSalutation(): string { if ($this->request->exists('customer_salutation')) { - switch ($this->request->get('customer_salutation')) { - case 'mr': - return 'male'; - break; - case 'mrs': - return 'female'; - break; - default: - // do nothing, an exception will be thrown later on - break; - } + $this->request->get('customer_salutation'); } throw new \RuntimeException('Salutation not set!'); @@ -248,28 +236,15 @@ public function emergencyRedirect(): BaseResponse * Handles form requests which do not need any further action by the client. * * @param BasketRepositoryContract $basketRepo - * @param AddressRepositoryContract $addressRepo - * @param ContactRepositoryContract $contactRepo * @param PaymentHelper $paymentHelper * @return BaseResponse * @throws \RuntimeException */ public function handleSyncRequest( BasketRepositoryContract $basketRepo, - AddressRepositoryContract $addressRepo, - ContactRepositoryContract $contactRepo, PaymentHelper $paymentHelper ): BaseResponse { $basket = $basketRepo->load(); - $customerId = $basket->customerId; - - $billingAddress = $addressRepo->findAddressById($basket->customerInvoiceAddressId)->toArray(); - $billingAddress['gender'] = $this->getSalutation(); - $addressRepo->updateAddress($billingAddress, $billingAddress['id']); - - $contact = $contactRepo->findContactById($customerId)->toArray(); - $contact['birthdayAt'] = $this->getDateOfBirth(); - $contactRepo->updateContact($contact, $customerId); $mopId = $basket->methodOfPaymentId; $paymentMethod = $paymentHelper->mapMopToPaymentMethod($mopId); @@ -283,7 +258,8 @@ public function handleSyncRequest( $basket, $paymentMethod, $methodInstance->getTransactionType(), - $mopId + $mopId, + ['birthday' => $this->getDateOfBirth(), 'salutation' => $this->getSalutation()] ); if ($response['isError'] === true) { diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index b532d6e..ea4849f 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -5,7 +5,6 @@ use Heidelpay\Configs\MethodConfigContract; use Heidelpay\Constants\Plugin; use Heidelpay\Constants\Routes; -use Heidelpay\Constants\Salutation; use Heidelpay\Constants\SessionKeys; use Heidelpay\Constants\TransactionStatus; use Heidelpay\Constants\TransactionType; @@ -232,7 +231,7 @@ public function executePayment(string $paymentMethod, ExecutePayment $event): ar * @param string $paymentMethod * @param string $transactionType * @param int $mopId - * @param array $parameters + * @param array $additionalParams * * @return array * @throws \RuntimeException @@ -242,17 +241,16 @@ public function sendPaymentRequest( string $paymentMethod, string $transactionType, int $mopId, - array $parameters = [] + array $additionalParams = [] ): array { $txnId = $this->createNewTxnId($basket); $this->createOrUpdateRelation($txnId, $mopId); - $this->prepareRequest($basket, $paymentMethod, $mopId, $txnId); + $this->prepareRequest($basket, $paymentMethod, $mopId, $txnId, $additionalParams); $result = $this->libService->sendTransactionRequest($paymentMethod, [ 'request' => $this->heidelpayRequest, - 'transactionType' => $transactionType, - 'parameters' => $parameters + 'transactionType' => $transactionType ]); return $result; @@ -311,6 +309,7 @@ public function getPaymentMethodContent( $basket = $this->basketRepository->load(); $customerId = $basket->customerId; + $contact = $this->contactRepo->findContactById($customerId); $birthday = explode('-', substr($contact->birthdayAt, 0, 10)); @@ -334,14 +333,20 @@ public function getPaymentMethodContent( * @param string $paymentMethod * @param int $mopId * @param string $transactionId + * @param array $additionalParams * @throws \RuntimeException */ - private function prepareRequest(Basket $basket, string $paymentMethod, int $mopId, string $transactionId) + private function prepareRequest( + Basket $basket, + string $paymentMethod, + int $mopId, + string $transactionId, + array $additionalParams = []) { $basketArray = $basket->toArray(); - /** @var BasketService $basketService */ - $basketService = pluginApp(BasketService::class); +// /** @var BasketService $basketService */ +// $basketService = pluginApp(BasketService::class); /** @var SecretService $secretService */ $secretService = pluginApp(SecretService::class); @@ -396,11 +401,13 @@ private function prepareRequest(Basket $basket, string $paymentMethod, int $mopI $this->heidelpayRequest['FRONTEND_PREVENT_ASYNC_REDIRECT'] = 'false'; } - $customerId = $basket->customerId; - $contact = $this->contactRepo->findContactById($customerId); + if (isset($additionalParams['birthday'])) { + $this->heidelpayRequest['NAME_BIRTHDATE'] = $additionalParams['birthday']; + } - $this->heidelpayRequest['NAME_SALUTATION'] = $this->mapGenderToSalutation($billingAddress->gender); - $this->heidelpayRequest['NAME_BIRTHDATE'] = substr($contact->birthdayAt, 0, 10); + if (isset($additionalParams['salutation'])) { + $this->heidelpayRequest['NAME_SALUTATION'] = $additionalParams['salutation']; + } // if ($methodInstance->needsBasket()) { // $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); @@ -742,20 +749,5 @@ protected function assignTxnIdToOrder(string $txnId, int $orderId) $this->orderRepo->updateOrder($order->toArray(), $order->id); } - /** - * Returns the salutation for the given gender. - * - * @param string $gender - * @return mixed - */ - private function mapGenderToSalutation($gender) - { - $salutation = Salutation::MRS; - if ($gender === 'female') { - $salutation = Salutation::MRS; - } - return $salutation; - } - // } From 907503e239cadaa6745e1ad59f5818e1445f5e70 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 09:34:33 +0100 Subject: [PATCH 33/70] [feature] (PLENTY-88) NGW-IVsec: Debug print all post data to log. --- src/Controllers/ResponseController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index d9953d5..c0dc08d 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -244,6 +244,11 @@ public function handleSyncRequest( BasketRepositoryContract $basketRepo, PaymentHelper $paymentHelper ): BaseResponse { + + $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__, $this->request->all()); + return $this->response->redirectTo('checkout'); + + $basket = $basketRepo->load(); $mopId = $basket->methodOfPaymentId; From 1bf1fb933c83b07034f0d9bdb47f81712f29dcea Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 09:40:41 +0100 Subject: [PATCH 34/70] [feature] (PLENTY-88) NGW-IVsec: Fix return salutation. --- src/Controllers/ResponseController.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index c0dc08d..0d5baaa 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -121,7 +121,7 @@ private function createAndHandleTransaction($response, $responseObject): bool private function getSalutation(): string { if ($this->request->exists('customer_salutation')) { - $this->request->get('customer_salutation'); + return $this->request->get('customer_salutation'); } throw new \RuntimeException('Salutation not set!'); @@ -244,11 +244,6 @@ public function handleSyncRequest( BasketRepositoryContract $basketRepo, PaymentHelper $paymentHelper ): BaseResponse { - - $this->notification->error('payment.errorDuringPaymentExecution', __METHOD__, $this->request->all()); - return $this->response->redirectTo('checkout'); - - $basket = $basketRepo->load(); $mopId = $basket->methodOfPaymentId; From fe8f41647f43fc17e011efcebc0a5e0ee444c6b3 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 09:47:06 +0100 Subject: [PATCH 35/70] [feature] (PLENTY-88) NGW-IVsec: Fix birthday format. --- src/Controllers/ResponseController.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Controllers/ResponseController.php b/src/Controllers/ResponseController.php index 0d5baaa..edf0ce7 100755 --- a/src/Controllers/ResponseController.php +++ b/src/Controllers/ResponseController.php @@ -138,14 +138,14 @@ private function getDateOfBirth(): string if ($this->request->exists('customer_dob_day') && $this->request->exists('customer_dob_month') && $this->request->exists('customer_dob_year')) { - return strtotime(implode( - '-', - [ - $this->request->get('customer_dob_year'), - $this->request->get('customer_dob_month'), - $this->request->get('customer_dob_day') - ] - )); + return implode( + '-', + [ + $this->request->get('customer_dob_year'), + $this->request->get('customer_dob_month'), + $this->request->get('customer_dob_day') + ] + ); } throw new \RuntimeException('Date of birth not set!'); From 09be67bf5a0d0df366f8cf524995f82695fd7992 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 12:54:20 +0100 Subject: [PATCH 36/70] [feature] (PLENTY-88) NGW-IVsec: Add basket. --- src/Services/PaymentService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index ea4849f..5a38ebe 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -345,8 +345,8 @@ private function prepareRequest( { $basketArray = $basket->toArray(); -// /** @var BasketService $basketService */ -// $basketService = pluginApp(BasketService::class); + /** @var BasketService $basketService */ + $basketService = pluginApp(BasketService::class); /** @var SecretService $secretService */ $secretService = pluginApp(SecretService::class); @@ -409,9 +409,9 @@ private function prepareRequest( $this->heidelpayRequest['NAME_SALUTATION'] = $additionalParams['salutation']; } -// if ($methodInstance->needsBasket()) { -// $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); -// } + if ($methodInstance->needsBasket()) { + $this->heidelpayRequest['BASKET_ID'] = $basketService->requestBasketId($basket, $heidelpayAuth); + } // shop + module information $this->heidelpayRequest['CRITERION_STORE_ID'] = $this->paymentHelper->getWebstoreId(); From b5d31ff4b0db8ca338267acbccc392caadc72f73 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 13:04:18 +0100 Subject: [PATCH 37/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data. --- src/Services/BasketService.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 52e34f6..cab0695 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -27,18 +27,25 @@ class BasketService * @var MainConfigContract */ private $config; + /** + * @var NotificationServiceContract + */ + private $notificationService; /** * BasketService constructor. * @param LibService $libraryService * @param MainConfigContract $config + * @param NotificationServiceContract $notificationService */ public function __construct( LibService $libraryService, - MainConfigContract $config + MainConfigContract $config, + NotificationServiceContract $notificationService ) { $this->libService = $libraryService; $this->config = $config; + $this->notificationService = $notificationService; } /** @@ -61,6 +68,9 @@ public function requestBasketId(Basket $basket, array $authData): string $params['sandboxmode'] = $this->config->isInSandboxMode(); $response = $this->libService->submitBasket($params); + + $this->notificationService->error('BasketItems', __METHOD__, ['basket' => $basket]); + return $response['basketId']; } } From 277d4d5aaa14b23cdc40dc4a803446790b818d81 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 13:10:13 +0100 Subject: [PATCH 38/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- 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 cab0695..4c02b53 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -69,7 +69,7 @@ public function requestBasketId(Basket $basket, array $authData): string $response = $this->libService->submitBasket($params); - $this->notificationService->error('BasketItems', __METHOD__, ['basket' => $basket]); + $this->notificationService->error('BasketItems', __METHOD__, ['basket' => $basket, 'array' => $basket->toArray(), 'items' => $basket->basketItems]); return $response['basketId']; } From 5a9d65dfa25eff230f05da4c2df589b47c7f4acc Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 13:18:27 +0100 Subject: [PATCH 39/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- src/Services/BasketService.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 4c02b53..e76eeff 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -4,6 +4,7 @@ use Heidelpay\Configs\MainConfigContract; use Plenty\Modules\Basket\Models\Basket; +use Plenty\Modules\Basket\Models\BasketItem; /** * Provides connection to heidelpay basketApi. @@ -65,11 +66,19 @@ public function requestBasketId(Basket $basket, array $authData): string 'senderId' => $authData['SECURITY_SENDER'], ]; $params['basket'] = $basket->toArray(); + + $items = []; + foreach ($basket->basketItems as $item) { + /** @var BasketItem $item*/ + $items = $item->toArray(); + } + $params['basketItems'] = $items; + $params['sandboxmode'] = $this->config->isInSandboxMode(); $response = $this->libService->submitBasket($params); - $this->notificationService->error('BasketItems', __METHOD__, ['basket' => $basket, 'array' => $basket->toArray(), 'items' => $basket->basketItems]); + $this->notificationService->error('BasketItems', __METHOD__, ['basket' => $basket, 'array' => $basket->toArray(), 'items' => $basket->basketItems, 'itemsArrays' => $items]); return $response['basketId']; } From 063912a396f9c03215c2aa7976053d3476e53c26 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 13:26:20 +0100 Subject: [PATCH 40/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- 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 e76eeff..a9f9e18 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -70,7 +70,7 @@ public function requestBasketId(Basket $basket, array $authData): string $items = []; foreach ($basket->basketItems as $item) { /** @var BasketItem $item*/ - $items = $item->toArray(); + $items[] = $item->toArray(); } $params['basketItems'] = $items; From 0f62201c93ec76b50c908a896d58ad45330a7e71 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 13:36:51 +0100 Subject: [PATCH 41/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- src/Services/BasketService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index a9f9e18..5d84ff1 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -70,6 +70,7 @@ public function requestBasketId(Basket $basket, array $authData): string $items = []; foreach ($basket->basketItems as $item) { /** @var BasketItem $item*/ + $this->notificationService->error('BasketItem', __METHOD__, ['item' => $item->toArray()]); $items[] = $item->toArray(); } $params['basketItems'] = $items; From 4e21a5310bb7ec56111bd1ebe65403a5b469279f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 13:40:09 +0100 Subject: [PATCH 42/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- src/Services/BasketService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 5d84ff1..4600da8 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -68,11 +68,13 @@ public function requestBasketId(Basket $basket, array $authData): string $params['basket'] = $basket->toArray(); $items = []; + $this->notificationService->error('Vor BasketItems loop', __METHOD__); foreach ($basket->basketItems as $item) { /** @var BasketItem $item*/ $this->notificationService->error('BasketItem', __METHOD__, ['item' => $item->toArray()]); $items[] = $item->toArray(); } + $this->notificationService->error('Nach BasketItems llop', __METHOD__); $params['basketItems'] = $items; $params['sandboxmode'] = $this->config->isInSandboxMode(); From 50310b0eae36ab821d9fde21e44034fd721fa8ab Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:05:06 +0100 Subject: [PATCH 43/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- src/Services/BasketService.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 4600da8..61a0c54 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -71,7 +71,11 @@ public function requestBasketId(Basket $basket, array $authData): string $this->notificationService->error('Vor BasketItems loop', __METHOD__); foreach ($basket->basketItems as $item) { /** @var BasketItem $item*/ - $this->notificationService->error('BasketItem', __METHOD__, ['item' => $item->toArray()]); + $this->notificationService->error('BasketItem', __METHOD__, [ + 'item' => $item->toArray(), + 'itemObj' => $item, + 'items' => $basket->basketItems + ]); $items[] = $item->toArray(); } $this->notificationService->error('Nach BasketItems llop', __METHOD__); From a0aa227d9f2f37c07d12171b544bd95ca64b552d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:17:49 +0100 Subject: [PATCH 44/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- resources/lib/submitBasket.php | 14 ++++++++------ src/Services/BasketService.php | 13 ------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index d7344f0..9aac857 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -18,6 +18,8 @@ $authData = SdkRestApi::getParam('auth'); /** @var array $basketData */ $basketData = SdkRestApi::getParam('basket'); +/** @var array $basketItems */ +$basketItems = SdkRestApi::getParam('basketItems'); /** @var bool $sandmoxmode */ $sandboxmode = SdkRestApi::getParam('sandboxmode'); @@ -26,13 +28,13 @@ //$basket->setAmountTotalVat($basketData['??']); $basket->setAmountTotalDiscount((int) $basketData['basketRebate'] * 100); -foreach ($basketData['basketItems'] as $cartItem) { +foreach ($basketItems as $item) { $basketItem = new \Heidelpay\PhpBasketApi\Object\BasketItem(); - $basketItem->setAmountGross((int) $cartItem['basketAmount'] * 100); - $basketItem->setAmountNet((int) $cartItem['basketAmountNet'] * 100); - $basketItem->setAmountDiscount((int) $cartItem['rebate'] * 100); - $basketItem->setQuantity((int) $cartItem['quantity'] * 100); - $basketItem->setVat((int) $cartItem['vat'] * 100); + $basketItem->setAmountGross((int)$item['basketAmount'] * 100); + $basketItem->setAmountNet((int)$item['basketAmountNet'] * 100); + $basketItem->setAmountDiscount((int)$item['rebate'] * 100); + $basketItem->setQuantity((int)$item['quantity'] * 100); + $basketItem->setVat((int)$item['vat'] * 100); } $request = new BasketApiRequest(); diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 61a0c54..a337d20 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -68,25 +68,12 @@ public function requestBasketId(Basket $basket, array $authData): string $params['basket'] = $basket->toArray(); $items = []; - $this->notificationService->error('Vor BasketItems loop', __METHOD__); foreach ($basket->basketItems as $item) { - /** @var BasketItem $item*/ - $this->notificationService->error('BasketItem', __METHOD__, [ - 'item' => $item->toArray(), - 'itemObj' => $item, - 'items' => $basket->basketItems - ]); $items[] = $item->toArray(); } - $this->notificationService->error('Nach BasketItems llop', __METHOD__); $params['basketItems'] = $items; - $params['sandboxmode'] = $this->config->isInSandboxMode(); - $response = $this->libService->submitBasket($params); - - $this->notificationService->error('BasketItems', __METHOD__, ['basket' => $basket, 'array' => $basket->toArray(), 'items' => $basket->basketItems, 'itemsArrays' => $items]); - return $response['basketId']; } } From 00bd668d376b50632696a5b4cb1a637f7628a119 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:26:44 +0100 Subject: [PATCH 45/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- resources/lib/submitBasket.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 9aac857..4534e9b 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -30,10 +30,9 @@ foreach ($basketItems as $item) { $basketItem = new \Heidelpay\PhpBasketApi\Object\BasketItem(); - $basketItem->setAmountGross((int)$item['basketAmount'] * 100); - $basketItem->setAmountNet((int)$item['basketAmountNet'] * 100); + $basketItem->setAmountGross((int)$item['price'] * 100); $basketItem->setAmountDiscount((int)$item['rebate'] * 100); - $basketItem->setQuantity((int)$item['quantity'] * 100); + $basketItem->setQuantity((int)$item['quantity']); $basketItem->setVat((int)$item['vat'] * 100); } From 24744290ace24599424727f0ba15def9e88de3b4 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:30:14 +0100 Subject: [PATCH 46/70] [feature] (PLENTY-88) NGW-IVsec: Debug basket data + items. --- resources/lib/submitBasket.php | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 4534e9b..ce39fda 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -25,7 +25,6 @@ $basket = new \Heidelpay\PhpBasketApi\Object\Basket(); $basket->setAmountTotalNet((int) $basketData['basketAmountNet'] * 100); -//$basket->setAmountTotalVat($basketData['??']); $basket->setAmountTotalDiscount((int) $basketData['basketRebate'] * 100); foreach ($basketItems as $item) { From 24ec99179c5f8624e1f003f9ee8bbaa7c0df7b12 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:36:07 +0100 Subject: [PATCH 47/70] [feature] (PLENTY-88) NGW-IVsec: Add basket currency. --- resources/lib/submitBasket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index ce39fda..8bc24ca 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -26,6 +26,7 @@ $basket = new \Heidelpay\PhpBasketApi\Object\Basket(); $basket->setAmountTotalNet((int) $basketData['basketAmountNet'] * 100); $basket->setAmountTotalDiscount((int) $basketData['basketRebate'] * 100); +$basket->setCurrencyCode($basketData['currency']); foreach ($basketItems as $item) { $basketItem = new \Heidelpay\PhpBasketApi\Object\BasketItem(); From 269acc1ea27fc1870c15cba076ae806e4e4c6365 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:40:19 +0100 Subject: [PATCH 48/70] [feature] (PLENTY-88) NGW-IVsec: Add basketitem to basket. --- resources/lib/submitBasket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 8bc24ca..d27fd77 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -34,6 +34,7 @@ $basketItem->setAmountDiscount((int)$item['rebate'] * 100); $basketItem->setQuantity((int)$item['quantity']); $basketItem->setVat((int)$item['vat'] * 100); + $basket->addBasketItem($basketItem); } $request = new BasketApiRequest(); From 5dfdf9f8d94438756b18d41bd2acbd59c67c3c43 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 14:50:07 +0100 Subject: [PATCH 49/70] [feature] (PLENTY-88) NGW-IVsec: Add item price. --- src/Services/BasketService.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index a337d20..0c24745 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -5,6 +5,7 @@ use Heidelpay\Configs\MainConfigContract; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Basket\Models\BasketItem; +use Plenty\Modules\Item\SalesPrice\Contracts\SalesPriceRepositoryContract; /** * Provides connection to heidelpay basketApi. @@ -32,21 +33,28 @@ class BasketService * @var NotificationServiceContract */ private $notificationService; + /** + * @var SalesPriceRepositoryContract + */ + private $priceRepo; /** * BasketService constructor. * @param LibService $libraryService * @param MainConfigContract $config * @param NotificationServiceContract $notificationService + * @param SalesPriceRepositoryContract $priceRepo */ public function __construct( LibService $libraryService, MainConfigContract $config, - NotificationServiceContract $notificationService + NotificationServiceContract $notificationService, + SalesPriceRepositoryContract $priceRepo ) { $this->libService = $libraryService; $this->config = $config; $this->notificationService = $notificationService; + $this->priceRepo = $priceRepo; } /** @@ -69,8 +77,15 @@ public function requestBasketId(Basket $basket, array $authData): string $items = []; foreach ($basket->basketItems as $item) { + /** @var BasketItem $item */ + $price = $this->priceRepo->findById($item->priceId); $items[] = $item->toArray(); + + $this->notificationService->error('basket item', __METHOD__, ['item' => $item, 'price' => $price]); } + + + $params['basketItems'] = $items; $params['sandboxmode'] = $this->config->isInSandboxMode(); $response = $this->libService->submitBasket($params); From 362a27e702f814994d1e601720efe2aacc876841 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 15:10:44 +0100 Subject: [PATCH 50/70] [feature] (PLENTY-88) NGW-IVsec: Fix fetching price object. --- src/Services/BasketService.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 0c24745..7039d49 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -3,6 +3,7 @@ namespace Heidelpay\Services; use Heidelpay\Configs\MainConfigContract; +use Plenty\Modules\Authorization\Services\AuthHelper; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Basket\Models\BasketItem; use Plenty\Modules\Item\SalesPrice\Contracts\SalesPriceRepositoryContract; @@ -37,6 +38,10 @@ class BasketService * @var SalesPriceRepositoryContract */ private $priceRepo; + /** + * @var AuthHelper + */ + private $authHelper; /** * BasketService constructor. @@ -44,17 +49,20 @@ class BasketService * @param MainConfigContract $config * @param NotificationServiceContract $notificationService * @param SalesPriceRepositoryContract $priceRepo + * @param AuthHelper $authHelper */ public function __construct( LibService $libraryService, MainConfigContract $config, NotificationServiceContract $notificationService, - SalesPriceRepositoryContract $priceRepo + SalesPriceRepositoryContract $priceRepo, + AuthHelper $authHelper ) { $this->libService = $libraryService; $this->config = $config; $this->notificationService = $notificationService; $this->priceRepo = $priceRepo; + $this->authHelper = $authHelper; } /** @@ -78,7 +86,11 @@ public function requestBasketId(Basket $basket, array $authData): string $items = []; foreach ($basket->basketItems as $item) { /** @var BasketItem $item */ - $price = $this->priceRepo->findById($item->priceId); + $price = $this->authHelper->processUnguarded( + function () use ($item) { + return $this->priceRepo->findById($item->priceId); + } + ); $items[] = $item->toArray(); $this->notificationService->error('basket item', __METHOD__, ['item' => $item, 'price' => $price]); From 519202f408cc8975a1398c1ec19c9b5c153724aa Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 16:22:43 +0100 Subject: [PATCH 51/70] [feature] (PLENTY-88) NGW-IVsec: Refactor amount calculation. --- resources/lib/submitBasket.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index d27fd77..f171afd 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -12,8 +12,13 @@ * @package heidelpay\plentymarkets-gateway\external-lib-callbacks */ +use Heidelpay\PhpBasketApi\Object\BasketItem; use Heidelpay\PhpBasketApi\Request as BasketApiRequest; +function normalizeValue($value) { + return (int)round(bcmul($value, 100)); +} + /** @var array $authData */ $authData = SdkRestApi::getParam('auth'); /** @var array $basketData */ @@ -24,16 +29,19 @@ $sandboxmode = SdkRestApi::getParam('sandboxmode'); $basket = new \Heidelpay\PhpBasketApi\Object\Basket(); -$basket->setAmountTotalNet((int) $basketData['basketAmountNet'] * 100); -$basket->setAmountTotalDiscount((int) $basketData['basketRebate'] * 100); +$basket->setAmountTotalNet(normalizeValue($basketData['basketAmountNet'])); +$basket->setAmountTotalDiscount(normalizeValue($basketData['basketRebate'])); $basket->setCurrencyCode($basketData['currency']); foreach ($basketItems as $item) { - $basketItem = new \Heidelpay\PhpBasketApi\Object\BasketItem(); - $basketItem->setAmountGross((int)$item['price'] * 100); - $basketItem->setAmountDiscount((int)$item['rebate'] * 100); + $basketItem = new BasketItem(); + $amount = normalizeValue($item['price']); + $vat = $item['vat']; + $basketItem->setAmountGross($amount); + $basketItem->setAmountNet(normalizeValue(bcdiv($amount, 100 + $vat))); + $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity((int)$item['quantity']); - $basketItem->setVat((int)$item['vat'] * 100); + $basketItem->setVat(normalizeValue($vat)); $basket->addBasketItem($basketItem); } From afb994f674b20beb043b6ae75f9f8c50a2ebdb9c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 16:38:34 +0100 Subject: [PATCH 52/70] [feature] (PLENTY-88) NGW-IVsec: Fix calculation (remove bcmath). --- resources/lib/submitBasket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index f171afd..aa48b37 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -16,7 +16,7 @@ use Heidelpay\PhpBasketApi\Request as BasketApiRequest; function normalizeValue($value) { - return (int)round(bcmul($value, 100)); + return (int)round($value * 100); } /** @var array $authData */ @@ -38,7 +38,7 @@ function normalizeValue($value) { $amount = normalizeValue($item['price']); $vat = $item['vat']; $basketItem->setAmountGross($amount); - $basketItem->setAmountNet(normalizeValue(bcdiv($amount, 100 + $vat))); + $basketItem->setAmountNet(normalizeValue($amount / (100 + $vat))); $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity((int)$item['quantity']); $basketItem->setVat(normalizeValue($vat)); From f1fea0450c95f8aceecdd1d594c9c7aa29e06a91 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 16:47:56 +0100 Subject: [PATCH 53/70] [feature] (PLENTY-88) NGW-IVsec: Set basketItem reference id. --- resources/lib/submitBasket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index aa48b37..dca4c56 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -42,6 +42,7 @@ function normalizeValue($value) { $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity((int)$item['quantity']); $basketItem->setVat(normalizeValue($vat)); + $basketItem->setBasketItemReferenceId($item->id); $basket->addBasketItem($basketItem); } From 2185b1cf13348a3ac8b8c6785598e83db48f2956 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 16:54:11 +0100 Subject: [PATCH 54/70] [feature] (PLENTY-88) NGW-IVsec: Set basketItem reference id. --- resources/lib/submitBasket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index dca4c56..5c67c80 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -42,7 +42,7 @@ function normalizeValue($value) { $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity((int)$item['quantity']); $basketItem->setVat(normalizeValue($vat)); - $basketItem->setBasketItemReferenceId($item->id); + $basketItem->setBasketItemReferenceId($item['id']); $basket->addBasketItem($basketItem); } From 6d67bed77046670e9cdb7e0d12168fe3ca1bf5b7 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 17:06:27 +0100 Subject: [PATCH 55/70] [feature] (PLENTY-88) NGW-IVsec: Debug Get item title. --- resources/lib/submitBasket.php | 1 + src/Services/BasketService.php | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 5c67c80..f6dbc44 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -43,6 +43,7 @@ function normalizeValue($value) { $basketItem->setQuantity((int)$item['quantity']); $basketItem->setVat(normalizeValue($vat)); $basketItem->setBasketItemReferenceId($item['id']); + $basketItem->setTitle($item['id']); $basket->addBasketItem($basketItem); } diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 7039d49..0d0d77d 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -6,7 +6,7 @@ use Plenty\Modules\Authorization\Services\AuthHelper; use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Basket\Models\BasketItem; -use Plenty\Modules\Item\SalesPrice\Contracts\SalesPriceRepositoryContract; +use Plenty\Modules\Item\Item\Contracts\ItemRepositoryContract; /** * Provides connection to heidelpay basketApi. @@ -34,35 +34,35 @@ class BasketService * @var NotificationServiceContract */ private $notificationService; - /** - * @var SalesPriceRepositoryContract - */ - private $priceRepo; /** * @var AuthHelper */ private $authHelper; + /** + * @var ItemRepositoryContract + */ + private $itemRepo; /** * BasketService constructor. * @param LibService $libraryService * @param MainConfigContract $config * @param NotificationServiceContract $notificationService - * @param SalesPriceRepositoryContract $priceRepo + * @param ItemRepositoryContract $itemRepo * @param AuthHelper $authHelper */ public function __construct( LibService $libraryService, MainConfigContract $config, NotificationServiceContract $notificationService, - SalesPriceRepositoryContract $priceRepo, + ItemRepositoryContract $itemRepo, AuthHelper $authHelper ) { $this->libService = $libraryService; $this->config = $config; $this->notificationService = $notificationService; - $this->priceRepo = $priceRepo; $this->authHelper = $authHelper; + $this->itemRepo = $itemRepo; } /** @@ -84,16 +84,16 @@ public function requestBasketId(Basket $basket, array $authData): string $params['basket'] = $basket->toArray(); $items = []; - foreach ($basket->basketItems as $item) { - /** @var BasketItem $item */ - $price = $this->authHelper->processUnguarded( - function () use ($item) { - return $this->priceRepo->findById($item->priceId); + foreach ($basket->basketItems as $basketItem) { + /** @var BasketItem $basketItem */ + $item = $this->authHelper->processUnguarded( + function () use ($basketItem) { + return $this->itemRepo->show($basketItem->itemId); } ); - $items[] = $item->toArray(); + $items[] = $basketItem->toArray(); - $this->notificationService->error('basket item', __METHOD__, ['item' => $item, 'price' => $price]); + $this->notificationService->error('basket basketItem', __METHOD__, ['basketItem' => $basketItem, 'item' => $item]); } From 1d9b6ebcb49e9ceddf96177207f4e7313df13d0a Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 17:24:21 +0100 Subject: [PATCH 56/70] [feature] (PLENTY-88) NGW-IVsec: Debug set amount per unit. --- resources/lib/submitBasket.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index f6dbc44..da3f248 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -35,13 +35,16 @@ function normalizeValue($value) { foreach ($basketItems as $item) { $basketItem = new BasketItem(); - $amount = normalizeValue($item['price']); + $quantity = $item['quantity']; + $amountPerUnit = $item['price']; + $amount = normalizeValue($amountPerUnit * $quantity); $vat = $item['vat']; $basketItem->setAmountGross($amount); $basketItem->setAmountNet(normalizeValue($amount / (100 + $vat))); $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); - $basketItem->setQuantity((int)$item['quantity']); + $basketItem->setQuantity($quantity); $basketItem->setVat(normalizeValue($vat)); + $basketItem->setAmountPerUnit($amountPerUnit); $basketItem->setBasketItemReferenceId($item['id']); $basketItem->setTitle($item['id']); $basket->addBasketItem($basketItem); From cb8f211dd971e82d5209671e8ac1a7eace422bb5 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 17:37:18 +0100 Subject: [PATCH 57/70] [feature] (PLENTY-88) NGW-IVsec: Add item title to basket request. --- resources/lib/submitBasket.php | 2 +- src/Services/BasketService.php | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index da3f248..c9ae2b0 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -46,7 +46,7 @@ function normalizeValue($value) { $basketItem->setVat(normalizeValue($vat)); $basketItem->setAmountPerUnit($amountPerUnit); $basketItem->setBasketItemReferenceId($item['id']); - $basketItem->setTitle($item['id']); + $basketItem->setTitle($item['title']); $basket->addBasketItem($basketItem); } diff --git a/src/Services/BasketService.php b/src/Services/BasketService.php index 0d0d77d..88ee76d 100755 --- a/src/Services/BasketService.php +++ b/src/Services/BasketService.php @@ -7,6 +7,7 @@ use Plenty\Modules\Basket\Models\Basket; use Plenty\Modules\Basket\Models\BasketItem; use Plenty\Modules\Item\Item\Contracts\ItemRepositoryContract; +use Plenty\Modules\Item\Item\Models\Item; /** * Provides connection to heidelpay basketApi. @@ -30,10 +31,6 @@ class BasketService * @var MainConfigContract */ private $config; - /** - * @var NotificationServiceContract - */ - private $notificationService; /** * @var AuthHelper */ @@ -47,20 +44,17 @@ class BasketService * BasketService constructor. * @param LibService $libraryService * @param MainConfigContract $config - * @param NotificationServiceContract $notificationService * @param ItemRepositoryContract $itemRepo * @param AuthHelper $authHelper */ public function __construct( LibService $libraryService, MainConfigContract $config, - NotificationServiceContract $notificationService, ItemRepositoryContract $itemRepo, AuthHelper $authHelper ) { $this->libService = $libraryService; $this->config = $config; - $this->notificationService = $notificationService; $this->authHelper = $authHelper; $this->itemRepo = $itemRepo; } @@ -86,18 +80,17 @@ public function requestBasketId(Basket $basket, array $authData): string $items = []; foreach ($basket->basketItems as $basketItem) { /** @var BasketItem $basketItem */ - $item = $this->authHelper->processUnguarded( + /** @var Item $item */ + $item = $this->authHelper->processUnguarded( function () use ($basketItem) { return $this->itemRepo->show($basketItem->itemId); } ); - $items[] = $basketItem->toArray(); - - $this->notificationService->error('basket basketItem', __METHOD__, ['basketItem' => $basketItem, 'item' => $item]); + $itemArray = $basketItem->toArray(); + $itemArray['title'] = $item->texts[0]->name1; + $items[] = $itemArray; } - - $params['basketItems'] = $items; $params['sandboxmode'] = $this->config->isInSandboxMode(); $response = $this->libService->submitBasket($params); From 53f8e2706edd753beb38b0e3258528c5753655c0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 17:54:10 +0100 Subject: [PATCH 58/70] [feature] (PLENTY-88) NGW-IVsec: Fix net value. --- resources/lib/submitBasket.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index c9ae2b0..2fb2da8 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -36,15 +36,14 @@ function normalizeValue($value) { foreach ($basketItems as $item) { $basketItem = new BasketItem(); $quantity = $item['quantity']; - $amountPerUnit = $item['price']; - $amount = normalizeValue($amountPerUnit * $quantity); + $amount = normalizeValue($item['price'] * $quantity); $vat = $item['vat']; $basketItem->setAmountGross($amount); $basketItem->setAmountNet(normalizeValue($amount / (100 + $vat))); $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity($quantity); - $basketItem->setVat(normalizeValue($vat)); - $basketItem->setAmountPerUnit($amountPerUnit); + $basketItem->setVat($vat); + $basketItem->setAmountPerUnit(normalizeValue($item['price'])); $basketItem->setBasketItemReferenceId($item['id']); $basketItem->setTitle($item['title']); $basket->addBasketItem($basketItem); From 1f351bc241c7fe2dafceff7e035f6de7621de76b Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 18:11:58 +0100 Subject: [PATCH 59/70] [feature] (PLENTY-88) NGW-IVsec: Refactor basket values. --- resources/lib/submitBasket.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 2fb2da8..83ffe73 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -32,14 +32,17 @@ function normalizeValue($value) { $basket->setAmountTotalNet(normalizeValue($basketData['basketAmountNet'])); $basket->setAmountTotalDiscount(normalizeValue($basketData['basketRebate'])); $basket->setCurrencyCode($basketData['currency']); +$basketAmountVat = 0; foreach ($basketItems as $item) { $basketItem = new BasketItem(); $quantity = $item['quantity']; - $amount = normalizeValue($item['price'] * $quantity); + $amount = $item['price'] * $quantity; $vat = $item['vat']; - $basketItem->setAmountGross($amount); - $basketItem->setAmountNet(normalizeValue($amount / (100 + $vat))); + $amountVat = $amount * $vat; + $basketItem->setAmountGross(normalizeValue($amount)); + $basketItem->setAmountVat(normalizeValue($amountVat)); + $basketItem->setAmountNet(normalizeValue($amount * 100 / (100 + $vat))); $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity($quantity); $basketItem->setVat($vat); @@ -47,7 +50,10 @@ function normalizeValue($value) { $basketItem->setBasketItemReferenceId($item['id']); $basketItem->setTitle($item['title']); $basket->addBasketItem($basketItem); + + $basketAmountVat += $amountVat; } +$basket->setAmountTotalVat(normalizeValue($basketAmountVat)); $request = new BasketApiRequest(); $request->setAuthentication($authData['login'], $authData['password'], $authData['senderId']); From b4702915f8d3f95b932d1406dc6933aa5543be16 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 11 Mar 2019 18:20:33 +0100 Subject: [PATCH 60/70] [feature] (PLENTY-88) NGW-IVsec: Fix vat calculation. --- resources/lib/submitBasket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 83ffe73..c2370ce 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -39,7 +39,7 @@ function normalizeValue($value) { $quantity = $item['quantity']; $amount = $item['price'] * $quantity; $vat = $item['vat']; - $amountVat = $amount * $vat; + $amountVat = $amount * $vat / 100; $basketItem->setAmountGross(normalizeValue($amount)); $basketItem->setAmountVat(normalizeValue($amountVat)); $basketItem->setAmountNet(normalizeValue($amount * 100 / (100 + $vat))); From 39fe6735343c94c494f4960f3f0020994a55abc2 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 08:44:49 +0100 Subject: [PATCH 61/70] [feature] (PLENTY-88) NGW-IVsec: Fix vat calculation. --- resources/lib/submitBasket.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index c2370ce..7e5e158 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -39,10 +39,11 @@ function normalizeValue($value) { $quantity = $item['quantity']; $amount = $item['price'] * $quantity; $vat = $item['vat']; - $amountVat = $amount * $vat / 100; + $amountNet = $amount * 100 / (100 + $vat); + $amountVat = $amount - $amountNet; // $amountNet * $vat / 100; $basketItem->setAmountGross(normalizeValue($amount)); $basketItem->setAmountVat(normalizeValue($amountVat)); - $basketItem->setAmountNet(normalizeValue($amount * 100 / (100 + $vat))); + $basketItem->setAmountNet(normalizeValue($amountNet)); $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); $basketItem->setQuantity($quantity); $basketItem->setVat($vat); From 0dae0299b7ad4826b9a556eed2ed28509eebcc19 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 09:13:28 +0100 Subject: [PATCH 62/70] [feature] (PLENTY-88) NGW-IVsec: Add shipping position. --- resources/lib/submitBasket.php | 40 ++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 7e5e158..f6cd653 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -29,9 +29,9 @@ function normalizeValue($value) { $sandboxmode = SdkRestApi::getParam('sandboxmode'); $basket = new \Heidelpay\PhpBasketApi\Object\Basket(); -$basket->setAmountTotalNet(normalizeValue($basketData['basketAmountNet'])); -$basket->setAmountTotalDiscount(normalizeValue($basketData['basketRebate'])); -$basket->setCurrencyCode($basketData['currency']); +$basket->setAmountTotalNet(normalizeValue($basketData['basketAmountNet'])) + ->setAmountTotalDiscount(normalizeValue($basketData['basketRebate'])) + ->setCurrencyCode($basketData['currency']); $basketAmountVat = 0; foreach ($basketItems as $item) { @@ -41,19 +41,35 @@ function normalizeValue($value) { $vat = $item['vat']; $amountNet = $amount * 100 / (100 + $vat); $amountVat = $amount - $amountNet; // $amountNet * $vat / 100; - $basketItem->setAmountGross(normalizeValue($amount)); - $basketItem->setAmountVat(normalizeValue($amountVat)); - $basketItem->setAmountNet(normalizeValue($amountNet)); - $basketItem->setAmountDiscount(normalizeValue($item['rebate'])); - $basketItem->setQuantity($quantity); - $basketItem->setVat($vat); - $basketItem->setAmountPerUnit(normalizeValue($item['price'])); - $basketItem->setBasketItemReferenceId($item['id']); - $basketItem->setTitle($item['title']); + $basketItem->setAmountGross(normalizeValue($amount)) + ->setAmountVat(normalizeValue($amountVat)) + ->setAmountNet(normalizeValue($amountNet)) + ->setAmountDiscount(normalizeValue($item['rebate'])) + ->setQuantity($quantity) + ->setVat($vat) + ->setAmountPerUnit(normalizeValue($item['price'])) + ->setBasketItemReferenceId($item['id']) + ->setTitle($item['title']); $basket->addBasketItem($basketItem); $basketAmountVat += $amountVat; } + +// Add shipping position +$shipping = new BasketItem(); +$shippingAmount = $basketData['shippingAmount']; +$shippingNet = $basketData['shippingAmountNet']; +$shippingVat = $shippingAmount - $shippingNet; +$shipping->setAmountGross(normalizeValue($shippingAmount)) + ->setAmountNet(normalizeValue($shippingNet)) + ->setAmountVat(normalizeValue($shippingVat)) + ->setQuantity(1) + ->setAmountPerUnit(normalizeValue($shippingAmount)) + ->setBasketItemReferenceId('shipping') + ->setTitle('Shipping'); +$basket->addBasketItem($shipping); +$basketAmountVat += $shippingVat; + $basket->setAmountTotalVat(normalizeValue($basketAmountVat)); $request = new BasketApiRequest(); From 97badc6ef0763cd7c93875324baa4bd52b762571 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 11:12:21 +0100 Subject: [PATCH 63/70] [feature] (PLENTY-88) NGW-IVsec: Add discount position. --- resources/lib/submitBasket.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index f6cd653..5553062 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -70,6 +70,17 @@ function normalizeValue($value) { $basket->addBasketItem($shipping); $basketAmountVat += $shippingVat; +// Add shipping position +$rebate = new BasketItem(); +$discountAmount = $basketData['couponDiscount']; +$rebate->setAmountGross(normalizeValue($discountAmount)) + ->setAmountNet(normalizeValue($discountAmount)) + ->setQuantity(1) + ->setAmountPerUnit(normalizeValue($discountAmount)) + ->setBasketItemReferenceId('discount') + ->setTitle('Discount'); +$basket->addBasketItem($rebate); + $basket->setAmountTotalVat(normalizeValue($basketAmountVat)); $request = new BasketApiRequest(); From edfdfd50ac24b2a54583ae589f73e6cb909b483c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 11:47:37 +0100 Subject: [PATCH 64/70] [feature] (PLENTY-88) NGW-IVsec: Fix basket amounts. --- resources/lib/submitBasket.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 5553062..4d2a615 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -29,10 +29,14 @@ function normalizeValue($value) { $sandboxmode = SdkRestApi::getParam('sandboxmode'); $basket = new \Heidelpay\PhpBasketApi\Object\Basket(); -$basket->setAmountTotalNet(normalizeValue($basketData['basketAmountNet'])) - ->setAmountTotalDiscount(normalizeValue($basketData['basketRebate'])) - ->setCurrencyCode($basketData['currency']); -$basketAmountVat = 0; +$basketAmount = $basketData['basketAmount']; +$basketAmountNet = $basketData['basketAmountNet']; +$basketAmountVat = $basketAmount - $basketAmountNet; +$basketDiscount = $basketData['couponDiscount']; +$basket->setAmountTotalNet(normalizeValue($basketAmountNet)) + ->setAmountTotalDiscount(normalizeValue($basketDiscount)) + ->setCurrencyCode($basketData['currency']) + ->setAmountTotalVat(normalizeValue($basketAmountVat)); foreach ($basketItems as $item) { $basketItem = new BasketItem(); @@ -51,8 +55,6 @@ function normalizeValue($value) { ->setBasketItemReferenceId($item['id']) ->setTitle($item['title']); $basket->addBasketItem($basketItem); - - $basketAmountVat += $amountVat; } // Add shipping position @@ -68,11 +70,10 @@ function normalizeValue($value) { ->setBasketItemReferenceId('shipping') ->setTitle('Shipping'); $basket->addBasketItem($shipping); -$basketAmountVat += $shippingVat; -// Add shipping position +// Add discount position $rebate = new BasketItem(); -$discountAmount = $basketData['couponDiscount']; +$discountAmount = $basketDiscount; $rebate->setAmountGross(normalizeValue($discountAmount)) ->setAmountNet(normalizeValue($discountAmount)) ->setQuantity(1) @@ -81,8 +82,6 @@ function normalizeValue($value) { ->setTitle('Discount'); $basket->addBasketItem($rebate); -$basket->setAmountTotalVat(normalizeValue($basketAmountVat)); - $request = new BasketApiRequest(); $request->setAuthentication($authData['login'], $authData['password'], $authData['senderId']); $request->setIsSandboxMode($sandboxmode); From ddfb5f260a11cb9a24914e2841210809dc7819c7 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 12:00:47 +0100 Subject: [PATCH 65/70] [feature] (PLENTY-88) NGW-IVsec: Fix basket amounts. --- resources/lib/submitBasket.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 4d2a615..cfa00f0 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -34,7 +34,7 @@ function normalizeValue($value) { $basketAmountVat = $basketAmount - $basketAmountNet; $basketDiscount = $basketData['couponDiscount']; $basket->setAmountTotalNet(normalizeValue($basketAmountNet)) - ->setAmountTotalDiscount(normalizeValue($basketDiscount)) + ->setAmountTotalDiscount($basketDiscount) ->setCurrencyCode($basketData['currency']) ->setAmountTotalVat(normalizeValue($basketAmountVat)); @@ -72,15 +72,17 @@ function normalizeValue($value) { $basket->addBasketItem($shipping); // Add discount position -$rebate = new BasketItem(); +$discountItem = new BasketItem(); $discountAmount = $basketDiscount; -$rebate->setAmountGross(normalizeValue($discountAmount)) +$discountItem->setAmountGross(normalizeValue($discountAmount)) ->setAmountNet(normalizeValue($discountAmount)) ->setQuantity(1) ->setAmountPerUnit(normalizeValue($discountAmount)) ->setBasketItemReferenceId('discount') - ->setTitle('Discount'); -$basket->addBasketItem($rebate); + ->setTitle('Discount') + ->setVat(0); + +$basket->addBasketItem($discountItem); $request = new BasketApiRequest(); $request->setAuthentication($authData['login'], $authData['password'], $authData['senderId']); From 726c6ed8fd15e74992d4befccf15b290fc8c8689 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 12:47:17 +0100 Subject: [PATCH 66/70] [feature] (PLENTY-88) NGW-IVsec: Fix discount net. --- resources/lib/submitBasket.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index cfa00f0..1b6a79c 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -16,7 +16,7 @@ use Heidelpay\PhpBasketApi\Request as BasketApiRequest; function normalizeValue($value) { - return (int)round($value * 100); + return (int)round(abs($value) * 100); } /** @var array $authData */ @@ -37,6 +37,7 @@ function normalizeValue($value) { ->setAmountTotalDiscount($basketDiscount) ->setCurrencyCode($basketData['currency']) ->setAmountTotalVat(normalizeValue($basketAmountVat)); +$goodsAndShipmentNet = 0; foreach ($basketItems as $item) { $basketItem = new BasketItem(); @@ -53,8 +54,10 @@ function normalizeValue($value) { ->setVat($vat) ->setAmountPerUnit(normalizeValue($item['price'])) ->setBasketItemReferenceId($item['id']) - ->setTitle($item['title']); + ->setTitle($item['title']) + ->setType($item['goods']); $basket->addBasketItem($basketItem); + $goodsAndShipmentNet += $amountNet; } // Add shipping position @@ -67,20 +70,23 @@ function normalizeValue($value) { ->setAmountVat(normalizeValue($shippingVat)) ->setQuantity(1) ->setAmountPerUnit(normalizeValue($shippingAmount)) - ->setBasketItemReferenceId('shipping') - ->setTitle('Shipping'); + ->setBasketItemReferenceId('shipment') + ->setTitle('Shipment') + ->setType('shipment'); $basket->addBasketItem($shipping); +$goodsAndShipmentNet += $shippingNet; // Add discount position $discountItem = new BasketItem(); $discountAmount = $basketDiscount; +$discountNet = $basketAmountNet - $goodsAndShipmentNet; $discountItem->setAmountGross(normalizeValue($discountAmount)) - ->setAmountNet(normalizeValue($discountAmount)) + ->setAmountNet(normalizeValue($discountNet)) ->setQuantity(1) ->setAmountPerUnit(normalizeValue($discountAmount)) ->setBasketItemReferenceId('discount') ->setTitle('Discount') - ->setVat(0); + ->setType('voucher'); $basket->addBasketItem($discountItem); From c62c768e19bc84fba6643fd32a13656a79a7fc3b Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 13:57:27 +0100 Subject: [PATCH 67/70] [feature] (PLENTY-88) NGW-IVsec: Fix setting goods type. --- resources/lib/submitBasket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 1b6a79c..c171f97 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -55,7 +55,7 @@ function normalizeValue($value) { ->setAmountPerUnit(normalizeValue($item['price'])) ->setBasketItemReferenceId($item['id']) ->setTitle($item['title']) - ->setType($item['goods']); + ->setType('goods'); $basket->addBasketItem($basketItem); $goodsAndShipmentNet += $amountNet; } From e3935aaa1af88208fad7ab1f5b54b21e0a679c8e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 14:07:32 +0100 Subject: [PATCH 68/70] [feature] (PLENTY-88) NGW-IVsec: Fix setting total discount. --- resources/lib/submitBasket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index c171f97..91d1dc3 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -34,7 +34,7 @@ function normalizeValue($value) { $basketAmountVat = $basketAmount - $basketAmountNet; $basketDiscount = $basketData['couponDiscount']; $basket->setAmountTotalNet(normalizeValue($basketAmountNet)) - ->setAmountTotalDiscount($basketDiscount) + ->setAmountTotalDiscount(normalizeValue($basketDiscount)) ->setCurrencyCode($basketData['currency']) ->setAmountTotalVat(normalizeValue($basketAmountVat)); $goodsAndShipmentNet = 0; From 18f5a8a9d6de464b6d12fa6e8edae5155a38bb20 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 14:31:45 +0100 Subject: [PATCH 69/70] [feature] (PLENTY-88) NGW-IVsec: Remove total discount. --- resources/lib/submitBasket.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index 91d1dc3..f1b4af2 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -32,9 +32,7 @@ function normalizeValue($value) { $basketAmount = $basketData['basketAmount']; $basketAmountNet = $basketData['basketAmountNet']; $basketAmountVat = $basketAmount - $basketAmountNet; -$basketDiscount = $basketData['couponDiscount']; $basket->setAmountTotalNet(normalizeValue($basketAmountNet)) - ->setAmountTotalDiscount(normalizeValue($basketDiscount)) ->setCurrencyCode($basketData['currency']) ->setAmountTotalVat(normalizeValue($basketAmountVat)); $goodsAndShipmentNet = 0; @@ -78,7 +76,7 @@ function normalizeValue($value) { // Add discount position $discountItem = new BasketItem(); -$discountAmount = $basketDiscount; +$discountAmount = $basketData['couponDiscount']; $discountNet = $basketAmountNet - $goodsAndShipmentNet; $discountItem->setAmountGross(normalizeValue($discountAmount)) ->setAmountNet(normalizeValue($discountNet)) From 5df403bbd59d9c0abe812532998dd24fbb06b93f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 12 Mar 2019 14:53:13 +0100 Subject: [PATCH 70/70] [feature] (PLENTY-88) NGW-IVsec: Only show discount position in basket if it is set. --- resources/lib/submitBasket.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/resources/lib/submitBasket.php b/resources/lib/submitBasket.php index f1b4af2..b87568c 100755 --- a/resources/lib/submitBasket.php +++ b/resources/lib/submitBasket.php @@ -75,18 +75,20 @@ function normalizeValue($value) { $goodsAndShipmentNet += $shippingNet; // Add discount position -$discountItem = new BasketItem(); $discountAmount = $basketData['couponDiscount']; -$discountNet = $basketAmountNet - $goodsAndShipmentNet; -$discountItem->setAmountGross(normalizeValue($discountAmount)) - ->setAmountNet(normalizeValue($discountNet)) - ->setQuantity(1) - ->setAmountPerUnit(normalizeValue($discountAmount)) - ->setBasketItemReferenceId('discount') - ->setTitle('Discount') - ->setType('voucher'); +if ($discountAmount !== 0) { + $discountItem = new BasketItem(); + $discountNet = $basketAmountNet - $goodsAndShipmentNet; + $discountItem->setAmountGross(normalizeValue($discountAmount)) + ->setAmountNet(normalizeValue($discountNet)) + ->setQuantity(1) + ->setAmountPerUnit(normalizeValue($discountAmount)) + ->setBasketItemReferenceId('discount') + ->setTitle('Discount') + ->setType('voucher'); -$basket->addBasketItem($discountItem); + $basket->addBasketItem($discountItem); +} $request = new BasketApiRequest(); $request->setAuthentication($authData['login'], $authData['password'], $authData['senderId']);