Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/piwoo 108 complete on shipping #843

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading