Skip to content

Commit

Permalink
added paymentId validation (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramth05 authored Sep 15, 2021
1 parent 5117da0 commit 0e5d079
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions Model/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,35 +323,49 @@ public function authorize(InfoInterface $payment, $amount)
else
{
// Order processing through front-end
if(empty($request['paymentMethod']['additional_data']['rzp_payment_id']) === false)
{
$payment_id = $request['paymentMethod']['additional_data']['rzp_payment_id'];

$payment_id = $request['paymentMethod']['additional_data']['rzp_payment_id'];

$rzp_order_id = $this->order->getOrderId();
$rzp_order_id = $this->order->getOrderId();

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

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

$this->validateSignature([
$this->validateSignature([
'razorpay_payment_id' => $payment_id,
'razorpay_order_id' => $rzp_order_id,
'razorpay_signature' => $request['paymentMethod']['additional_data']['rzp_signature']
]);
}
}
}

$payment->setStatus(self::STATUS_APPROVED)
if((isset($payment_id) === true) and
(empty($payment_id) === false))
{
$payment->setStatus(self::STATUS_APPROVED)
->setAmountPaid($amount)
->setLastTransId($payment_id)
->setTransactionId($payment_id)
->setIsTransactionClosed(true)
->setShouldCloseParentTransaction(true);

//update the Razorpay payment with corresponding created order ID of this quote ID
$this->updatePaymentNote($payment_id, $order, $rzp_order_id, $isWebhookCall);
//update the Razorpay payment with corresponding created order ID of this quote ID
$this->updatePaymentNote($payment_id, $order, $rzp_order_id, $isWebhookCall);
}
else
{
$error = "Razorpay paymentId missing for payment verification.";

$this->_logger->critical($e);
throw new LocalizedException(__('Razorpay Error: %1.', $error));
}

}
catch (\Exception $e)
{
Expand Down

0 comments on commit 0e5d079

Please sign in to comment.