Change: The Commerce Payment module has been enhanced to improve the handling of orders with a zero balance. The update introduces new event subscribers and interfaces to manage payment method requirements and the availability of payment gateways for zero balance orders. This allows for greater flexibility in handling cases where the order total is zero, yet payment methods may still need to be collected.
Key Features:
- Zero Balance Order Support: A new
SupportsZeroBalanceOrderInterfacehas been introduced, requiring each payment gateway to explicitly declare if it can handle zero balance orders. Gateways that implement this interface will be available for selection during checkout even when the order total is zero, allowing them to manage payment method collection and storage in such scenarios. - Event for Requiring Payment Method: A new event,
PaymentEvents::REQUIRE_PAYMENT_METHOD, has been added to control whether a payment method is required during checkout, even if the order balance is zero. The event is handled by theRequirePaymentMethodEventclass. - Zero Balance Order Subscriber: The
ZeroBalanceOrderSubscriberclass has been introduced to filter out payment gateways that do not support zero balance orders, ensuring that only relevant gateways are available for such orders. - Payment Checkout Pane Enhancements: The
PaymentCheckoutPaneBaseclass has been added as a base class for checkout panes that handle payment processing. It includes logic to determine if only billing information should be collected when payment methods are not required. - Configuration Options: The
PaymentInformationcheckout pane now includes a new configuration option,require_payment_method, allowing site builders to specify whether payment methods should be collected for zero balance orders.
Important Note: The default behavior in Checkout hasn't changed —zero balance orders will only collect the billing address unless explicitly opted-in to the new feature. In headless scenarios, such as when using the commerce_api module, if the order balance is zero, the corresponding endpoint will now only return payment gateways that explicitly support zero balance orders.
Usage:
- To enable payment method collection for zero balance orders, ensure that your payment gateway implements the
SupportsZeroBalanceOrderInterface. - Use the new
require_payment_methodconfiguration option in the PaymentInformation checkout pane to control whether payment methods are required, even for zero balance orders. - Subscribe to the
PaymentEvents::REQUIRE_PAYMENT_METHODevent if you need to programmatically alter the requirement for payment methods during checkout.