diff --git a/PluginRazorpay.php b/PluginRazorpay.php index 6430352..cc7b27f 100644 --- a/PluginRazorpay.php +++ b/PluginRazorpay.php @@ -158,6 +158,26 @@ function singlepayment($params) try { $payment = $api->payment->fetch($razorpay_payment_id); // Returns a particular payment $pricePaid = sprintf("%01.2f", round(($payment->amount / 100), 2)); // paise in rupees + + // If payment is authorized but not captured, capture it + if ($payment->status === 'authorized') { + try { + $payment->capture(array( + 'amount' => $payment->amount, + 'currency' => $payment->currency + )); + + // Refetch to confirm capture + $payment = $api->payment->fetch($razorpay_payment_id); + + if ($payment->status !== 'captured') { + throw new Exception('Payment capture failed'); + } + } catch (Exception $e) { + $success = false; + $error = 'Razorpay Error : Capture failed - ' . $e->getMessage(); + } + } } catch (Exception $e) { $pricePaid = $params['invoiceTotal']; } @@ -216,7 +236,7 @@ public function getForm($args) $orderData = array( 'receipt' => $args['invoiceId'], 'amount' => sprintf("%01.2f", round($args['invoiceBalanceDue'], 2)) * 100, // rupees in paise - 'currency' => 'INR', + 'currency' => $args['currency'], 'payment_capture' => 1 // auto capture ); $razorpayOrder = $api->order->create($orderData);