【问题标题】:Magento: Invoice and capture an authorized orderMagento:开票并获取授权订单
【发布时间】:2014-05-07 21:43:56
【问题描述】:

我正在为支付网关开发一个模块,该模块可以通过两个不同的步骤进行授权和捕获。到目前为止,我可以通过运行以下代码来授权订单:

class My_Gateway_Model_Method_Cc extends Mage_Payment_Model_Method_Cc
{
    protected $_code          = 'mycode';
    protected $_canSaveCc     = true;

    protected $_canRefund                   = true;
    protected $_isGateway                   = true;
    protected $_canAuthorize                = true;
    protected $_canCapture                  = true;
    protected $_canCapturePartial           = false;


    public function authorize(Varien_Object $payment, $amount){
        /* code to call the payment gateway and authorize the charge */
    }


    public function capture(Varien_Object $payment, $amount){
        /* some code to capture the payment */
    }
}

问题是,当我下订单,然后我进入发票面板时,我会收到以下消息:

'将在不与支付网关通信的情况下创建发票'

开票时没有捕获授权付款的选项,也没有调用捕获方法。

【问题讨论】:

  • 我已经浏览了代码,显然 Magento 在授权时将交易设置为关闭或关闭 == 1。因此,它禁用了在后端捕获付款的选项。任何想法如何在不硬编码的情况下防止这种情况发生?

标签: magento magento-1.7 magento-1.8


【解决方案1】:

好的,我找到了解决办法:

基本上,Magento 默认关闭任何授权交易,并启用在授权交易打开时捕获发票付款的选项。所以你所要做的就是将事务配置为保持开放(不关闭)

这就是我所做的:

public function authorize(Varien_Object $payment, $amount)
{
    // Leave the transaction opened so it can later be captured in backend
    $payment->setIsTransactionClosed(false);

    /*
     * Place all the code to connect with your gateway here!!!
     *
     */

    return $this;
}

【讨论】:

    【解决方案2】:

    看看最后的blog Magento Transactions部分。

    if($result['status'] == 1){  // on success result from payment gateway
        $payment->setTransactionId($result['transaction_id']);
        $payment->setIsTransactionClosed(1);
        $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('key1'=>'value1','key2'=>'value2'));
    }
    

    【讨论】:

      【解决方案3】:

      你已经设置了

      $_isGateway = true;
      

      所以你还需要设置网关url

      在您的支付模式中,扩展Mage_Payment_Model_Method_Abstract,您需要实现该方法:

      function getOrderPlaceRedirectUrl() {
          return 'http://www.where.should.we.pay.com/pay';
      }
      

      通常您会将用户重定向到您网站上的某个页面,例如 /mymodule/payment/redirect,然后在控制器的操作中处理重定向逻辑。这使您的支付模式保持干净和无状态,同时允许您收到某种“您现在正在被转移到支付网关”的消息。

      在会话变量中保存您决定重定向到何处所需的所有内容,通常是Mage::getSingleton('checkout/session')

      Magento 为 Paypal 标准提供了一个相当可靠的实现,如果混乱的话。你可以在app/code/core/Mage/Paypal/{Model/Standard.php,controllers/StandardController.php}查看他们是如何做到的。

      【讨论】:

      • 谢谢。我会将 $_isGateway 更改为 false,因为它实际上不是一个。它在后端处理付款。问题是它默认关闭支付交易。找到答案后,我将自动回答我的问题。谢谢。
      猜你喜欢
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2011-10-25
      • 2014-11-18
      • 2023-03-08
      相关资源
      最近更新 更多