How to add refund in custom payment gateway woocommerce

I want to add refund to the woocommerce-payment-gateway

  • in class WC_Custom_Gateway extends WC_Payment_Gateway
        function __construct()
        {
            $this-supports             = array('products', 'refunds');
            $this-id = 'custom';
            $this-icon = plugins_url('../assets/custom-logo.png', __FILE__);
            $this-has_fields = true;
            $this-method_title = 'Custom';
            $this-method_description = 'Payment using Custom card';
            $this-init_form_fields();


            $this-init_settings();
            $this-title = sanitize_textarea_field($this-get_option('title'));
            $this-description = sanitize_textarea_field($this-get_option('description'));
            $this-enabled = sanitize_key($this-get_option('enabled'));
            $this-discount = intval($this-get_option('discount'));
            $this-token = sanitize_text_field($this-get_option('token'));
            $this-client = sanitize_text_field($this-get_option('client'));
            $this-back_url = esc_url_raw($this-get_option('back_url'));
            $this-response_type = $this-get_option('response_type');

            add_action('woocommerce_update_options_payment_gateways_' . $this-id, array($this, 'process_admin_options'));
            // if (is_admin()) {
            //     add_action('woocommerce_update_options_payment_gateways_' . $this-id, array($this, 'process_admin_options'));
            // }
            //https://woocommerce.com/document/wc_api-the-woocommerce-api-callback/
            add_action('woocommerce_api_custom', array($this, 'webhook'));

            if (!function_exists('write_log')) {

                function write_log($log)
                {
                    if (true === WP_DEBUG) {
                        if (is_array($log) || is_object($log)) {
                            error_log(print_r($log, true));
                        } else {
                            error_log($log);
                        }
                    }
                }
            }

            write_log('THIS IS THE START OF MY CUSTOM DEBUG');
        }
        public function can_refund_order($order){
            if($order instanceof WC_Order  method_exists($order,'get_transaction_id'))
            {
                return true;
            }
            return false;
        }

        public function process_refund($order_id, $amount = null, $reason = '')
        {
            return true;
        }

I want to call the function process_refund($order_id, $amount = null, $reason = '') in the class of WC_Custom_Gateway

Topic woocommerce-offtopic apache php Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.