Skip to content

Commit

Permalink
Merge pull request #172 from razorpay/webhook_virtual_account_credited
Browse files Browse the repository at this point in the history
Fix the amount compare issue
  • Loading branch information
ChetanGN authored Dec 29, 2020
2 parents 3fa9e08 + c17fae7 commit 22def9f
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions includes/razorpay-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,12 @@ protected function paymentAuthorized(array $data)

$success = false;
$errorMessage = 'The payment has failed.';
$amountVerified = false;

if($payment['amount'] >= $amount)
{
if($payment['amount'] > $amount)
{
$orderAmountWithoutFeeBearer = $payment['amount'] - $payment['fee'];

if($orderAmountWithoutFeeBearer === $amount)
{
$amountVerified = true;
}
}
else
{
$amountVerified = true;
}
}

if ($payment['status'] === 'captured' and $amountVerified === true)
if ($payment['status'] === 'captured')
{
$success = true;
}
else if (($payment['status'] === 'authorized') and $amountVerified === true and
else if (($payment['status'] === 'authorized') and
($this->razorpay->getSetting('payment_action') === WC_Razorpay::CAPTURE))
{
//
Expand Down Expand Up @@ -270,6 +252,7 @@ protected function virtualAccountCredited(array $data)

$razorpayPaymentId = $data['payload']['payment']['entity']['id'];
$virtualAccountId = $data['payload']['virtual_account']['entity']['id'];
$amountPaid = (int) $data['payload']['virtual_account']['entity']['amount_paid'];

$payment = $this->getPaymentEntity($razorpayPaymentId, $data);

Expand All @@ -278,11 +261,11 @@ protected function virtualAccountCredited(array $data)
$success = false;
$errorMessage = 'The payment has failed.';

if ($payment['amount'] === $amount and $payment['status'] === 'captured')
if ($payment['status'] === 'captured' and $amountPaid === $amount)
{
$success = true;
}
else if (($payment['status'] === 'authorized') and $payment['amount'] === $amount and
else if (($payment['status'] === 'authorized') and $amountPaid === $amount and
($this->razorpay->getSetting('payment_action') === WC_Razorpay::CAPTURE))
{
//
Expand Down

0 comments on commit 22def9f

Please sign in to comment.