Issue #3531056: Extend Accept Hosted integration for Authorize.Net to support the unified merchant payment form
Issue #3531056: Extend Accept Hosted integration for Authorize.Net to support the unified merchant payment form.
Summary
This MR refactors and extends the commerce_authnet Accept Hosted integration, modernizing its frontend code and improving how transaction type, amount, and contexts are handled across both checkout and merchant payment flows.
Key changes
Libraries
- Removed deprecated
core/jqueryandcore/jquery.once. - Added
core/oncedependency toform-accept-hosted.
Module / Form handling
- Updated
commerce_authnet_form_alter()to passEntityContext::fromEntity($order)and build contexts before rendering Accept Hosted forms.
Services
- Added new event subscriber:
commerce_authnet.payment_options_subscriber.
JavaScript
-
Replaced old jQuery-based
commerce_authnet.accept_hosted.form.jswith vanilla JS + Drupalonce(). -
Improved iframe form submission:
- Dynamic form creation + token posting.
-
CommunicationHandlerfor cancel, transactResponse, resizeWindow. - Stronger error handling + config validation (
drupalSettings).
-
Removed deprecated
Drupal.commerceAuthorizeNetAcceptHostedFormcall.
Event Subscriber
-
Introduced
PaymentOptionsSubscriber:- Ensures Accept Hosted payment options include their payment method type ID.
- Fixes downstream issues when the gateway doesn’t explicitly set it.
Payment Gateway Plugin (AcceptHosted.php)
- Defined
payment_type = "accept_hosted"+default_payment_method_type. - Added
formsdefinitions foradd-paymentandadd-payment-method. -
onReturn()now usestransaction_typeandamountfrom route params, falling back to checkout config if missing. - Prevents order re-placement if beyond
draft. - Applies
placetransition only when valid. - Refactored
getPaymentPageRequestToken()to accept explicitcapture+Price $amount. - Updated
getAcceptHostedCheckoutForm()to use context array (capture, amount, order, continueUrl, cancelUrl).
Payment Type
- Added
Plugin\Commerce\PaymentType\AcceptHostedfor dedicated type definition.
Plugin Form
-
Added
PluginForm\AcceptHosted\PaymentMethodAddForm:- Delegates form building to gateway plugin via context.
- Context includes capture, amount, order, continueUrl, cancelUrl.
- Preserves merchant-selected transaction type + amount across return.
- Empty validate/submit hooks since hosted form handles them.
Why
Previously, Accept Hosted assumed transaction type + amount from checkout config (capture pane) and order total. This broke when merchants selected different values in the “Add payment” flow. By introducing context-driven form building and explicit route params, merchant-selected values are now preserved consistently.
Impact
- Correctly preserves merchant-selected transaction type and amount.
- Aligns with Commerce core patterns (contexts, event subscribers).
- Modernizes frontend (drops jQuery).
- Provides a cleaner extension point for future enhancements.