Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #138 from heidelpay/MAGE2-316/fix/shipping_order_s…
Browse files Browse the repository at this point in the history
…tate

(MAGE2-316)[fix] Set expected orderstate after shipment for invoice
  • Loading branch information
Ryouzanpaku authored May 8, 2020
2 parents 796abb0 + 833c139 commit 46d753b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project does not follow a versioning standard. Versions are crafted after t
for secured payment methods and PayPal.
- Disable caching for dynamic blocks.
- An issue creating orders from Reservations.
- Invoice Payment methods : An issue not always setting the expected state after shipment.

## 20.2.24
### Added
Expand Down
16 changes: 7 additions & 9 deletions Controller/Adminhtml/Order/Shipment/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);

Expand All @@ -142,16 +142,14 @@ 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.'));
}

// 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);
}
}
}
8 changes: 8 additions & 0 deletions PaymentMethods/HeidelpayAbstractPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 3 additions & 0 deletions PaymentMethods/HeidelpayInvoicePaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,8 @@
*/
class HeidelpayInvoicePaymentMethod extends HeidelpayAbstractPaymentMethod
{
use CanShipBeforePayment;

/** @var string Payment Code */
const CODE = 'hgwiv';

Expand Down
2 changes: 2 additions & 0 deletions PaymentMethods/HeidelpayInvoiceSecuredPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@
*/
class HeidelpayInvoiceSecuredPaymentMethod extends HeidelpayAbstractPaymentMethod
{
use CanShipBeforePayment;
/** @var string Payment Code */
const CODE = 'hgwivs';

Expand Down
33 changes: 33 additions & 0 deletions PaymentMethods/Traits/CanShipBeforePayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Trait to handle payment methods that can ship before payment e.g. Invoice.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
* @link http://dev.heidelpay.com/magento2
* @author David Owusu
*
* @package heidelpay
* @subpackage magento2
* @category magento2
*/

namespace Heidelpay\Gateway\Traits;


use Magento\Sales\Model\Order;

trait CanShipBeforePayment
{
/**
* @param Order $order
*/
public function setShippedOrderState(&$order)
{
if ($order->getTotalPaid() < $order->getGrandTotal()) {
$state = Order::STATE_PENDING_PAYMENT;
$status = $order->getConfig()->getStateDefaultStatus($state);
$order->setState($state)->setStatus($status);
}
}
}

0 comments on commit 46d753b

Please sign in to comment.