Skip to content

Commit

Permalink
PON-689: updated order status based on backend setting and amount rou…
Browse files Browse the repository at this point in the history
…nd of fix
  • Loading branch information
Ram Prakash Singh committed Nov 6, 2020
1 parent 880b0e6 commit 7940fbf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
11 changes: 7 additions & 4 deletions Controller/Payment/Order.php
Expand Up @@ -43,7 +43,7 @@ public function execute()
{
$mazeOrder = $this->checkoutSession->getLastRealOrder();

$amount = (int) (round($mazeOrder->getBaseGrandTotal(), 2) * 100);
$amount = (int) (number_format($mazeOrder->getGrandTotal() * 100, 0, ".", ""));

$receipt_id = $mazeOrder->getIncrementId();

Expand All @@ -54,10 +54,13 @@ public function execute()


//if already order from same session , let make it's to pending state
$new_order_status = $this->config->getNewOrderStatus();

$orderModel = $this->_objectManager->get('Magento\Sales\Model\Order')->load($mazeOrder->getEntityId());

$orderModel->setState('new')
->setStatus('pending');
$orderModel->save();
->setStatus($new_order_status)
->save();

if ($payment_action === 'authorize')
{
Expand Down Expand Up @@ -92,7 +95,7 @@ public function execute()
'order_id' => $receipt_id,
'amount' => $order->amount,
'quote_currency' => $mazeOrder->getOrderCurrencyCode(),
'quote_amount' => round($mazeOrder->getBaseGrandTotal(), 2),
'quote_amount' => $amount,
'maze_version' => $maze_version,
'module_version' => $module_version,
];
Expand Down
6 changes: 6 additions & 0 deletions Model/Config.php
Expand Up @@ -14,6 +14,7 @@ class Config
const KEY_MERCHANT_NAME_OVERRIDE = 'merchant_name_override';
const KEY_PAYMENT_ACTION = 'rzp_payment_action';
const KEY_AUTO_INVOICE = 'auto_invoice';
const KEY_NEW_ORDER_STATUS = 'order_status';

/**
* @var string
Expand Down Expand Up @@ -57,6 +58,11 @@ public function getPaymentAction()
return $this->getConfigData(self::KEY_PAYMENT_ACTION);
}

public function getNewOrderStatus()
{
return $this->getConfigData(self::KEY_NEW_ORDER_STATUS);
}

/**
* @param int $storeId
* @return $this
Expand Down
17 changes: 9 additions & 8 deletions Observer/AfterPlaceOrderObserver.php
Expand Up @@ -14,10 +14,6 @@
*/
class AfterPlaceOrderObserver implements ObserverInterface
{
/**
* Status pending
*/
const STATUS_PENDING_PAYMENT = 'pending_payment';

/**
* Store key
Expand All @@ -42,10 +38,12 @@ class AfterPlaceOrderObserver implements ObserverInterface
*/
public function __construct(
OrderRepositoryInterface $orderRepository,
\Magento\Checkout\Model\Session $checkoutSession
\Magento\Checkout\Model\Session $checkoutSession,
\Razorpay\Magento\Model\Config $config
) {
$this->orderRepository = $orderRepository;
$this->checkoutSession = $checkoutSession;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -76,9 +74,12 @@ public function execute(Observer $observer)
private function assignStatus(Payment $payment)
{
$order = $payment->getOrder();

$order->setState(static::STATUS_PENDING_PAYMENT)
->setStatus(static::STATUS_PENDING_PAYMENT);

$new_order_status = $this->config->getNewOrderStatus();

$order->setState('new')
->setStatus($new_order_status);

$this->orderRepository->save($order);
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "razorpay/magento",
"description": "Razorpay Magento 2.0 plugin for accepting payments.",
"version": "2.8.0",
"version": "beta-3.3.1",
"require": {
"php": "~5.5.0|~5.6.0|^7.0",
"razorpay/razorpay": "2.*"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Razorpay_Magento" setup_version="2.8.0">
<module name="Razorpay_Magento" setup_version="beta-3.3.1">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit 7940fbf

Please sign in to comment.