Php 如何在magento中使用付款方式取消订单
我正在为Magento创建一个开源扩展。它处于非常早期的阶段。我正在努力解决取消订单的问题。我在这里找到了一些解决办法 但每当我取消订单时,它既不会调用void(在仅授权支付操作的情况下)也不会调用return(在授权捕获支付操作的情况下) 当我使用“捕获退款”时,它表示订单无法取消 当我使用authorize void时,它表示订单已被取消。但是Void()函数根本没有被调用。我在里面保存了一些Mage::Log()函数。日志文件中未显示的 我不明白怎么了 这是代码。 这是付款方式模型Php 如何在magento中使用付款方式取消订单,php,zend-framework,magento,Php,Zend Framework,Magento,我正在为Magento创建一个开源扩展。它处于非常早期的阶段。我正在努力解决取消订单的问题。我在这里找到了一些解决办法 但每当我取消订单时,它既不会调用void(在仅授权支付操作的情况下)也不会调用return(在授权捕获支付操作的情况下) 当我使用“捕获退款”时,它表示订单无法取消 当我使用authorize void时,它表示订单已被取消。但是Void()函数根本没有被调用。我在里面保存了一些Mage::Log()函数。日志文件中未显示的 我不明白怎么了 这是代码。 这是付款方式模型 &l
<?php
class Package_Cashondelivery_Model_Createorder extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'cashondelivery';
protected $_canCapture = true;
protected $_canUseCheckout = true;
protected $_canFetchTransactionInfo = true;
protected $_isGateway = true;
protected $_canUseInternal = true;
protected $_canVoid = true;
protected $_canRefund = true;
public function validate()
{
$paymentInfo = $this->getInfoInstance();
if ($paymentInfo instanceof Mage_Sales_Model_Order_Payment) {
$postCode = $paymentInfo->getOrder()->getBillingAddress()->getPostcode();
}
else {
$postCode = $paymentInfo->getQuote()->getBillingAddress()->getPostcode();
}
$res=Api->validatePostCode($postCode);
$r = $res=='false'? FALSE : TRUE;
if (!$r) {
Mage::throwException($this->_getHelper()->__('Sorry ! Service is not available in your area'));
}
return $this;
}
public function authorize(Varien_Object $payment, $amount)
{
-------------------------------
-------------------------------
-------------------------------
#This is working fine
$transactionId = Api->someCall();
$payment->setTransactionId();
-------------------------------
-------------------------------
-------------------------------
-------------------------------
-------------------------------
-------------------------------
return $this;
}
public function void(Varien_Object $payment)
{
if (!$this->canVoid($payment)) {
Mage::throwException($this->_getHelper()->__('Void action is not available.'));
}
-------------------------------
-------------------------------
-------------------------------
-------------------------------
Mage::Log('Starting Void here....');
$transactionId = $Payment->getTransactionId();
Api->cancelOrder($transactionId);
return $this;
-------------------------------
-------------------------------
-------------------------------
}
}
?>
这里是配置文件
<?xml version="1.0"?>
<config>
<modules>
<Package_Cashondelivery>
<!-- declare module's version information for database updates -->
<version>0.1.0</version>
</Package_Cashondelivery>
</modules>
<global>
<!-- declare model group for new module -->
<models>
<!-- model group alias to be used in Mage::getModel('newmodule/...') -->
<cashondelivery>
<!-- base class name for the model group -->
<class>Package_Cashondelivery_Model</class>
</cashondelivery>
</models>
<helpers>
<cashondelivery>
<class>Package_Cashondelivery_Helper</class>
</cashondelivery>
</helpers>
<!-- declare resource setup for new module -->
<resources>
<!-- resource identifier -->
<cashondelivery_setup>
<!-- specify that this resource is a setup resource and used for upgrades -->
<setup>
<!-- which module to look for install/upgrade files in -->
<module>Package_Cashondelivery</module>
</setup>
<!-- specify database connection for this resource -->
<connection>
<!-- do not create new connection, use predefined core setup connection -->
<use>core_setup</use>
</connection>
</cashondelivery_setup>
<cashondelivery_write>
<connection>
<use>core_write</use>
</connection>
</cashondelivery_write>
<cashondelivery_read>
<connection>
<use>core_read</use>
</connection>
</cashondelivery_read>
</resources>
</global>
<!-- declare default configuration values for this module -->
<default>
<payment>
<cashondelivery>
<active>1</active>
<model>cashondelivery/createorder</model>
<order_status>Processing</order_status>
<payment_action>authorize</payment_action>
<title>Cash On Delivery</title>
<example_uri>services.example.com</example_uri>
</cashondelivery>
</payment>
</default>
</config>
0.1.0
套餐\现金交付\模式
包裹\现金交付\助手
包裹/现金交付
核心单元设置
核心写入
核心读取
1.
现金交付/创建订单
处理
授权
货到付款
services.example.com
任何人都知道为什么会发生这种情况以及如何解决。遗憾的是,我没有足够的“经验”来发表评论,所以我将把这篇文章作为一个答案
在取消之前,您能确认订单处于正确的状态吗?例如,有些订单是自动处理的,比如软件下载。信用卡收费和产品分销都可以自动完成,那么我怀疑它是否允许您取消。您可以验证订单是否仍处于挂起状态吗?您应该只能对尚未捕获的订单执行“取消”或“作废”操作。i、 e.没有关联发票的订单 如果您想退还捕获的订单,则应通过在发票上创建信用备忘录来实现 对于您的支付方法的无效函数未被调用的问题,您应该使用X-Debug设置一个类似Netbeans的IDE,并在Mage\u Adminhtml\u Sales\u OrderController中的取消操作和作废付款操作函数的第一行中放置一个断点。通过这种方式,您可以逐步查看代码并查看问题所在 例如,到void的路径应该类似于 Mage\u Adminhtml\u Sales\u OrderController->作废付款操作:629
Mage\u Sales\u Model\u Order\u Payment->作废:602
Mage\u Sales\u Model\u Order\u Payment->\u void:1088
包裹\u现金交付\u模型\u创建订单->无效:
因此,如果您不想使用适当的调试环境,请将日志语句放在该路径上,并检查所有条件是否有效,以调用付款方法的void函数。问题是,Magento确实不调用void,也不在按cancel时调用Return。当您按void时,它将运行void方法,当您单击return时,它将调用return方法。猜猜看,当你按下cancel时,它实际上调用了cancel方法 我同意当你按下cancel键时,你实际上想使授权无效,但是如果你想做其他事情,有单独的方法是很方便的。所以你可以这样做:
/*
* Your class stuff
*/
public function cancel(Varien_Object $payment){
// void the order if canceled
$this->void($payment);
return $this;
}
public function void(Varien_Object $payment){
/* Whatever you call to void a payment in your gateway */
}
我正试图取消一个由相同付款方式创建的订单。这没有意义。当然,付款方式是一样的,我们只谈一份订单。您能进一步解释吗?当我下订单时,authorize方法被调用…authorize方法进行rest api调用并得到响应。作为响应,我从Api中获取唯一的引用Id,并将其作为transactionId存储在Magento中。订单成功后,我选择相同的订单并尝试取消。它显示订单已成功取消,但Void()函数中的API调用未发生。这是我不理解的原因。我可以知道什么是强制标志,如canVoid、canCancel等。这里有人可以帮助我吗?我也有同样的问题!