Magento: Invoice and capture an authorized order

Magento: Invoice and capture an authorized order

August 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Invoice and capture an authorized order

Solving Payment Authorization and Capture Issues in Magento

As a senior developer working on Magento payment gateway integrations, I frequently encounter scenarios where clients require two-step processing—authorization followed by capture—for their e-commerce checkout flows. This blog post will guide you through resolving the issue of capturing an authorized order within the Magento invoicing panel.

Understanding the Two-Step Payment Process

Before we dive into the code, let’s clarify the concept of authorizing and capturing a payment. Authorizing involves validating the credit card details without immediate charge, while capturing triggers the actual transaction to collect funds from the customer’s account.

In your current setup, you’ve correctly defined the authorize method in your custom payment method class:

public function authorize(Varien_Object $payment, $amount){
    /* code to call the payment gateway and authorize the charge */
}

However, when you attempt to capture the authorized transaction through the invoicing panel, Magento fails to communicate with your custom payment gateway. This leads to the error message: “Invoice will be created without communication with payment gateway.”

Resolving the Capture Issue

To fix this issue, we need to ensure that Magento can recognize and process the capture request through your custom payment method. Here are the steps you should follow:

  1. Enable Capture in Payment Configuration

    • Navigate to System > Configuration > Payment Methods.
    • Find your custom payment method (Mycode) under the list of methods.
    • Ensure that both “Use for Authorize” and “Use for Capture” are enabled.
  2. Implement the Capture Method

    In your Capture method, you need to call the appropriate API endpoint provided by your payment gateway to process the authorized transaction:

public function capture(Varien_Object $payment, $amount)
{
    // Retrieve the authorization transaction ID from the payment object
    $authorizationTransactionId = $payment->getCcTransId();

    if (!empty($authorizationTransactionId)) {
        try {
            // Call your payment gateway's API to capture the authorized amount
            $response = $this->_gateway->capture(
                $authorizationTransactionId,
                $amount
            );

            // Process the response and update the transaction details in Magento
            if ($response['success']) {
                $payment->setAmountAuthorized($amount);
                $payment->setCcTransId($response['transaction_id']);
            } else {
                Mage::throwException('Capture failed: ' . $response['error_message']);
            }
        } catch (Exception $e) {
            // Handle exceptions and ensure the capture fails gracefully
            Mage::logException($e);
            throw new Exception('Error capturing transaction');
        }
    }

    return $this;
}
  1. Handle Partial Capture

    If your payment gateway supports partial captures, make sure you enable this functionality in Magento by setting $_canCapturePartial to true.

protected $_canCapturePartial           = true;

*Conclusion: Capturing Authorized Transactions

By following these steps and ensuring that your custom payment method is properly configured within the Magento administration panel, you should now be able to successfully capture authorized transactions through the invoicing interface.

Remember to thoroughly test this implementation in a staging environment before deploying it to production. Proper error handling and logging are crucial for maintaining a stable checkout process.

For more detailed information on working with custom payment methods in Magento, I recommend exploring our comprehensive guide at Laravel Company’s Magento Payment Gateway Integration Tutorial.

Don’t hesitate to reach out if you have any further questions or need assistance with your Magento development projects.

Checkout Configuration Orders Customers

Our network