How to Add Refund Support and Transaction ID in Woocommerce

geekerhub

Updated on:

While developing a new payment gateway we can easily implement the payment method to collect the payment using the example from the google. But when further process come to Add Refund Support and Transaction ID in Woo commerce payment gateway development, most of initial developer get confused.

To allow refund support, you need to add support in your payment gateway.

<?php
$this->supports = array( 'refunds' );
?>

So i will add some basic code snippet and the function which are related to the refund and transaction id.

List of functions associated with basic payment gateway for collecting payment and refunds

<?php
//Process refund functions to refund payment.
public function process_refund( $order_id, $amount = null, $reason = '' ) {

	global $woocommerce;
	$customer_order = new WC_Order( $order_id );
	$customer_order->get_currency();
	$refundamount = $amount;
	$transactionId = get_post_meta( $order_id, '_transaction_id', true );

	//you need to do your logic for refund functionality over here

	/*
		RETURN TRUE IF YOUR LOGIC ON REFUND IS SUCCESS ELSE RETURN FALSE
	*/
}

Leave a Comment