Skip to content

Commit

Permalink
Instant refund fix (#536)
Browse files Browse the repository at this point in the history
* Instant refund fallback
  • Loading branch information
yashgit891 authored Feb 22, 2024
1 parent 790f631 commit 812a39e
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ public function process_refund($orderId, $amount = null, $reason = '')

$data = array(
'amount' => (int) round($amount * 100),
'speed' => 'optimum',
'notes' => array(
'reason' => $reason,
'order_id' => $orderId,
Expand All @@ -1536,29 +1537,59 @@ public function process_refund($orderId, $amount = null, $reason = '')
try
{
$refund = $client->payment
->fetch( $paymentId )
->refund( $data );
->fetch($paymentId)
->refund($data);

if (isset($refund) === true)
if (isset($refund) === true and
isset($refund->id) === true)
{
$order->add_order_note( __( 'Refund Id: ' . $refund->id, 'woocommerce' ) );
$order->add_order_note(__('Refund Id: ' . $refund->id, 'woocommerce'));
/**
* @var $refund ->id -- Provides the RazorPay Refund ID
* @var $orderId -> Refunded Order ID
* @var $refund -> WooCommerce Refund Instance.
*/
do_action( 'woo_razorpay_refund_success', $refund->id, $orderId, $refund );
do_action('woo_razorpay_refund_success', $refund->id, $orderId, $refund);

rzpLogInfo( 'Refund ID = ' . $refund->id .
rzpLogInfo('Refund ID = ' . $refund->id .
' , Refund speed requested = ' . $refund->speed_requested .
' , Refund speed processed = ' . $refund->speed_processed);
}

return true;
}
catch(Exception $e)
{
return new WP_Error('error', __($e->getMessage(), 'woocommerce'));
rzpLogInfo('Refund failed with error message :- ' . $e->getMessage());

rzpLogInfo('Refund reinitiated with normal speed.');

try
{
$data['speed'] = 'normal';

$refund = $client->payment
->fetch($paymentId)
->refund($data);

if (isset($refund) === true and
isset($refund->id) === true)
{
$order->add_order_note(__('Refund Id: ' . $refund->id, 'woocommerce'));

do_action('woo_razorpay_refund_success', $refund->id, $orderId, $refund);

rzpLogInfo('Refund ID = ' . $refund->id .
' , Refund speed requested = ' . $refund->speed_requested .
' , Refund speed processed = ' . $refund->speed_processed);
}

return true;
}
catch(Exception $e)
{
return new WP_Error('error', __($e->getMessage(), 'woocommerce'));
}
}
}

Expand Down

0 comments on commit 812a39e

Please sign in to comment.