Skip to content

Commit

Permalink
Merge pull request #876 from mollie/release/7.4.2-beta-1-flags
Browse files Browse the repository at this point in the history
Release/7.4.2 beta 1 flags
  • Loading branch information
mmaymo authored Jan 29, 2024
2 parents 1839e2b + 14ce783 commit 8bf8da1
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 30 deletions.
2 changes: 1 addition & 1 deletion mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 7.4.1
* Version: 7.5.0-beta1
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
Expand Down
2 changes: 1 addition & 1 deletion src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function services(): array
},
'gateway.getKlarnaPaymentMethodsAfterFeatureFlag' => static function (ContainerInterface $container): array {
$availablePaymentMethods = $container->get('gateway.listAllMethodsAvailable');
$klarnaOneFlag = apply_filters('inpsyde.feature-flags.mollie-woocommerce.klarna_one_enabled', getenv('MOL_KLARNA_ENABLED') === '1');
$klarnaOneFlag = apply_filters('inpsyde.feature-flags.mollie-woocommerce.klarna_one_enabled', true);
if (!$klarnaOneFlag) {
return array_filter($availablePaymentMethods, static function ($method) {
return $method['id'] !== Constants::KLARNA;
Expand Down
2 changes: 1 addition & 1 deletion src/MerchantCapture/Capture/Action/VoidPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __invoke()
$this->logger->error($exception->getMessage());
$this->order->add_order_note(
__(
'Payment Void Failed. We encountered an issue while canceling the pre-authorized payment.',
'Payment cancelation failed. We encountered an issue while canceling the pre-authorized payment.',
'mollie-payments-for-woocommerce'
)
);
Expand Down
9 changes: 9 additions & 0 deletions src/MerchantCapture/Capture/Type/StateChangeCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ class StateChangeCapture
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$pluginId = $container->get('shared.plugin_id');

add_action('woocommerce_order_status_changed', [$this, "orderStatusChange"], 10, 3);

/** When the webhook process is activated we don't need automatic status change. Status change is handled
* by the webhook logic.
*/
add_action($pluginId . '_before_webhook_payment_action', function () {
remove_action('woocommerce_order_status_changed', [$this, "orderStatusChange"]);
});
}

public function orderStatusChange(int $orderId, string $oldStatus, string $newStatus)
Expand Down
74 changes: 51 additions & 23 deletions src/MerchantCapture/MerchantCaptureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,55 @@ public function services(): array

public function run(ContainerInterface $container): bool
{
$pluginId = $container->get('shared.plugin_id');
$captureSettings = new MollieCaptureSettings();
add_action(
/**
* @throws \WC_Data_Exception
*/ $pluginId . '_after_webhook_action',
static function (Payment $payment, WC_Order $order) use ($container) {
if ($payment->isAuthorized()) {
if (!$payment->getAmountCaptured() == 0.0) {
return;
add_action('init', static function () use ($container) {
$pluginId = $container->get('shared.plugin_id');
$captureSettings = new MollieCaptureSettings();
if (!apply_filters('mollie_wc_gateway_enable_merchant_capture_module', true)) {
return;
}

add_action(
$pluginId . '_after_webhook_action',
static function (Payment $payment, WC_Order $order) use ($container) {

if ($payment->isAuthorized()) {
if (!$payment->getAmountCaptured() == 0.0) {
return;
}
$order->set_status(SharedDataDictionary::STATUS_ON_HOLD);
$order->update_meta_data(
self::ORDER_PAYMENT_STATUS_META_KEY,
ManualCaptureStatus::STATUS_AUTHORIZED
);
$order->set_transaction_id($payment->id);
$order->save();
} elseif (
$payment->isPaid() && (
($container->get('merchant.manual_capture.is_waiting'))($order) ||
($container->get('merchant.manual_capture.is_authorized'))($order)
)
) {
$order->update_meta_data(
self::ORDER_PAYMENT_STATUS_META_KEY,
ManualCaptureStatus::STATUS_CAPTURED
);
$order->save();
} elseif (
$payment->isCanceled() && (
($container->get('merchant.manual_capture.is_waiting'))($order) ||
($container->get('merchant.manual_capture.is_authorized'))($order)
)
) {
$order->update_meta_data(
self::ORDER_PAYMENT_STATUS_META_KEY,
ManualCaptureStatus::STATUS_VOIDED
);
$order->save();
}
$order->set_status(SharedDataDictionary::STATUS_ON_HOLD);
$order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_AUTHORIZED);
$order->set_transaction_id($payment->id);
$order->save();
} elseif ($payment->isPaid() && ($container->get('merchant.manual_capture.is_waiting'))($order)) {
$order->update_meta_data(self::ORDER_PAYMENT_STATUS_META_KEY, ManualCaptureStatus::STATUS_CAPTURED);
$order->save();
}
},
10,
2
);
},
10,
2
);

add_action('woocommerce_order_refunded', static function (int $orderId) use ($container) {
$order = wc_get_order($orderId);
Expand Down Expand Up @@ -209,7 +235,7 @@ static function ($disableShipAndCapture, WC_Order $order) use ($container) {
if ($disableShipAndCapture) {
return true;
}
return $container->get('merchant.manual_capture.is_waiting')($order);
return $container->get('merchant.manual_capture.is_waiting')($order) || $container->get('merchant.manual_capture.is_authorized')($order);
},
10,
2
Expand All @@ -223,6 +249,8 @@ static function ($disableShipAndCapture, WC_Order $order) use ($container) {
new OrderListPaymentColumn();
new ManualCapture($container);
new StateChangeCapture($container);
});

return true;
}
}
6 changes: 3 additions & 3 deletions src/MerchantCapture/MollieCaptureSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ public function settings(array $advancedSettings, string $pluginName): array
'default' => 'immediate_capture',
'desc' => sprintf(
__(
'Authorized payment can be captured or voided by changing the order status instead of doing it manually.',
'Authorized payment can be captured or canceled by changing the order status instead of doing it manually.',
'mollie-payments-for-woocommerce'
)
),
],
[
'id' => $pluginName . '_capture_or_void',
'title' => __(
'Capture or void on status change',
'Capture or cancel on status change',
'mollie-payments-for-woocommerce'
),
'type' => 'checkbox',
'default' => 'no',
'desc' => __(
'Capture authorized payments automatically when setting the order status to Processing or Completed. Void the payment by setting the order status Canceled.',
'Capture authorized payments automatically when setting the order status to Processing or Completed. Cancel the payment by setting the order status Canceled.',
'mollie-payments-for-woocommerce'
),
],
Expand Down
2 changes: 1 addition & 1 deletion src/MerchantCapture/UI/StatusRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __invoke(string $molliePaymentStatus)
);
} elseif ($molliePaymentStatus === ManualCaptureStatus::STATUS_VOIDED) {
(new StatusButton())(
__('Payment voided', 'mollie-payments-for-woocommerce'),
__('Payment canceled', 'mollie-payments-for-woocommerce'),
SharedDataDictionary::STATUS_CANCELLED
);
} elseif ($molliePaymentStatus === ManualCaptureStatus::STATUS_CAPTURED) {
Expand Down
1 change: 1 addition & 0 deletions src/Payment/MollieOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public function onWebhookAction()
}

if (method_exists($payment_object, $method_name)) {
do_action($this->pluginId . '_before_webhook_payment_action', $payment, $order);
$payment_object->{$method_name}($order, $payment, $payment_method_title);
} else {
$order->add_order_note(sprintf(
Expand Down

0 comments on commit 8bf8da1

Please sign in to comment.