From 3688cbcab7ca40da6ba51cff47dc0b1c2873a888 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 15 Feb 2021 13:01:00 +0100 Subject: [PATCH 1/8] [fix] (MAGE2-323) Update readme. --- CHANGELOG.md | 6 ++++++ etc/module.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09c8612..1296e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.0.2][1.0.2] +### Fix +* Billing address not changeable in checkout. +* Checkout not possible with virtual quotes. + ## [1.0.1][1.0.1] ### Added * php 7.4 support. @@ -15,3 +20,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.0.0]: https://github.com/heidelpay/magento2-merchant-gateway/tree/1.0.0 [1.0.1]: https://github.com/heidelpay/magento2-merchant-gateway/compare/1.0.0..1.0.1 +[1.0.2]: https://github.com/heidelpay/magento2-merchant-gateway/compare/1.0.1..1.0.2 diff --git a/etc/module.xml b/etc/module.xml index a57503e..02ef32f 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - + From 83c84bcd3cbd0cdf14e1135d56d89f58449b248d Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 18 Jun 2021 14:34:24 +0200 Subject: [PATCH 2/8] [fix] disable PAPI-customer creation before order. --- Helper/Order.php | 7 ++-- .../js/view/payment/method-renderer/base.js | 39 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Helper/Order.php b/Helper/Order.php index ca723f3..08626d5 100644 --- a/Helper/Order.php +++ b/Helper/Order.php @@ -165,11 +165,12 @@ public function createMetadataForOrder(OrderModel $order): Metadata * * @param Quote $quote * @param string $email + * @param bool $create + * * @return Customer * @throws HeidelpayApiException - * @throws NoSuchEntityException */ - public function createCustomerFromQuote(Quote $quote, string $email): ?Customer + public function createCustomerFromQuote(Quote $quote, string $email, bool $create = false): ?Customer { // A virtual quote does not have any customer data other than E-Mail so we can't create a customer object. if ($quote->isVirtual()) { @@ -200,7 +201,7 @@ public function createCustomerFromQuote(Quote $quote, string $email): ?Customer /** @var Heidelpay $client */ $client = $this->_moduleConfig->getHeidelpayClient(); - return $client->createCustomer($customer); + return $create ? $client->createCustomer($customer) : $customer; } /** diff --git a/view/frontend/web/js/view/payment/method-renderer/base.js b/view/frontend/web/js/view/payment/method-renderer/base.js index c0375c5..cb6933f 100644 --- a/view/frontend/web/js/view/payment/method-renderer/base.js +++ b/view/frontend/web/js/view/payment/method-renderer/base.js @@ -88,15 +88,12 @@ define( _initializeCustomerFormForB2bCustomer: function (fieldId, errorFieldId, customer) { this.customerProvider = this.sdk.B2BCustomer(); this.customerProvider.initFormFields(customer); - this.customerProvider.update( - customer.id, - { - containerId: fieldId, - errorHolderId: errorFieldId, - fields: ['companyInfo'], - showHeader: false - } - ); + this.customerProvider.create({ + containerId: fieldId, + errorHolderId: errorFieldId, + fields: ['companyInfo'], + showHeader: false + }); // The SDK currently always shows these fields, although we don't specify them in the options above. // Hide them manually since users are not allowed to change them anyways. @@ -108,16 +105,13 @@ define( _initializeCustomerFormForB2cCustomer: function (fieldId, errorFieldId, customer) { this.customerProvider = this.sdk.Customer(); this.customerProvider.initFormFields(customer); - this.customerProvider.update( - customer.id, - { - infoBoxText: $t('Your date of birth'), - containerId: fieldId, - errorHolderId: errorFieldId, - fields: ['birthdate'], - showHeader: false - } - ); + this.customerProvider.create({ + infoBoxText: $t('Your date of birth'), + containerId: fieldId, + errorHolderId: errorFieldId, + /*fields: ['birthdate'],*/ + showHeader: false + }); }, initializeForm: function () { @@ -129,6 +123,7 @@ define( }, getData: function () { + //console.log(this.customer); return { 'method': this.item.method, 'po_number': null, @@ -145,7 +140,7 @@ define( self = this; if (this.customerProvider) { - promises = [this.resourceProvider.createResource(), this.customerProvider.updateCustomer()]; + promises = [this.resourceProvider.createResource(), this.customerProvider.createCustomer()]; } else { promises = [this.resourceProvider.createResource()]; } @@ -160,6 +155,10 @@ define( Promise.all(promises).then( function (values) { self.resourceId = values[0].id; + if (self.customer && values[1]) { + self.customer.id = values[1].id + } + console.log(values[1]) placeOrderAction(self.getData(), self.messageContainer) .done(function () { From 046d00aaaf5567f24ccbe610e19825e2428d54bf Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 18 Jun 2021 18:29:21 +0200 Subject: [PATCH 3/8] [fix] customer creation: - create customer in backend only if no customer id was handed over right before transaction. - fix customer handling in frontend - hide input fields for invoice form that are not needed. --- Helper/Order.php | 78 +++++++++++++++++-- Model/Command/AbstractCommand.php | 9 +++ .../js/view/payment/method-renderer/base.js | 11 +-- 3 files changed, 88 insertions(+), 10 deletions(-) diff --git a/Helper/Order.php b/Helper/Order.php index 08626d5..5f983cd 100644 --- a/Helper/Order.php +++ b/Helper/Order.php @@ -165,12 +165,12 @@ public function createMetadataForOrder(OrderModel $order): Metadata * * @param Quote $quote * @param string $email - * @param bool $create + * @param bool $createResource * * @return Customer * @throws HeidelpayApiException */ - public function createCustomerFromQuote(Quote $quote, string $email, bool $create = false): ?Customer + public function createCustomerFromQuote(Quote $quote, string $email, bool $createResource = false): ?Customer { // A virtual quote does not have any customer data other than E-Mail so we can't create a customer object. if ($quote->isVirtual()) { @@ -201,7 +201,65 @@ public function createCustomerFromQuote(Quote $quote, string $email, bool $creat /** @var Heidelpay $client */ $client = $this->_moduleConfig->getHeidelpayClient(); - return $create ? $client->createCustomer($customer) : $customer; + return $createResource ? $client->createCustomer($customer) : $customer; + } + + /** + * Returns a new or updated Heidelpay Customer resource for the given quote. + * + * @param OrderModel $order + * @param string $email + * @param bool $createResource + * + * @return Customer + * @throws HeidelpayApiException + */ + public function createCustomerFromOrder(OrderModel $order, string $email, bool $createResource = false): ?Customer + { + /** @var Heidelpay $client */ + $client = $this->_moduleConfig->getHeidelpayClient(); + $client->debugLog('createCostomerFromOder'); + + + // A virtual quote does not have any customer data other than E-Mail so we can't create a customer object. + /*if ($order->getIsNotVirtual()) { + return null; + }*/ + + /** @var Quote\Address $billingAddress */ + $billingAddress = $order->getBillingAddress(); + + $client->debugLog('create customer instance'); + + /** @var Customer $customer */ + $customer = CustomerFactory::createCustomer( + $billingAddress->getFirstname(), + $billingAddress->getLastname() + ); + + $client->debugLog('set salutation'); + $gender = $order->getCustomerGender(); + $customer->setSalutation($this->getSalutationFromGender($gender)); + + $client->debugLog('set email'); + $customer->setEmail($email); + + $client->debugLog('set phone'); + $customer->setPhone($billingAddress->getTelephone()); + + $client->debugLog('set company'); + + $company = $billingAddress->getCompany(); + if (!empty($company)) { + $customer->setCompany($company); + } + + $this->updateGatewayAddressFromMagento($customer->getBillingAddress(), $billingAddress); + $this->updateGatewayAddressFromMagento($customer->getShippingAddress(), $order->getShippingAddress()); + + $client->debugLog('before customer creation'); + + return $createResource ? $client->createCustomer($customer) : $customer; } /** @@ -321,7 +379,17 @@ private function validateGatewayAddressAgainstOrderAddress( */ protected function getSalutationFromQuote(Quote $quote): string { - switch ($quote->getCustomer()->getGender()) { + return $this->getSalutationFromGender($quote->getCustomer()->getGender()); + } + + /** + * @param float | int $gender + * + * @return string + */ + protected function getSalutationFromGender($gender): string + { + switch ($gender) { case self::GENDER_MALE: $salutation = Salutations::MR; break; @@ -332,5 +400,5 @@ protected function getSalutationFromQuote(Quote $quote): string $salutation = Salutations::UNKNOWN; } return $salutation; - } +} } diff --git a/Model/Command/AbstractCommand.php b/Model/Command/AbstractCommand.php index 538292d..f58e864 100644 --- a/Model/Command/AbstractCommand.php +++ b/Model/Command/AbstractCommand.php @@ -149,6 +149,15 @@ protected function _getCustomerId(InfoInterface $payment, \Magento\Sales\Model\O /** @var string|null $customerId */ $customerId = $payment->getAdditionalInformation(BaseDataAssignObserver::KEY_CUSTOMER_ID); + if (empty($customerId)) { + try { + $papiCustomer = $this->_orderHelper->createCustomerFromOrder($order, $order->getCustomerEmail(), true); + } catch (\Exception $exception) { + $this->_getClient()->getDebugHandler()->log('Customer Creation failed'); + } + $customerId = $papiCustomer->getId(); + } + if (empty($customerId)) { return null; } diff --git a/view/frontend/web/js/view/payment/method-renderer/base.js b/view/frontend/web/js/view/payment/method-renderer/base.js index cb6933f..a18a4b5 100644 --- a/view/frontend/web/js/view/payment/method-renderer/base.js +++ b/view/frontend/web/js/view/payment/method-renderer/base.js @@ -109,9 +109,12 @@ define( infoBoxText: $t('Your date of birth'), containerId: fieldId, errorHolderId: errorFieldId, - /*fields: ['birthdate'],*/ showHeader: false }); + + var field = $('#' + fieldId); + field.find('.field').filter('.city, .company, :has(.country), .street, .zip, .firstname, .lastname').hide(); + field.find('.heidelpayUI.divider-horizontal:eq(0)').hide(); }, initializeForm: function () { @@ -123,7 +126,6 @@ define( }, getData: function () { - //console.log(this.customer); return { 'method': this.item.method, 'po_number': null, @@ -155,10 +157,9 @@ define( Promise.all(promises).then( function (values) { self.resourceId = values[0].id; - if (self.customer && values[1]) { - self.customer.id = values[1].id + if (self.customer() && values[1]) { + self.customer().id = values[1].id } - console.log(values[1]) placeOrderAction(self.getData(), self.messageContainer) .done(function () { From 1ce72628b3aa7f41715932ab4635106c14bc51d8 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 21 Jun 2021 17:12:31 +0200 Subject: [PATCH 4/8] [fix] customer creation: - hide infobox of customer field. --- view/frontend/web/js/view/payment/method-renderer/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/base.js b/view/frontend/web/js/view/payment/method-renderer/base.js index a18a4b5..05fac76 100644 --- a/view/frontend/web/js/view/payment/method-renderer/base.js +++ b/view/frontend/web/js/view/payment/method-renderer/base.js @@ -106,7 +106,6 @@ define( this.customerProvider = this.sdk.Customer(); this.customerProvider.initFormFields(customer); this.customerProvider.create({ - infoBoxText: $t('Your date of birth'), containerId: fieldId, errorHolderId: errorFieldId, showHeader: false @@ -115,6 +114,7 @@ define( var field = $('#' + fieldId); field.find('.field').filter('.city, .company, :has(.country), .street, .zip, .firstname, .lastname').hide(); field.find('.heidelpayUI.divider-horizontal:eq(0)').hide(); + field.find('.heidelpayUI.message.downArrow').hide(); }, initializeForm: function () { From cc17d1b18e1e12ac70e7bf8d937f2f56a091f9df Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 21 Jun 2021 17:56:17 +0200 Subject: [PATCH 5/8] [fix] customer creation: - set name, email and country correctly for addresses. - hide infobox of customer field. - removed log entries and --- Helper/Order.php | 53 ++++++++++++++----------------- Model/Command/AbstractCommand.php | 5 +-- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/Helper/Order.php b/Helper/Order.php index 5f983cd..0889480 100644 --- a/Helper/Order.php +++ b/Helper/Order.php @@ -218,46 +218,31 @@ public function createCustomerFromOrder(OrderModel $order, string $email, bool $ { /** @var Heidelpay $client */ $client = $this->_moduleConfig->getHeidelpayClient(); - $client->debugLog('createCostomerFromOder'); - - // A virtual quote does not have any customer data other than E-Mail so we can't create a customer object. - /*if ($order->getIsNotVirtual()) { - return null; - }*/ - - /** @var Quote\Address $billingAddress */ $billingAddress = $order->getBillingAddress(); - $client->debugLog('create customer instance'); - /** @var Customer $customer */ $customer = CustomerFactory::createCustomer( $billingAddress->getFirstname(), $billingAddress->getLastname() ); - $client->debugLog('set salutation'); $gender = $order->getCustomerGender(); $customer->setSalutation($this->getSalutationFromGender($gender)); - - $client->debugLog('set email'); $customer->setEmail($email); - - $client->debugLog('set phone'); $customer->setPhone($billingAddress->getTelephone()); - $client->debugLog('set company'); - $company = $billingAddress->getCompany(); if (!empty($company)) { $customer->setCompany($company); } $this->updateGatewayAddressFromMagento($customer->getBillingAddress(), $billingAddress); - $this->updateGatewayAddressFromMagento($customer->getShippingAddress(), $order->getShippingAddress()); - $client->debugLog('before customer creation'); + $shippingAddress = $order->getShippingAddress(); + if($shippingAddress) { + $this->updateGatewayAddressFromMagento($customer->getShippingAddress(), $shippingAddress); + } return $createResource ? $client->createCustomer($customer) : $customer; } @@ -275,8 +260,9 @@ private function updateGatewayAddressFromMagento( { $street = $this->convertStreetLinesToString($magentoAddress->getStreet()); + $gatewayAddress->setName($magentoAddress->getName()); $gatewayAddress->setCity($magentoAddress->getCity()); - $gatewayAddress->setCountry($magentoAddress->getCountry()); + $gatewayAddress->setCountry($magentoAddress->getCountryId()); $gatewayAddress->setStreet($street); $gatewayAddress->setZip($magentoAddress->getPostcode()); } @@ -306,16 +292,20 @@ public function updateGatewayCustomerFromOrder(OrderModel $order, Customer $gate $gatewayCustomer->setLastname($billingAddress->getLastname()); $gatewayCustomer->setCompany($billingAddress->getCompany()); + $gatewayCustomer->setEmail($billingAddress->getEmail()); $this->updateGatewayAddressFromMagento( $gatewayCustomer->getBillingAddress(), $billingAddress ); - $this->updateGatewayAddressFromMagento( - $gatewayCustomer->getShippingAddress(), - $order->getShippingAddress() - ); + $magentoShippingAddress = $order->getShippingAddress(); + if (null !== $magentoShippingAddress) { + $this->updateGatewayAddressFromMagento( + $gatewayCustomer->getShippingAddress(), + $magentoShippingAddress + ); + } $client = $this->_moduleConfig->getHeidelpayClient(); $client->updateCustomer($gatewayCustomer); @@ -336,18 +326,23 @@ public function validateGatewayCustomerAgainstOrder(OrderModel $order, Customer // Magento's getCompany() always returns a string, but the heidelpay Customer Address does not, so we must make // sure that both have the same type. $companyValid = ($order->getBillingAddress()->getCompany() ?? '') === ($gatewayCustomer->getCompany() ?? ''); + $emailValid = $order->getCustomerEmail() === $gatewayCustomer->getEmail(); $billingAddressValid = $this->validateGatewayAddressAgainstOrderAddress( $gatewayCustomer->getBillingAddress(), $order->getBillingAddress() ); - $shippingAddressValid = $this->validateGatewayAddressAgainstOrderAddress( - $gatewayCustomer->getShippingAddress(), - $order->getShippingAddress() - ); + $shippingAddress = $order->getShippingAddress(); + $shippingAddressValid = true; + if($shippingAddress !== null) { + $shippingAddressValid = $this->validateGatewayAddressAgainstOrderAddress( + $gatewayCustomer->getShippingAddress(), + $shippingAddress + ); + } - return $nameValid && $companyValid && $billingAddressValid && $shippingAddressValid; + return $nameValid && $companyValid && $billingAddressValid && $shippingAddressValid && $emailValid; } /** diff --git a/Model/Command/AbstractCommand.php b/Model/Command/AbstractCommand.php index f58e864..2525a88 100644 --- a/Model/Command/AbstractCommand.php +++ b/Model/Command/AbstractCommand.php @@ -5,6 +5,7 @@ use Heidelpay\MGW\Helper\Order; use Heidelpay\MGW\Model\Config; use Heidelpay\MGW\Model\Method\Observer\BaseDataAssignObserver; +use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\AbstractHeidelpayResource; use heidelpayPHP\Resources\Customer; @@ -152,10 +153,10 @@ protected function _getCustomerId(InfoInterface $payment, \Magento\Sales\Model\O if (empty($customerId)) { try { $papiCustomer = $this->_orderHelper->createCustomerFromOrder($order, $order->getCustomerEmail(), true); + $customerId = $papiCustomer->getId(); } catch (\Exception $exception) { - $this->_getClient()->getDebugHandler()->log('Customer Creation failed'); + $customerId = null; } - $customerId = $papiCustomer->getId(); } if (empty($customerId)) { From 12f621c4e96adaa8cc71e99b648fda42717428b7 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 21 Jun 2021 18:10:52 +0200 Subject: [PATCH 6/8] [fix] update changelog for version 1.1.2 --- CHANGELOG.md | 11 +++++++++++ etc/module.xml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7fe30d..65cee68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.1.2][1.1.2] +### Fix +* Payment customer + * Customer resource was created to early in checkout before order was placed. + * Customer data were missing when ordering with a virtual quote. + * Missing customer-email when ordering with invoice secured and direct debit secured. + +### Added +* Payment method asks for salutation when needed. + ## [1.1.1][1.1.1] ### Fix * Incompatibility with magento 2.3.x causing DI compilation to fail. @@ -31,3 +41,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.0.2]: https://github.com/heidelpay/magento2-merchant-gateway/compare/1.0.1..1.0.2 [1.1.0]: https://github.com/heidelpay/magento2-merchant-gateway/compare/1.0.2..1.1.0 [1.1.1]: https://github.com/heidelpay/magento2-merchant-gateway/compare/1.1.0..1.1.1 +[1.1.2]: https://github.com/heidelpay/magento2-merchant-gateway/compare/1.1.1..1.1.2 diff --git a/etc/module.xml b/etc/module.xml index abe0c28..df874f7 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - + From 8b369ca36209ccd0ef2cc904ab5b29488547ca39 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 21 Jun 2021 18:16:17 +0200 Subject: [PATCH 7/8] [fix] typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65cee68..b262b15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Fix * Payment customer * Customer resource was created to early in checkout before order was placed. - * Customer data were missing when ordering with a virtual quote. + * Customer data were missing when ordering with a virtual quote. * Missing customer-email when ordering with invoice secured and direct debit secured. ### Added From 96f30013b9524724a310ef8bb71c93be551d00d4 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 21 Jun 2021 18:55:23 +0200 Subject: [PATCH 8/8] [fix] typo --- Model/Command/AbstractCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Model/Command/AbstractCommand.php b/Model/Command/AbstractCommand.php index 2525a88..5dec720 100644 --- a/Model/Command/AbstractCommand.php +++ b/Model/Command/AbstractCommand.php @@ -5,7 +5,6 @@ use Heidelpay\MGW\Helper\Order; use Heidelpay\MGW\Model\Config; use Heidelpay\MGW\Model\Method\Observer\BaseDataAssignObserver; -use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\AbstractHeidelpayResource; use heidelpayPHP\Resources\Customer;