From 4c7a6b4db214046a6b92f966929bb08f492dadc0 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 28 Oct 2024 14:17:20 +0100 Subject: [PATCH] Hook into refund action and return it --- src/PluginApi/MolliePluginApi.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/PluginApi/MolliePluginApi.php b/src/PluginApi/MolliePluginApi.php index 040a7af1..4869b6a4 100644 --- a/src/PluginApi/MolliePluginApi.php +++ b/src/PluginApi/MolliePluginApi.php @@ -3,6 +3,7 @@ namespace Mollie\WooCommerce\PluginApi; use Closure; +use Mollie\Api\Resources\Refund; use Mollie\WooCommerce\Payment\MollieObject; class MolliePluginApi @@ -73,12 +74,16 @@ public function captureOrder(\WC_Order $wcOrder): void * @param \WC_Order $wcOrder The WooCommerce order. * @param float $amount The refund amount. * @param string $reason The reason for the refund. - * @return \WP_Error|bool The result of the refund operation. + * @return \WP_Error|Refund The result of the refund operation. */ public function refundOrder(\WC_Order $wcOrder, float $amount, string $reason = '') { - - return $this->mollieObject->processRefund($wcOrder->get_id(), $amount, $reason); + $mollieRefund = null; + add_action('mollie-payments-for-woocommerce_refund_amount_created', function ($refund, $order, $amount) use (&$mollieRefund) { + $mollieRefund = $refund; + }, 10, 3); + $refundCreated = $this->mollieObject->processRefund($wcOrder->get_id(), $amount, $reason); + return $refundCreated ? $mollieRefund : new \WP_Error('mollie_refund_failed', __('Refund failed', 'mollie-payments-for-woocommerce')); } /**