Issue #3531056: Extend Accept Hosted integration for Authorize.Net to support the unified merchant payment form
#3531056: Extend Accept Hosted integration for Authorize.Net to support the unified merchant payment form.
IssueSummary
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/jquery
andcore/jquery.once
. - Added
core/once
dependency 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.js
with vanilla JS + Drupalonce()
. -
Improved iframe form submission:
- Dynamic form creation + token posting.
-
CommunicationHandler
for cancel, transactResponse, resizeWindow. - Stronger error handling + config validation (
drupalSettings
).
-
Removed deprecated
Drupal.commerceAuthorizeNetAcceptHostedForm
call.
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.
AcceptHosted.php
)
Payment Gateway Plugin (- Defined
payment_type = "accept_hosted"
+default_payment_method_type
. - Added
forms
definitions foradd-payment
andadd-payment-method
. -
onReturn()
now usestransaction_type
andamount
from route params, falling back to checkout config if missing. - Prevents order re-placement if beyond
draft
. - Applies
place
transition 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\AcceptHosted
for 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.