diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php index 7f63813b..cb61dbc0 100644 --- a/src/Payment/MollieOrder.php +++ b/src/Payment/MollieOrder.php @@ -371,6 +371,13 @@ public function onWebhookCompleted(WC_Order $order, $payment, $paymentMethodTitl if ($payment->method === 'paypal') { $this->addPaypalTransactionIdToOrder($order); } + add_filter('woocommerce_valid_order_statuses_for_payment_complete', static function ($statuses) { + $statuses[] = 'processing'; + return $statuses; + }); + add_filter('woocommerce_payment_complete_order_status', static function ($status) use ($order) { + return $order->get_status() === 'processing' ? 'completed' : $status; + }); $order->payment_complete($payment->id); // Add messages to log $this->logger->debug(__METHOD__ . ' WooCommerce payment_complete() processed and returned to ' . __METHOD__ . ' for order ' . $orderId); diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index 898c0686..0c7ba253 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -80,7 +80,7 @@ public function onWebhookAction() $data_helper = $this->data; $order = wc_get_order($order_id); - if (!$order) { + if (!$order instanceof WC_Order) { $this->httpResponse->setHttpResponseCode(404); $this->logger->debug(__METHOD__ . ": Could not find order $order_id."); return; @@ -135,7 +135,11 @@ public function onWebhookAction() // Log a message that webhook was called, doesn't mean the payment is actually processed $this->logger->debug($this->gateway->id . ": Mollie payment object {$payment->id} (" . $payment->mode . ") webhook call for order {$order->get_id()}.", [true]); + // Get payment method title + $payment_method_title = $this->getPaymentMethodTitle($payment); + // Create the method name based on the payment status + $method_name = 'onWebhook' . ucfirst($payment->status); // Order does not need a payment if (! $this->orderNeedsPayment($order)) { // TODO David: move to payment object? @@ -145,7 +149,10 @@ public function onWebhookAction() // Check and process a possible refund or chargeback $this->processRefunds($order, $payment); $this->processChargebacks($order, $payment); - + //if the order gets updated to completed at mollie, we need to update the order status + if ($order->get_status() === 'processing' && $payment->isCompleted() && method_exists($payment_object, 'onWebhookCompleted')) { + $payment_object->onWebhookCompleted($order, $payment, $payment_method_title); + } return; } @@ -154,12 +161,6 @@ public function onWebhookAction() $this->setBillingAddressAfterPayment($payment, $order); } - // Get payment method title - $payment_method_title = $this->getPaymentMethodTitle($payment); - - // Create the method name based on the payment status - $method_name = 'onWebhook' . ucfirst($payment->status); - if (method_exists($payment_object, $method_name)) { $payment_object->{$method_name}($order, $payment, $payment_method_title); } else {