/** * Process a refund if supported * @param int $order_id * @param float $amount * @param string $reason * @return boolean True or false based on success, or a WP_Error object */ public function process_refund($order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); if (!$this->can_refund_order($order)) { $this->log('Refund Failed: No transaction ID'); return false; } include_once 'includes/class-wc-gateway-paypal-refund.php'; WC_Gateway_Paypal_Refund::$api_username = $this->get_option('api_username'); WC_Gateway_Paypal_Refund::$api_password = $this->get_option('api_password'); WC_Gateway_Paypal_Refund::$api_signature = $this->get_option('api_signature'); $result = WC_Gateway_Paypal_Refund::refund_order($order, $amount, $reason, $this->testmode); if (is_wp_error($result)) { $this->log('Refund Failed: ' . $result->get_error_message()); return false; } $this->log('Refund Result: ' . print_r($result, true)); switch (strtolower($result['ACK'])) { case 'success': case 'successwithwarning': $order->add_order_note(sprintf(__('Refunded %s - Refund ID: %s', 'woocommerce'), $result['GROSSREFUNDAMT'], $result['REFUNDTRANSACTIONID'])); return true; break; } return false; }
public static function refund_order($order, $amount = null, $reason = '', $sandbox = false) { if ($sandbox) { self::$sandbox = $sandbox; } $result = self::refund_transaction($order, $amount, $reason); if (is_wp_error($result)) { return $result; } else { return (array) $result; } }