简体   繁体   English

magento自定义支付网关集成中未调用void方法

[英]void method not getting called in magento custom payment gateway integration

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. 我正在尝试在magento中集成自定义付款方式,该方式的工作流程类似于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. 问题是,当从管理员取消订单时,我需要调用支付网关的更新api。 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. 因此,在自定义付款方法模型类中,我将$_canVoid变量设置为true并实现了一个void方法,该方法将调用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 找了通话功能,并把断点在Magento的核心代码后,我发现, void不叫,因为canVoid的方法Mage_Sales_Model_Order_Payment返回false这又是因为下列表达式的值为false

$authTransaction = $this->getAuthorizationTransaction();

I thought this is happening because I haven't implemented the authorize method in the payment method model. 我以为是因为没有在付款方式模型中实现authorize方式。 So I added authorize method but even that isn't getting called. 因此,我添加了authorize方法,但即使这样也没有被调用。 In the config.xml file "authorize" is added in payment_action node. 在config.xml文件中,在payment_action节点中添加了“授权”。

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. 为了提供背景知识,我正在尝试在magento中集成类似于paypal标准的支付网关。 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 . 即,在结帐时,将提交带有参数的隐藏表格,如在paypal中一样, 购物者将在付款网关网站上输入信用卡详细信息 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. 现在,除此之外,每当取消任何订单时,我都需要调用支付网关的update-api来将交易状态设置为取消。 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. 浏览完代码后,似乎magento正在寻找授权交易,如果找不到,则不会调用上述void方法。 Does it mean that it's necessary to call authorize method first and then only it can be void ? 这是否意味着有必要先调用authorize方法,然后才可以将其无效? 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. 我检查了magento中的Paypal标准代码,那里也没有void方法。 Does it mean that for paypal standard like payment gateways, this wouldn't work in magento ? 这是否意味着对于Paypal标准(例如付款网关),这在magento中不起作用?

Any help is appreciated. 任何帮助表示赞赏。

PS. 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. 我已经经历了这个问题-Magento付款流程,但是并不能完全解释为什么在我的情况下不会调用void方法。

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) 当然,您可以用不好的方法来做到这一点(像authorize.net实现一样重新实现_addTransaction)

But the best approach is to call setIsTransactionClosed method with false, in the authorize method of your custom payment gateway. 但是最好的方法是在自定义支付网关的authorize方法中使用false调用setIsTransactionClosed方法。

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. 这是一个未记录的功能,您将很难在IDE中找到它,因为此方法通过PHP的魔术__call方法设置了Mage_Sales_Model_Order_Payment的内部成员。

$payment->setIsTransactionClosed(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM