Magento中的交易ID和支付对象

时间:2013-01-25 15:52:30

标签: php magento variables

我的问题可能看起来很流行,但我面临困难......

部分功能代码是

 public function capture(Varien_Object $payment, $amount){

            if(!$this->isEnabled()){
                return parent::capture($payment, $amount);
            }else{
    ---- MORE CODE--
    $quote = Mage::getSingleton('customer/session');
        $nickname = $quote->getAuthorizenetNickname();
        $profile = $quote->getProfile();
        $postedNickname = $quote->getNickname();

        if ($payment->getCcTransId()) {
        $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
        } else {
        $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE);
        }

        $payment->setAmount($amount);

        $request= $this->_buildRequest($payment);
        $result = $this->_postRequest($request);

        MORE CODE HERE, NOT RELEVENT TO MY ISSUE    

我在这里有两个问题

我如何通过

进行交易ID
$payment->setAmount($amount);   
$request= $this->_buildRequest($payment);
$result = $this->_postRequest($request);

,第二个问题是

  

如何回传/调试传递的transactionID值

对你来说可能很容易,但我失败了

到目前为止

尝试了

$payment->setTransID($payment->gerOrder->getTransID());   
and 
$payment->gerOrder->getTransID()
$payment->setAmount($amount);   
$request= $this->_buildRequest($payment);

感谢您的帮助和指南

2 个答案:

答案 0 :(得分:7)

之前我已经完成了这个问题,这是我的发现:)

付款与交易完全不同,尽管它们有关系。

付款对象包含有关订单总数的完整信息(折扣,总计,取消,运送等...)

交易仅保留与例如来自支付网关(txn_idparent_txn_id的相关信息 - 如果它具有父母交易 - 等等......)因此它不会支付多少费用/多少钱/多少取消/发货等..

  • 付款与交易有一对多的关系(因此您无法为其设置交易ID)您需要将last_trans_id设置为付款或者如果是信用卡交易(一次)您可以设置并使用此字段cc_trans_id 换句话说,如何将交易分配给付款,您需要执行以下操作: -
    • 创建分配给订单的新付款对象并保存所有数据等。(或者如果您从支付网关返回,则加载订单/报价并获取付款对象$order->getPayment();
    • 创建交易对象将其分配给该paymentID和订单ID等。然后保存
    • last_trans_id分配给付款对象并保存!
    • 然后使用该付款对象保存订单,或将已分配的付款对象保存到该订单。

我希望这可以帮助你:)

请找到我为将付款添加到付款

所做的付款集成示例
    /**
 * Creates Transactions for directlink activities
 *
 * @param Mage_Sales_Model_Order $order
 * @param int $transactionID - persistent transaction id
 * @param int $subPayID - identifier for each transaction
 * @param array $arrInformation - add dynamic data
 * @param string $typename - name for the transaction exp.: refund
 * @param string $comment - order comment
 * 
 * @return Cashu_Helper_DirectLink $this
 */
public function directLinkTransact($order,$transactionID, $subPayID,
    $arrInformation = array(), $typename, $comment, $closed = 0)
{
    $payment = $order->getPayment();
    $payment->setTransactionId($transactionID."/".$subPayID);
    $transaction = $payment->addTransaction($typename, null, false, $comment);
    $transaction->setParentTxnId($transactionID);
    $transaction->setIsClosed($closed);
    $transaction->setAdditionalInformation("arrI    nfo", serialize($arrInformation));
    $transaction->save();
    $order->save();
    return $this;
}

答案 1 :(得分:2)

我也正在构建CIM支付模块。所以我确切地知道你要经历什么(我想我差不多完成了,但是过去3周我一直都这么说)

从您上面的代码中,您似乎正在尝试执行PRIOR_AUTH_CAPTURE,这意味着您应该在执行AUTH_ONLY事务时存储事务ID。

看看

  

/app/code/core/Mage/Paygate/Model/Authorizenet.php

设置交易ID(PRIOR_AUTH_CAPTURE

的代码
protected function _preauthorizeCaptureCardTransaction($payment, $amount, $card)
{
    $authTransactionId = $card->getLastTransId();
    $authTransaction = $payment->getTransaction($authTransactionId);
    $realAuthTransactionId = $authTransaction->getAdditionalInformation($this->_realTransactionIdKey);

    $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE);
    $payment->setXTransId($realAuthTransactionId);

保存交易ID的代码(AUTH_ONLY

protected function _place($payment, $amount, $requestType)
{
    ....
    switch ($result->getResponseCode()) {
        case self::RESPONSE_CODE_APPROVED:
            $this->getCardsStorage($payment)->flushCards();
            $card = $this->_registerCard($result, $payment); //<-- take a look at

    .....

    $this->_addTransaction(
          $payment,
          $card->getLastTransId(),
          $newTransactionType,
          array('is_transaction_closed' => 0),
          array(
              $this->_realTransactionIdKey => $card->getLastTransId(), //<-- take a look at
              $this->_isTransactionFraud => true
          ),

更新

$payment->setAmount($amount);   
$payment->setXTransId({put your transaction id here});
$payment->setAnetTransType($requestType);
$request= $this->_buildRequest($payment);
$result = $this->_postRequest($request);

然后在构建您的请求时

protected function _buildRequest(Varien_Object $payment)
{
   ....
   switch ($payment->getAnetTransType()) {
   .....
        case self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE: //<-- for all the request that need Transaction id 
            $request->setXTransId($payment->getXTransId());
            break;