Problem/Motivation

#3582241 switched Accept Hosted to send the order number as the invoiceNumber whenever the order has one, while the net.authorize.payment.authcapture.created webhook still loads the order by ID. Sites that assign order numbers before payment cannot complete orders from the webhook, and an order number that equals another order's ID loads the wrong order.

Accept.js has sent the order number when present since 2018, so the two gateways were never consistent. Some sites need the order number on the transaction; most are better served by the order ID, which is always present and unique.

The refund request also has an operator-precedence bug: 'REFUND#' . $order->getOrderNumber() ?: $order->id() concatenates first, so the fallback to the ID never runs.

Proposed resolution

  • Standardize on the order ID by default for Accept Hosted and Accept.js.
  • Add an "Invoice number" setting to both gateways ("Use the order ID" / "Use the order number"), similar to the order number strategy in Commerce Moneris Checkout. Orders without a number always send the ID.
  • Webhook lookup follows the setting with a fallback so existing transactions keep resolving:
    • Order ID: load by ID, then by order number (transactions created after #3582241).
    • Order number: load by order number, then by ID only for orders that have no number.
  • Fix the refund invoiceNumber precedence bug.
  • Kernel test coverage for both strategies, the webhook lookup, and refunds on both gateways.

Remaining tasks

  • Review MR !70.
  • Manual test of the webhook against a sandbox account with both strategies.

User interface changes

New "Invoice number" radios on the Accept Hosted and Accept.js gateway configuration forms.

API changes

New invoice_number_strategy gateway setting (default order_id) and InvoiceNumberTrait::getInvoiceNumber() / getInvoiceNumberStrategy().

Release notes snippet

Accept Hosted and Accept.js now send the order ID as the Authorize.net invoice number by default. This changes what Accept.js has sent since 2018 and reverts the Accept Hosted change from #3582241. Sites that want the order number on transactions (for example, to match invoices in the Merchant Interface) should set Invoice number to "Use the order number" on the payment gateway after updating. The Accept Hosted webhook resolves orders under either value, so existing transactions are not affected.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vmarchuk created an issue. See original summary.

vmarchuk’s picture

Assigned: vmarchuk » Unassigned
Status: Active » Needs review
vmarchuk’s picture

Title: Accept Hosted webhook cannot find the order when the order has an order number » Make the invoice number sent to Authorize.net configurable (order ID or order number)
Assigned: Unassigned » vmarchuk
Issue summary: View changes
Status: Needs review » Needs work
vmarchuk’s picture

Issue summary: View changes
vmarchuk’s picture

Assigned: vmarchuk » Unassigned
Status: Needs work » Needs review
adrianandres’s picture

Status: Needs review » Needs work
adrianandres’s picture

Status: Needs work » Reviewed & tested by the community

  • vmarchuk committed 5084751c on 2.x
    Issue #3627239: Accept Hosted webhook cannot find the order when the...
vmarchuk’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.