It seems like you’re experiencing issues when trying to capture previously authorized transactions using Authorize.net’s Authorize.net Direct Post Method (ADPM) within your Magento Enterprise store. The error message “A valid referenced transaction ID is required” suggests that the necessary transaction details are missing in your request.
To troubleshoot this issue, let’s analyze the request and response data you provided:
Request:
x_typeis set to PRIOR_AUTH_CAPTURE, which indicates that a previously authorized transaction is being captured.- The
x_amountfield contains the amount to be captured (127.48 USD). - However, the
x_trans_idfield is left empty, which is required for capturing an existing transaction.
Response:
- The
response_codeis 3, andresponse_subcodeis 2. - The
response_reason_textstates “A valid referenced transaction ID is required.” - Notice that the
transaction_idin the response is 0, indicating a failure to capture the transaction.
The issue seems to stem from the missing x_trans_id field in your request. When capturing an existing authorized transaction using ADPM, you need to include the x_trans_id of the original authorization transaction in your capture request. This ID can be found in the response of the previous authorization request or retrieved from Magento’s database.
To resolve this issue:
- Ensure that when performing a prior authorization, you store the returned
transaction_id(which is available in the response) and associate it with the corresponding order or payment record. - Before sending a capture request for an authorized transaction, retrieve the stored
x_trans_idfrom your database or the order details. - Include the retrieved
x_trans_idin thex_trans_idfield of the capture request.
Here’s an example of how you can modify your code to include the transaction_id:
// Retrieve the transaction ID associated with the order
$order = $payment->getOrder();
$transactionId = $this->getTransactionIdForOrder($order);
// Include the retrieved transaction ID in the capture request
$this->createTransaction(
$pID,
$ppID,
$amount,
$lastOrderId,
"profileTransAuthCapture",
$cvv,
$transactionId
);
You can create a custom method getTransactionIdForOrder() to retrieve the transaction ID for a given order from your database or use Magento’s payment and transaction management system.
By ensuring that you have stored the correct x_trans_id and including it in the capture request, you should be able to successfully capture previously authorized transactions without encountering the “A valid referenced transaction ID is required” error.