2
votes

Edit: This is a revised question and I am hoping that it will give me some answers :) (The original question is below the line)

I am trying to integrate a custom payment method in magento in which the workflow is similar to Paypal Standard. Which means the user will be redirected to the payment gateway for filling in the CC details. So far I have implemented this part and it's working perfectly fine.

The problem is when the order is cancelled from the admin, I need to call the update api of the payment gateway. So in the custom payment method model class, I set the $_canVoid variable to true and implemented a void method which would make the call to the api. But it doesn't get called.

After looking up the calling functions and putting breakpoints in magento's core code, I have found that void is not called because the canVoid method of Mage_Sales_Model_Order_Payment returns false which in turn is because the following expression evaluates to false

$authTransaction = $this->getAuthorizationTransaction();

I thought this is happening because I haven't implemented the authorize method in the payment method model. So I added authorize method but even that isn't getting called. In the config.xml file "authorize" is added in payment_action node.

I am not able to figure out when and from where will authorize method be called and what would I have to do so that void works upon order cancellation.

Please help..


Original Question:

I need some basic understanding of payment gateway related concepts like authorize and capture.

To give a background, I am trying to integrate a payment gateway similar to paypal standard in magento. I have completed the checkout part of integration. ie upon checkout, a hidden form with parameters is submitted as in paypal and the shopper enters the credit card details on the payment gateways site. This part works well..

Now besides this, I need to call the update-api of the payment gateway to set the status of the transaction as cancelled whenever any order is cancelled. So I added the following code in my payment methods model class

protected $_canVoid = true;

public function void(Varien_Object $payment) {
    // some code here.. 
    var_dump($payment); exit; 
}

But this method isn't getting called at all. After looking through the code, it seems that magento looks for an authorization transaction and if not found, doesn't call the above void method. Does it mean that it's necessary to call authorize method first and then only it can be void ? But with the user entering the credit card details on the payment gateways website, as per my understanding, I don't need to implement either authorize and capture as it's taken care of by the gateway service. Kindly correct if this is wrong..

I checked the Paypal Standard code in magento and there is no void method there too. Does it mean that for paypal standard like payment gateways, this wouldn't work in magento ?

Any help is appreciated.

PS. I have already gone through this question - Magento Payment flow but it doesn't quite explain why the void method wouldn't get called in my case.

1
Have you ever visit this site? Creating Your Own Payment GatewayOğuz Çelikdemir
thanks for the link. i see that it's for payment methods where the credit card info is accepted on the store website itself. In my case, the shoppers enter the cc details on the payment gateways' site. So I guess, the payment method class in magento doesn't need to authorize/capture. but i need to make a call to the update-api to void/refund when order is cancelled and credit memo is clicked. My question is, is this possible or have I not understood the concepts of authorize/capture/void (in general) not clearly ?naiquevin

1 Answers

1
votes

If you want to void an authorization, you have to prevent transaction from being closed.

Of course you can do it the bad way (re-implementing _addTransaction just like authorize.net implementation)

But the best approach is to call setIsTransactionClosed method with false, in the authorize method of your custom payment gateway.

It's an undocumented feature, and you'll have a hard time finding it in your IDE as this method sets an internal member of Mage_Sales_Model_Order_Payment through PHP's magic __call method.

$payment->setIsTransactionClosed(false);