Skip to content

Commit

Permalink
Hook into refund action and return it
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Oct 28, 2024
1 parent 03bcfca commit 4c7a6b4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/PluginApi/MolliePluginApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mollie\WooCommerce\PluginApi;

use Closure;
use Mollie\Api\Resources\Refund;
use Mollie\WooCommerce\Payment\MollieObject;

class MolliePluginApi
Expand Down Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit 4c7a6b4

Please sign in to comment.