diff --git a/Controller/Payment/Webhook.php b/Controller/Payment/Webhook.php index 61e2942d..cb59a25a 100644 --- a/Controller/Payment/Webhook.php +++ b/Controller/Payment/Webhook.php @@ -262,16 +262,6 @@ protected function orderPaid(array $post) return; } - //validate amount before placing order - $quoteAmount = (int) (number_format($quote->getGrandTotal() * 100, 0, ".", "")); - - if ($quoteAmount !== $post['payload']['payment']['entity']['amount']) - { - $this->logger->info("Razorpay Webhook: Amount paid doesn't match with store order amount for Razorpay payment_id(:$paymentId)"); - - return; - } - # fetch the related sales order and verify the payment ID with rzp payment id # To avoid duplicate order entry for same quote $collection = $this->_objectManager->get('Magento\Sales\Model\Order') diff --git a/Model/PaymentMethod.php b/Model/PaymentMethod.php index cb93ceb7..4607aa11 100644 --- a/Model/PaymentMethod.php +++ b/Model/PaymentMethod.php @@ -399,4 +399,16 @@ public function getConfigData($field, $storeId = null) } return $this->config->getConfigData($field, $storeId); } + + /** + * Get the amount paid from RZP + * + * @param string $paymentId + */ + public function getAmountPaid($paymentId) + { + $payment = $this->rzp->payment->fetch($paymentId); + + return $payment->amount; + } } diff --git a/Observer/AfterPlaceOrderObserver.php b/Observer/AfterPlaceOrderObserver.php index 64cd9c31..534550e9 100755 --- a/Observer/AfterPlaceOrderObserver.php +++ b/Observer/AfterPlaceOrderObserver.php @@ -35,11 +35,14 @@ class AfterPlaceOrderObserver implements ObserverInterface public function __construct( OrderRepositoryInterface $orderRepository, \Magento\Checkout\Model\Session $checkoutSession, - \Razorpay\Magento\Model\Config $config + \Razorpay\Magento\Model\Config $config, + \Razorpay\Magento\Model\PaymentMethod $rzpMethod ) { $this->orderRepository = $orderRepository; $this->checkoutSession = $checkoutSession; $this->config = $config; + + $this->rzpMethod = $rzpMethod; } /** @@ -79,6 +82,13 @@ private function updateOrderLinkStatus(Payment $payment) $lastQuoteId = $order->getQuoteId(); $rzpPaymentId = $payment->getLastTransId(); + $amount_paid = number_format($this->rzpMethod->getAmountPaid($rzpPaymentId) / 100, 2, ".", ""); + + $order->addStatusHistoryComment( + __('Actual Amount Paid of %1, with Razorpay Offer/Fee applied.', $order->getBaseCurrency()->formatTxt($amount_paid)) + ); + $order->save(); + //update quote $quote = $objectManager->get('Magento\Quote\Model\Quote')->load($lastQuoteId); $quote->setIsActive(false)->save(); diff --git a/view/frontend/web/template/payment/razorpay-form.html b/view/frontend/web/template/payment/razorpay-form.html index c705de47..46583e7a 100644 --- a/view/frontend/web/template/payment/razorpay-form.html +++ b/view/frontend/web/template/payment/razorpay-form.html @@ -4,7 +4,9 @@ name="payment[method]" class="radio" data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/> - Razorpay +