Skip to content

Commit

Permalink
Merge branch 'fix/PIWOO-108-complete-on-shipping' into release/7.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Oct 20, 2023
2 parents 94b0172 + 0e39885 commit 376491a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/Payment/MollieOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions src/Payment/MollieOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?
Expand All @@ -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;
}

Expand All @@ -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 {
Expand Down

0 comments on commit 376491a

Please sign in to comment.