Skip to content

Commit

Permalink
Merge pull request #982 from mollie/PIWOO-609-mollie-for-woocommerce-…
Browse files Browse the repository at this point in the history
…orders-have-conflicting-statuses-in-woocommerce

don't do webhooks when order is in processing or completed state
  • Loading branch information
danielhuesken authored Jan 31, 2025
2 parents 3fefff3 + 1d6f4cc commit 6b441ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Log/WcPsrLoggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function log($level, $message, array $context = [])
if (isset($this->psrWcLoggingLevels[$level])) {
$wcLevel = $this->psrWcLoggingLevels[$level];
}

if (\WC_Log_Levels::get_level_severity($wcLevel) < \WC_Log_Levels::get_level_severity($this->loggingLevel)) {
$message = sprintf("Unknown log level %s", $wcLevel);
throw new InvalidArgumentException(esc_html($message));
Expand Down
10 changes: 10 additions & 0 deletions src/MerchantCapture/MerchantCaptureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public function run(ContainerInterface $container): bool
$pluginId . '_after_webhook_action',
static function ($payment, WC_Order $order) use ($container) {

if (!$container->get('merchant.manual_capture.enabled') || !in_array($order->get_payment_method(), $container->get('merchant.manual_capture.supported_methods'), true)) {
return;
}

if (!$payment instanceof Payment) {
return;
}
Expand Down Expand Up @@ -203,6 +207,9 @@ static function ($payment, WC_Order $order) use ($container) {
if (!is_a($order, WC_Order::class)) {
return;
}
if (!$container->get('merchant.manual_capture.enabled') || !in_array($order->get_payment_method(), $container->get('merchant.manual_capture.supported_methods'), true)) {
return;
}
$merchantCanCapture = ($container->get('merchant.manual_capture.is_authorized'))($order);
if ($merchantCanCapture) {
($container->get(VoidPayment::class))($order->get_id());
Expand All @@ -213,6 +220,9 @@ static function ($payment, WC_Order $order) use ($container) {
if (!is_a($order, WC_Order::class)) {
return;
}
if (!$container->get('merchant.manual_capture.enabled') || !in_array($order->get_payment_method(), $container->get('merchant.manual_capture.supported_methods'), true)) {
return;
}
$paymentStatus = $order->get_meta(MerchantCaptureModule::ORDER_PAYMENT_STATUS_META_KEY, true);
$actionBlockParagraphs = [];

Expand Down
6 changes: 6 additions & 0 deletions src/Payment/MollieOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public function onWebhookAction()
return;
}

if (in_array($payment->method, ['klarna', 'klarnapaylater', 'klarnasliceit', 'klarnapaynow'], true) && strpos($paymentId, 'tr_') === 0) {
$this->httpResponse->setHttpResponseCode(200);
$this->logger->debug($this->gateway->id . ": not respond on transaction webhooks for this payment method. Payment ID {$payment->id}, order ID $order_id");
return;
}

if ($order_id != $payment->metadata->order_id) {
$this->httpResponse->setHttpResponseCode(400);
$this->logger->debug(__METHOD__ . ": Order ID does not match order_id in payment metadata. Payment ID {$payment->id}, order ID $order_id");
Expand Down

0 comments on commit 6b441ad

Please sign in to comment.