Skip to content

Commit

Permalink
removed amount check in webhook and added it in order comments (#249)
Browse files Browse the repository at this point in the history
* removed amount check in webhook and added it in order comments for Actual amount paid, fixed label in display
  • Loading branch information
ramth05 committed Jun 1, 2021
1 parent 4b38d92 commit ad79ce3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
10 changes: 0 additions & 10 deletions Controller/Payment/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 12 additions & 0 deletions Model/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 11 additions & 1 deletion Observer/AfterPlaceOrderObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion view/frontend/web/template/payment/razorpay-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
name="payment[method]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<img src="https://cdn.razorpay.com/logo.png" width="20%" alt="Razorpay" class="payment-icon"/>
<label data-bind="attr: {'for': getCode()}" class="label">
<img src="https://cdn.razorpay.com/logo.png" width="20%" alt="Razorpay" class="payment-icon"/>
</label>
</div>

<div class="payment-method-content">
Expand Down

0 comments on commit ad79ce3

Please sign in to comment.