From 889e448172fef07e1157119d1a3f985cf5c5eade Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 6 May 2020 19:43:21 +0200 Subject: [PATCH 1/4] (MAGE2-316)[fix] Set expected orderstate after shipment for invoice payment methods. --- Controller/Adminhtml/Order/Shipment/Save.php | 12 ++++-------- PaymentMethods/HeidelpayAbstractPaymentMethod.php | 8 ++++++++ PaymentMethods/HeidelpayInvoicePaymentMethod.php | 11 +++++++++++ .../HeidelpayInvoiceSecuredPaymentMethod.php | 11 +++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Controller/Adminhtml/Order/Shipment/Save.php b/Controller/Adminhtml/Order/Shipment/Save.php index 7eb471390cd..48646b1306f 100755 --- a/Controller/Adminhtml/Order/Shipment/Save.php +++ b/Controller/Adminhtml/Order/Shipment/Save.php @@ -131,8 +131,8 @@ public function beforeExecute() // if the response isn't successful, redirect back to the order view. if (!$heidelpayMethod->getResponse()->isSuccess()) { - $this->messageManager->addErrorMessage( - __('Heidelpay Error at sending Finalize Request. The Shipment was not created.') + $this->messageManager->addWarningMessage( + __('Heidelpay Error at sending Finalize Request. The Shipment was created.') . ' Error Message: ' . $heidelpayMethod->getResponse()->getError()['message'] ); @@ -144,14 +144,10 @@ public function beforeExecute() $this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]); } - // set order state to "pending payment" - $state = Order::STATE_PENDING_PAYMENT; - $order->setState($state)->addStatusHistoryComment('heidelpay - Finalizing Order', true); - - $this->orderResository->save($order); - $this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.')); } + $method->setShippedOrderState($order); + $this->orderResository->save($order); } } } diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 70140f134e9..029fc837f9d 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -889,6 +889,14 @@ public function getUseShippingAddressAsBillingAddress() return $this->useShippingAddressAsBillingAddress; } + /** + * Define order status after shipment. + * @param $order + */ + public function setShippedOrderState(&$order) + { + } + /** * Load the payment information by store id, customer email address and payment method of the quote * diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 227cfd850b9..96cddc46295 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -108,4 +108,15 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $this->_paymentHelper->saveTransaction($invoice); } } + + /** + * @param Order $order + */ + public function setShippedOrderState(&$order) + { + if ($order->getTotalPaid() < $order->getGrandTotal()) { + $state = Order::STATE_PENDING_PAYMENT; + $order->setState($state)->addStatusHistoryComment('heidelpay - Order shipped, awaiting payment', true); + } + } } diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index 962a631c490..90e78e166c4 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -143,4 +143,15 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $this->_paymentHelper->saveTransaction($invoice); } } + + /** + * @param Order $order + */ + public function setShippedOrderState(&$order) + { + if ($order->getTotalPaid() < $order->getGrandTotal()) { + $state = Order::STATE_PENDING_PAYMENT; + $order->setState($state)->addStatusHistoryComment('heidelpay - Finalizing Order', true); + } + } } From 578479e5303ed111266771b57d83e5ae1c85bc5e Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 7 May 2020 11:39:28 +0200 Subject: [PATCH 2/4] (MAGE2-316)[refactor] - Use trait for state handling of shipments. - update changelog. --- CHANGELOG.md | 2 +- Controller/Adminhtml/Order/Shipment/Save.php | 4 +++- .../HeidelpayInvoicePaymentMethod.php | 14 +++--------- .../HeidelpayInvoiceSecuredPaymentMethod.php | 13 ++--------- .../Traits/CanShipBeforePayment.php | 22 +++++++++++++++++++ 5 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 PaymentMethods/Traits/CanShipBeforePayment.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e35a61fa1..4391a4d4bf3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ This project does not follow a versioning standard. Versions are crafted after t ### Fixed - An issue during checkout if phone number is optional and not set by customer. That leads to a failing address comparison for secured payment methods and PayPal. - - An issue creating orders from Reservations. +- Invoice Payment methods : An issue not always setting the expected state after shipment. ## 20.2.24 ### Added diff --git a/Controller/Adminhtml/Order/Shipment/Save.php b/Controller/Adminhtml/Order/Shipment/Save.php index 48646b1306f..ab851c57bac 100755 --- a/Controller/Adminhtml/Order/Shipment/Save.php +++ b/Controller/Adminhtml/Order/Shipment/Save.php @@ -142,9 +142,11 @@ public function beforeExecute() ); $this->_redirect('*/*/new', ['order_id' => $this->getRequest()->getParam('order_id')]); + } else { + $order->addStatusHistoryComment('heidelpay - Finalizing Order'); + $this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.')); } - $this->messageManager->addSuccessMessage(__('Shipping Notification has been sent to Heidelpay.')); } $method->setShippedOrderState($order); $this->orderResository->save($order); diff --git a/PaymentMethods/HeidelpayInvoicePaymentMethod.php b/PaymentMethods/HeidelpayInvoicePaymentMethod.php index 96cddc46295..f2c8957848e 100755 --- a/PaymentMethods/HeidelpayInvoicePaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoicePaymentMethod.php @@ -15,6 +15,7 @@ use Exception; use Heidelpay\Gateway\Block\Info\Invoice as InvoiceBlock; +use Heidelpay\Gateway\Traits\CanShipBeforePayment; use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\InvoicePaymentMethod; use Magento\Sales\Model\Order; @@ -27,6 +28,8 @@ */ class HeidelpayInvoicePaymentMethod extends HeidelpayAbstractPaymentMethod { + use CanShipBeforePayment; + /** @var string Payment Code */ const CODE = 'hgwiv'; @@ -108,15 +111,4 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $this->_paymentHelper->saveTransaction($invoice); } } - - /** - * @param Order $order - */ - public function setShippedOrderState(&$order) - { - if ($order->getTotalPaid() < $order->getGrandTotal()) { - $state = Order::STATE_PENDING_PAYMENT; - $order->setState($state)->addStatusHistoryComment('heidelpay - Order shipped, awaiting payment', true); - } - } } diff --git a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php index 90e78e166c4..d9ccc2e133a 100755 --- a/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php +++ b/PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php @@ -15,6 +15,7 @@ use Heidelpay\Gateway\Block\Info\InvoiceSecured as InvoiceSecuredBlock; use Heidelpay\Gateway\Model\PaymentInformation; +use Heidelpay\Gateway\Traits\CanShipBeforePayment; use Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException; use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod; use Magento\Quote\Api\Data\CartInterface; @@ -28,6 +29,7 @@ */ class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMethod { + use CanShipBeforePayment; /** @var string Payment Code */ const CODE = 'hgwivs'; @@ -143,15 +145,4 @@ public function pendingTransactionProcessing($data, &$order, $message = null) $this->_paymentHelper->saveTransaction($invoice); } } - - /** - * @param Order $order - */ - public function setShippedOrderState(&$order) - { - if ($order->getTotalPaid() < $order->getGrandTotal()) { - $state = Order::STATE_PENDING_PAYMENT; - $order->setState($state)->addStatusHistoryComment('heidelpay - Finalizing Order', true); - } - } } diff --git a/PaymentMethods/Traits/CanShipBeforePayment.php b/PaymentMethods/Traits/CanShipBeforePayment.php new file mode 100644 index 00000000000..dfdbfbd41a7 --- /dev/null +++ b/PaymentMethods/Traits/CanShipBeforePayment.php @@ -0,0 +1,22 @@ +getTotalPaid() < $order->getGrandTotal()) { + $state = Order::STATE_PENDING_PAYMENT; + $status = $order->getConfig()->getStateDefaultStatus($state); + $order->setState($state)->setStatus($status); + } + } +} \ No newline at end of file From 413fb71105011459394e91cdc4c01a6d3c0529a7 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 8 May 2020 11:54:29 +0200 Subject: [PATCH 3/4] (MAGE2-299)[refactor] Use trait for state handling of shipments. --- PaymentMethods/Traits/CanShipBeforePayment.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/PaymentMethods/Traits/CanShipBeforePayment.php b/PaymentMethods/Traits/CanShipBeforePayment.php index dfdbfbd41a7..deabb9c05e0 100644 --- a/PaymentMethods/Traits/CanShipBeforePayment.php +++ b/PaymentMethods/Traits/CanShipBeforePayment.php @@ -1,5 +1,16 @@ Date: Fri, 8 May 2020 11:56:49 +0200 Subject: [PATCH 4/4] (MAGE2-316)[refactor] code style. --- PaymentMethods/Traits/CanShipBeforePayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PaymentMethods/Traits/CanShipBeforePayment.php b/PaymentMethods/Traits/CanShipBeforePayment.php index deabb9c05e0..a2da31b96e4 100644 --- a/PaymentMethods/Traits/CanShipBeforePayment.php +++ b/PaymentMethods/Traits/CanShipBeforePayment.php @@ -30,4 +30,4 @@ public function setShippedOrderState(&$order) $order->setState($state)->setStatus($status); } } -} \ No newline at end of file +}