Skip to content

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/jquery and core/jquery.once.
  • Added core/once dependency to form-accept-hosted.

Module / Form handling

  • Updated commerce_authnet_form_alter() to pass EntityContext::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 + Drupal once().

  • 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.

Payment Gateway Plugin (AcceptHosted.php)

  • Defined payment_type = "accept_hosted" + default_payment_method_type.
  • Added forms definitions for add-payment and add-payment-method.
  • onReturn() now uses transaction_type and amount 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 explicit capture + 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.
Edited by Adrian M.

Merge request reports

Loading