Search code examples
magentomagento-1.7authorize.net

Cancel Magento Orders With Expired Pre-Authorization


I have some orders in my Magento site that are older than 30 days so the authorize.net pre-auth has expired. When I go to cancel the orders, it tries to submit the pre-auth void but it fails because the original transaction no longer exists. Is there any way to manual override this void procedure and simply cancel an order in this state?


Solution

  • Take a look @

    /app/code/core/Mage/Paygate/Model/Authorizenet.php

    Turn on debugging for your payment module to see the result of $result->getResponseCode() for an expired transaction. Once you figure out what the result (code/error code) are, you could create a new 'case' that mimic case self::RESPONSE_CODE_APPROVED:

    Also take a look @ $this->_isTransactionExpired($realAuthTransactionId) to see why it isn't catching your expired transaction.

    protected function _voidCardTransaction($payment, $card)
    {
        $authTransactionId = $card->getLastTransId();
        $authTransaction = $payment->getTransaction($authTransactionId);
        $realAuthTransactionId = $authTransaction->getAdditionalInformation($this->_realTransactionIdKey);
    
        $payment->setAnetTransType(self::REQUEST_TYPE_VOID);
        $payment->setXTransId($realAuthTransactionId);
    
        $request= $this->_buildRequest($payment);
        $result = $this->_postRequest($request);
    
        switch ($result->getResponseCode()) {
            case self::RESPONSE_CODE_APPROVED:
                if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) {
                    $voidTransactionId = $result->getTransactionId() . '-void';
                    $card->setLastTransId($voidTransactionId);
                    return $this->_addTransaction(
                        $payment,
                        $voidTransactionId,
                        Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID,
                        array(
                            'is_transaction_closed' => 1,
                            'should_close_parent_transaction' => 1,
                            'parent_transaction_id' => $authTransactionId
                        ),
                        array($this->_realTransactionIdKey => $result->getTransactionId()),
                        Mage::helper('paygate')->getTransactionMessage(
                            $payment, self::REQUEST_TYPE_VOID, $result->getTransactionId(), $card
                        )
                    );
                }
                $exceptionMessage = $this->_wrapGatewayError($result->getResponseReasonText());
                break;
            case self::RESPONSE_CODE_DECLINED:
            case self::RESPONSE_CODE_ERROR:
            if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_NOT_FOUND
                && $this->_isTransactionExpired($realAuthTransactionId)
            ) {
              .....
    
    
    public function canVoid(Varien_Object $payment)
    {
        if ($this->_isGatewayActionsLocked($this->getInfoInstance())) {
            return false;
        }
        return $this->_isPreauthorizeCapture($this->getInfoInstance());
    }