From a92bdd011a0bb96c073146ff44d5e39eca7aea37 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 18 Oct 2023 12:56:37 +0200 Subject: [PATCH] Change status on webhook completed & cbf --- .../ApplePayButton/ApplePayDataObjectHttp.php | 2 +- src/Payment/MollieOrder.php | 7 +++++++ src/Payment/MollieOrderService.php | 17 +++++++++-------- src/PaymentMethods/Kbc.php | 14 +++++++------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php b/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php index 38f91294..db7f6919 100644 --- a/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php +++ b/src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php @@ -326,7 +326,7 @@ protected function addressHasRequiredFieldsValues( sprintf('ApplePay Data Error: Missing value for %s', $requiredField) ); $this->errors[] - = [ + = [ 'errorCode' => $errorCode, 'contactField' => $errorValue, ]; 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 { diff --git a/src/PaymentMethods/Kbc.php b/src/PaymentMethods/Kbc.php index 361116ed..5c220cac 100644 --- a/src/PaymentMethods/Kbc.php +++ b/src/PaymentMethods/Kbc.php @@ -6,10 +6,10 @@ class Kbc extends AbstractPaymentMethod implements PaymentMethodI { -protected const DEFAULT_ISSUERS_DROPDOWN = 'yes'; -protected function getConfig(): array -{ - return [ + protected const DEFAULT_ISSUERS_DROPDOWN = 'yes'; + protected function getConfig(): array + { + return [ 'id' => 'kbc', 'defaultTitle' => __('KBC/CBC Payment Button', 'mollie-payments-for-woocommerce'), 'settingsDescription' => '', @@ -23,10 +23,10 @@ protected function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => true, 'SEPA' => true, - ]; -} + ]; + } -public function getFormFields($generalFormFields): array + public function getFormFields($generalFormFields): array { $paymentMethodFormFieds = [ 'issuers_dropdown_shown' => [