Hi,
I have installed Magento 2 C.E (V2.2.3) and integrated CCAvenue payment gateway. I have set the new order status to PENDING and payment success order status to PROCESSING in my admin panel configuration. Everything is working fine on the website.
The problem is however, in the mobile application which I have created for the same website. I used REST API for developing mobile application and the API which I used for placing the order is given below.
POST /v1/carts/mine/payment-information
The order status in this case is getting set to PROCESSING and not PENDING when I am using ccavenue as the payment method. So, even if I do not complete the payment process, the order is shown in the processing status to the customer.
I do not know whether it is an issue or normal behaviour. If it is normal then I don't know how to interpret it. If it is normal then how to differentiate between paid and unpaid orders by seeing the order status?
By default CCAvenue Payment gateway with default Status is processing. so you need to do programmatically set pending status from code level.
You need to find out code at which place processing status will applied.
thanks
Hi,
As far as what I am able to investigate through the function calls, I found that there is a function in file \Magento\Sales\Model\Order\Payment.php
public function place() { $this->_eventManager->dispatch('sales_order_payment_place_start', ['payment' => $this]); $order = $this->getOrder(); $this->setAmountOrdered($order->getTotalDue()); $this->setBaseAmountOrdered($order->getBaseTotalDue()); $this->setShippingAmount($order->getShippingAmount()); $this->setBaseShippingAmount($order->getBaseShippingAmount()); $methodInstance = $this->getMethodInstance(); $methodInstance->setStore($order->getStoreId()); $orderState = Order::STATE_NEW; $orderStatus = $methodInstance->getConfigData('order_status'); $isCustomerNotified = $order->getCustomerNoteNotify(); // Do order payment validation on payment method level $methodInstance->validate(); $action = $methodInstance->getConfigPaymentAction(); if ($action) { if ($methodInstance->isInitializeNeeded()) { $stateObject = new \Magento\Framework\DataObject(); // For method initialization we have to use original config value for payment action $methodInstance->initialize($methodInstance->getConfigData('payment_action'), $stateObject); $orderState = $stateObject->getData('state') ?: $orderState; $orderStatus = $stateObject->getData('status') ?: $orderStatus; $isCustomerNotified = $stateObject->hasData('is_notified') ? $stateObject->getData('is_notified') : $isCustomerNotified; } else { $orderState = Order::STATE_PROCESSING; $this->processAction($action, $order); $orderState = $order->getState() ? $order->getState() : $orderState; $orderStatus = $order->getStatus() ? $order->getStatus() : $orderStatus; } } else { $order->setState($orderState) ->setStatus($orderStatus); } $isCustomerNotified = $isCustomerNotified ?: $order->getCustomerNoteNotify(); if (!array_key_exists($orderStatus, $order->getConfig()->getStateStatuses($orderState))) { $orderStatus = $order->getConfig()->getStateDefaultStatus($orderState); } $this->updateOrder($order, $orderState, $orderStatus, $isCustomerNotified); $this->_eventManager->dispatch('sales_order_payment_place_end', ['payment' => $this]); return $this; }
In this function, I expected the Class for the object $methodInstance should be Magento\Ccavenuepay\Model\Ccavenuepay.php because this the payment method class for Ccavenue payment gateway extension I am using but when I used get_class($methodInstance) then I found out that it is an instance of \Magento\Payment\Model\Method\Adapter.
In the adapter class there are functions defined
/** * @inheritdoc */ public function isInitializeNeeded() { return (bool)(int)$this->getConfiguredValue('can_initialize'); } /** * Unifies configured value handling logic * * @param string $field * @param null $storeId * @return mixed */ private function getConfiguredValue($field, $storeId = null) { $handler = $this->valueHandlerPool->get($field); $subject = [ 'field' => $field ]; if ($this->getInfoInstance()) { $subject['payment'] = $this->paymentDataObjectFactory->create($this->getInfoInstance()); } return $handler->handle($subject, $storeId ?: $this->getStore()); }
From here, I am unable to understand from where it is picking "can_initialize" configurable value. I wanted to set it to true for Ccavenue, so I tried editing . config.xml for that extension and added the tag <can_initialize>1</can_initialize> and ran setup:upgrade command to reinstall the extension. But now, it is giving error "Command initialize does not exist".