Problem/Motivation
The authorizenet_accept_hosted payment gateway plugin (AcceptHosted) has no way to log full Authorize.net API requests and responses for debugging. The only logging today comes from ErrorHelper::logResponse() (commerce_authnet/src/ErrorHelper.php), and it only fires for a non-Ok getResultCode() (successful calls are never logged), and even then logs a one-line summary of getMessages() codes/text — never the raw request or response body.
Concretely, none of AcceptHosted::createPayment() (AcceptHosted.php:323-325), ::capturePayment() (:654-660), ::voidPayment() (:680-690), ::refundPayment() (:719-740), or ::getPaymentPageRequestToken() (:1195-1226) record what was actually sent to or received from Authorize.net. That makes gateway-side issues (unclear declines, unexpected field values, hosted-page settings not taking effect) hard to diagnose without reproducing against a sandbox account.
#3209041 requested this for the module generally back in 2021 but has no design or work behind it. commerce_cybersource already ships exactly this for its cybersource_unified_checkout gateway, so that's the natural model to copy.
Proposed solution
Add a log_api_calls boolean gateway config option to AcceptHosted, matching Drupal\commerce_cybersource\Plugin\Commerce\PaymentGateway\UnifiedCheckout:
- defaultConfiguration(): 'log_api_calls' => 0.
- buildConfigurationForm(): a checkbox, off by default, with the same PII warning CyberSource uses ("Logs will contain personally identifiable information (PII) in plain text and should usually not be enabled in production.").
- submitConfigurationForm(): persist the value.
- At each API call site, when enabled, log the outgoing request and raw response via $this->logger (commerce_authnet.logger), e.g. in createPayment():
if ($this->configuration['log_api_calls']) {
$this->logger->notice(static::class . '::createPayment() API request: <pre>@object</pre>', ['@object' => $request->getBody()]);
}
$response = $request->execute();
if ($this->configuration['log_api_calls']) {
$this->logger->notice(static::class . '::createPayment() API response: <pre>@object</pre>', ['@object' => print_r($response->contents(), TRUE)]);
}(CommerceGuys\AuthNet\Request\BaseRequest::getBody() and Response\ResponseInterface::contents() are the SDK equivalents of CyberSource's $request_obj->__toString() / print_r($result, TRUE).)
- Same pattern for capturePayment(), voidPayment(), refundPayment(), and getPaymentPageRequestToken().
- ErrorHelper::logResponse()'s existing always-on error summary is untouched — this is additive, opt-in, full-fidelity logging alongside it.
Scoped to authorizenet_accept_hosted only. OnsiteBase/Accept.js could get the same treatment later, but that's a separate issue.
Related issues
- #3209041 — original unscoped request; this supersedes it with a concrete design mirroring commerce_cybersource.
Issue fork commerce_authnet-3624901
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
Comment #3
vmarchukComment #4
adrianandres commentedComment #6
vmarchukCommitted!