Skip to content

Commit

Permalink
Fix capture payment badge, when captured from Mollie dasboard
Browse files Browse the repository at this point in the history
  • Loading branch information
inpsyde-maticluznar committed Nov 16, 2023
1 parent c27045f commit 5bcf8f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/MerchantCapture/Capture/Type/StateChangeCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ class StateChangeCapture
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$pluginId = $container->get('shared.plugin_id');

add_action('woocommerce_order_status_changed', [$this, "orderStatusChange"], 10, 3);

/** When the webhook process is activated we don't need automatic status change. Status change is handled
* by the webhook logic.
*/
add_action($pluginId . '_before_webhook_payment_action', function(){
remove_action('woocommerce_order_status_changed', [$this, "orderStatusChange"], 10, 3);
});
}

public function orderStatusChange(int $orderId, string $oldStatus, string $newStatus)
Expand Down
7 changes: 5 additions & 2 deletions src/MerchantCapture/MerchantCaptureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ static function (Payment $payment, WC_Order $order) use ($container) {
ManualCaptureStatus::STATUS_AUTHORIZED
);
$order->save();
} elseif ($payment->isPaid() && ($container->get('merchant.manual_capture.is_waiting'))($order)) {
} elseif ($payment->isPaid() && (
($container->get('merchant.manual_capture.is_waiting'))($order) ||
($container->get('merchant.manual_capture.is_authorized'))($order)
)) {
$order->update_meta_data(
self::ORDER_PAYMENT_STATUS_META_KEY,
ManualCaptureStatus::STATUS_CAPTURED
Expand Down Expand Up @@ -198,7 +201,7 @@ static function ($disableShipAndCapture, WC_Order $order) use ($container) {
if ($disableShipAndCapture) {
return true;
}
return $container->get('merchant.manual_capture.is_waiting')($order);
return $container->get('merchant.manual_capture.is_waiting')($order) || $container->get('merchant.manual_capture.is_authorized')($order);
},
10,
2
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/MollieOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public function onWebhookAction()
if ($order->get_status() === 'processing' && $payment->isCompleted() && method_exists($payment_object, 'onWebhookCompleted')) {
$payment_object->onWebhookCompleted($order, $payment, $payment_method_title);
}
do_action($this->pluginId . '_after_webhook_no_payment_action', $payment, $order);
return;
}

Expand All @@ -163,6 +162,7 @@ public function onWebhookAction()
}

if (method_exists($payment_object, $method_name)) {
do_action($this->pluginId . '_before_webhook_payment_action', $payment, $order);
$payment_object->{$method_name}($order, $payment, $payment_method_title);
} else {
$order->add_order_note(sprintf(
Expand Down

0 comments on commit 5bcf8f6

Please sign in to comment.