Skip to content

Commit 47f0222

Browse files
authored
Merge pull request #83 from razorpay/PO-183
PO-183 (Updated amount in unpaid invoice not reflecting in checkout when attempting to pay)
2 parents 1ed6b71 + 898be71 commit 47f0222

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

modules/gateways/razorpay.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ function createRazorpayOrderId(array $params)
182182
return $razorpayOrderId;
183183
}
184184

185+
function getExistingOrderDetails($params, $razorpayOrderId)
186+
{
187+
try
188+
{
189+
$api = getRazorpayApiInstance($params);
190+
return $api->order->fetch($razorpayOrderId);
191+
}
192+
catch (Exception $e)
193+
{
194+
logTransaction(razorpay_MetaData()['DisplayName'], $e->getMessage(), "Unsuccessful - Fetch existing order failed");
195+
}
196+
197+
}
185198
/**
186199
* Payment link.
187200
* Required by third party payment gateway modules only.
@@ -229,7 +242,17 @@ function razorpay_link($params)
229242
}
230243
else
231244
{
232-
$razorpayOrderId = $existingRazorpayOrderId;
245+
$existingOrder = getExistingOrderDetails($params, $existingRazorpayOrderId);
246+
247+
if (isset($existingOrder) === true and
248+
((int)$existingOrder['amount']) !== ((int)$amount))
249+
{
250+
$razorpayOrderId = createRazorpayOrderId($params);
251+
}
252+
else
253+
{
254+
$razorpayOrderId = $existingRazorpayOrderId;
255+
}
233256
}
234257

235258
return <<<EOT
@@ -256,4 +279,4 @@ function razorpay_link($params)
256279
></script>
257280
</form>
258281
EOT;
259-
}
282+
}

0 commit comments

Comments
 (0)