Title: Create a refund programmatically
Last modified: September 23, 2020

---

# Create a refund programmatically

 *  Resolved [miroslavps](https://wordpress.org/support/users/miroslavps/)
 * (@miroslavps)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/create-a-refund-programmatically/)
 * Hi to all,
    I want to create a refund programmatically, so I use wc_create_refund(),
   but it returns me “An error occurred while attempting to create the refund using
   the payment gateway API.”. So I flow the code to find where this message come
   from. The massage is from same file where wc_create_refund() is, and the function
   is wc_refund_payment().
 * In this function we have the following few lines of code:
 * $result = $gateway->process_refund( $order->get_id(), $amount, $reason );
 *  if ( ! $result ) {
    throw new Exception( __( ‘An error occurred while attempting
   to create the refund using the payment gateway API.’, ‘woocommerce’ ) ); }
 * Following the code again I found process_refund() function in the abstract class
   WC_Payment_Gateway. But this function always return false:
 * public function process_refund( $order_id, $amount = null, $reason = ” ) {
 *  return false;
    }
 * so I can not see the way I can skip this check if ( ! $result ).
 * Can someone help me? Do I use the correct functions or there is another solution
   to create refund?
 * Regards!

Viewing 1 replies (of 1 total)

 *  Thread Starter [miroslavps](https://wordpress.org/support/users/miroslavps/)
 * (@miroslavps)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/create-a-refund-programmatically/#post-13444497)
 * Sorry guys, I missed parameter refund_payment in data array for the wc_create_refund.
   
   I set it to false, and I skip the check if ( ! $result ).
 * So do not worry with this.
    Regards!

Viewing 1 replies (of 1 total)

The topic ‘Create a refund programmatically’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [payment](https://wordpress.org/support/topic-tag/payment/)

 * 1 reply
 * 1 participant
 * Last reply from: [miroslavps](https://wordpress.org/support/users/miroslavps/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/create-a-refund-programmatically/#post-13444497)
 * Status: resolved