Magento Forum

   
Invoice Void issue
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

Ok, I’m still searching for the root cause of this, but I’d thought I’d post here in the meantime to see if any of you have an idea (mainly Moshu).

I’ve set up a new payment method for my company. Creating an order and sending the payment data through is working correctly. I am currently working on when the order is voided through Magento, it voids it from our system as well.

My problem is, I can get it to void in our system, but I ALWAYS get “Invoice Void Error” from Magento. Magento never correctly voids the invoice/transaction. For some reason when I call the Void function in my module, $payment->getVoidTransactionId() is undefined. Thus is catches the exception and doesnt void. Anyone know why this might be?

Here’s my void function code. Let me know if there is more you need as I’m not sure if there is something somewhere else that needs to be defined/set in order for this to work.

public function void(Varien_Object $payment)
    
{
        
if($payment->getVoidTransactionId()){
            $gateway 
= new Gateway();
            
$dynamicKey = new DynamicKey($gateway);
            
$gateway->CancelPayment$dynamicKey->key $payment->getCcTransId() , NULL);
            
$payment->setStatus(self::STATUS_SUCCESS );
        
}
        
else
        
{
            $payment
->setStatus(self::STATUS_ERROR);
        
}
        
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

First thing I would check is if there is any actual data being passed to the $payment object, i.e. do a var_dump($payment) at the beginning of the function to see what is being passed.  Secondly if there is data being passed then does the getVoidTransactionId() actually correspond to an existing database field or to another function?  Usually if you are calling get(something here) then it is corresponding to a database field.  In this case it would be void_transaction_id.  That would be where I would start from.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

So I did a vardump of payment. It’s definitely getting data. Problem is, it’s getting so much data that it outputted more and more data for 10+ minutes and eventually crashed my browser from using too much memory (recursive). Is there a way to filter it possibly?

Also, tracing the void calls, I was able to track down a void call in adminhtml/controllers/sales/order/invoicecontroller.php. Which then lead me to mage/sales/order/payment.php.

I can throw an exception and see it up until after the dispatchEvent function (in the void function in payment.php). After that, instead of my exception it throws the “Invoice Void Error” exception. This isn’t hugely relevant other then for me to maybe find a flag or something that I need to have set in my code, but i was unsuccessful in finding anything of the sort.

I modeled my payment module from the authorizenet module. I’m not sure what they are doing in their module that I’m not.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

So the only difference (that I think matters anyway) between my code and authorizenet’s code is in the capture function.

Authorizenet has a line: $payment->setLastTransId($result->getTransactionId());

In my capture function, I had added $payment->setLastTransId($payment->getTransactionId());

$result, in authorizenet, is “messed with” in their _postresponse function. I’m not sure whether or not it matters, but is there a flag in that function that is getting set that I’m not doing?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

I had that same thing happen in a var_dump I did with returning order info for printing into a pdf.  There must be a loop somewhere that I am not selecting only the relevant one’s I need.  How is the $result in Authorizenet being computed?  Is it any different then how you are computing your $payment variable?  There is a way to filter it but I haven’t quite found the exact call yet, though I haven’t looked very hard either.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

Ok. I’m pretty sure I found the issue, but I don’t know where to get the values to set.

Authorize.net does mess with $result by setting the invoice number and transaction id using setInvoiceNumber and setTransactionId. It also sets a bunch of other stuff, but I doubt they are relevant for what I’m doing.

I’m not using setInvoiceNumber() or setTransactionId() anywhere. Pretty sure this is why it doesn’t work. Do you guys know where I can get the values from to set? Authorize uses some http page to get all the info and then explodes it into an array at which point it sets all those variables. So the only way to see what it’s getting I would have to pay using authorize.net and throw an exception in there which just isnt possible as I don’t have an authorize.net account nor do i want one.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

I’m getting ever so slightly closer. Still not there though.

I found how to set the void_transaction_id object (the one that getVoidTransactionId gets its value from). The question is, does it have to be set to something specific like the order number? I set it to the transaction id for our system (since I was already saving that anyway) and its still giving me a void error.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

This is what the exception message inplace of “Invoice Void Error”

exception ‘Exception’ with message ‘Notice: Undefined variable: invoice in /home/tbrown/web/magento/app/code/core/Mage/Sales/Model/Order/Payment.php on line 262’ in /home/tbrown/web/magento/app/code/core/Mage/Core/functions.php:244

 
Magento Community Magento Community
Magento Community
Magento Community
 
Troy Brown
Jr. Member
 
Total Posts:  14
Joined:  2008-05-29
 

I figured it out.

Anyone that works for Magento, you need to know this as it is a problem with the base code.

The invoice variable that my last post refers to is in Mage/Sales/Model/Order/Payment.php

public function void(Varien_Object $document)
{
        $this
->getMethodInstance()->processBeforeVoid($document$this);
        
//$this->getMethodInstance()->void($document);
        
$this->getMethodInstance()->void($this);
        
Mage::dispatchEvent('sales_order_payment_void', array('payment' => $this'invoice' => $invoice));
        
        return 
$this;
}

Should be

public function void(Varien_Object $document)
{
        $this
->getMethodInstance()->processBeforeVoid($document$this);
        
//$this->getMethodInstance()->void($document);
        
$this->getMethodInstance()->void($this);
        
Mage::dispatchEvent('sales_order_payment_void', array('payment' => $this'invoice' => $document));
        
        return 
$this;
}

So $invoice should change to $document as there is not reference to an $invoice variable anywhere in that function. I changed it and it works great now. I’m honestly surprised that I’m the first one to find this. No one else has ever tried to void?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

Nope, I don’t do invoicing through Magento, just collect the orders for printout.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
Quiddity
Jr. Member
 
Total Posts:  22
Joined:  2008-06-13
 

I’m trying to display authorize.net Transaction Id and Authorization Code both in my admin invoice view and also have it displayed when I print the invoice.

Thx in advance

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top