Skip to content

Commit

Permalink
Fixed cature amount mismatch version bump 3.3.0 (#219)
Browse files Browse the repository at this point in the history
* PON-851:Magento Order Amount and RZP capture mismatch, fixed

* version bump to 3.3.0
  • Loading branch information
ramth05 authored Jan 8, 2021
1 parent 30d1a3c commit 81b3195
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
37 changes: 29 additions & 8 deletions Controller/Payment/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,30 @@ public function execute()
}
else
{
//set the chache to stop webhook processing
$this->cache->save("started", "quote_Front_processing_$receipt_id", ["razorpay"], 30);
if(empty($receipt_id) === false)
{
//set the chache to stop webhook processing
$this->cache->save("started", "quote_Front_processing_$receipt_id", ["razorpay"], 30);

$this->logger->info("Razorpay front-end order processing started quoteID:" . $receipt_id);
$this->logger->info("Razorpay front-end order processing started quoteID:" . $receipt_id);

$responseContent = [
'success' => false,
'parameters' => []
];
$responseContent = [
'success' => false,
'parameters' => []
];
}
else
{
$this->logger->info("Razorpay order already processed with quoteID:" . $this->checkoutSession
->getLastQuoteId());

$responseContent = [
'success' => true,
'order_id' => true,
'parameters' => []
];

}
}

$response = $this->resultFactory->create(ResultFactory::TYPE_JSON);
Expand Down Expand Up @@ -225,6 +240,7 @@ public function execute()
$code = 200;

$this->catalogSession->setRazorpayOrderID($order->id);
$this->catalogSession->setRazorpayOrderAmount($amount);
}
}
catch(\Razorpay\Api\Errors\Error $e)
Expand All @@ -244,7 +260,7 @@ public function execute()
}

//set the chache for race with webhook
$this->cache->save("started", "quote_Front_processing_$receipt_id", ["razorpay"], 30);
$this->cache->save("started", "quote_Front_processing_$receipt_id", ["razorpay"], 120);

$response = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$response->setData($responseContent);
Expand All @@ -259,6 +275,11 @@ public function getOrderID()
return $this->catalogSession->getRazorpayOrderID();
}

public function getRazorpayOrderAmount()
{
return $this->catalogSession->getRazorpayOrderAmount();
}

protected function getMerchantPreferences()
{
try
Expand Down
5 changes: 3 additions & 2 deletions Controller/Payment/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ protected function orderPaid(array $post)
exit;
}

$this->cache->save("started", "quote_processing_$quoteId", ["razorpay"], 30);

$amount = number_format($post['payload']['payment']['entity']['amount']/100, 2, ".", "");

$this->logger->info("Razorpay Webhook processing started for Razorpay payment_id(:$paymentId)");
Expand Down Expand Up @@ -247,6 +245,9 @@ protected function orderPaid(array $post)
}
}

//Set cache flag for webhook processing
$this->cache->save("started", "quote_processing_$quoteId", ["razorpay"], 30);

$quote = $this->getQuoteObject($post, $quoteId);

//before creating order let wait for 15 sec and re-verify if the quote is active or not
Expand Down
11 changes: 11 additions & 0 deletions Model/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ public function authorize(InfoInterface $payment, $amount)
else
{
$payment_id = $request['paymentMethod']['additional_data']['rzp_payment_id'];

//validate RzpOrderamount with quote/order amount before signature
$orderAmount = (int) (number_format($amount * 100, 0, ".", ""));

if ($orderAmount !== $this->order->getRazorpayOrderAmount())
{
$rzpOrderAmount = $order->getBaseCurrency()->formatTxt(number_format($this->order->getRazorpayOrderAmount() / 100, 2, ".", ""));

throw new LocalizedException(__("Cart order amount = %1 doesn't match with amount paid = %2", $order->getBaseCurrency()->formatTxt($amount), $rzpOrderAmount));
}

$this->validateSignature($request);
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "razorpay/magento",
"description": "Razorpay Magento 2.0 plugin for accepting payments.",
"version": "3.2.3",
"version": "3.3.0",
"require": {
"php": "~5.5.0|~5.6.0|^7.0",
"razorpay/razorpay": "2.*"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -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="3.2.3">
<module name="Razorpay_Magento" setup_version="3.3.0">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit 81b3195

Please sign in to comment.