1

My question might looks vogue, but I am facing difficult over it..

part of function code is

 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    

I got two question here

HOW CAN I PASS TRANSACTION ID IN

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

and 2nd question is

how can I Echo / debug value of transactionID being passed

might be very easy for you, but I am at failure

tried so far

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

thanks for your help and guideline

Zaffar Saffee
  • 6,167
  • 5
  • 39
  • 77

2 Answers2

8

I have ran through this issue before and here is my findings :)

Payment is completely different from Transaction although they have a relation.

Payment objects holds complete information about the order totals ( discounts , grand total, canceled , shipping , etc... )

Transaction only hold the information related to if for instance from payment gateway ( txn_id,parent_txn_id - if it has parent trans - ,etc... ) so it's not away of how much paid/how much left/how much cancelled/shipped etc..

  • Payment has One-To-Many Relation with Transaction ( so you cant set Transaction Id to it ) You need to set last_trans_id to the payment or if it's credit card transaction ( onetime ) You can set and use this field cc_trans_id In other words How to assign transaction to payment, you need to do as follow:-
    • Create New Payment Object assigned to the order and save all your data etc.. ( or if you coming back from payment gateway you load the order/quote and get the payment object $order->getPayment(); )
    • Create Transaction Object assign it to that paymentID and order ID , etc.. Then save it
    • Assign last_trans_id to the payment object and save it !
    • Then save the order with that payment object or save the payment object its already assigned to that order.

I hope this helps you :)

Please find the code Example of payment integration I have done to add transaction to the payment

    /**
 * 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;
}
Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
Meabed
  • 3,828
  • 1
  • 27
  • 37
2

I'm also in the process of building a CIM payment module. So i know exactly what your going thru (I think I'm almost finish, but then again I have been saying that for the last 3 weeks)

From your code above it seem like you are trying to do a PRIOR_AUTH_CAPTURE which mean that you should have store the transaction id when you did AUTH_ONLY transaction.

Take a look at

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

Code to set transaction 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);

Code to saving transaction 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
          ),

Update

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

Then when building your 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;
MagePal Extensions
  • 17,646
  • 2
  • 47
  • 62
  • you got me quite near buddy, but my issue is not how can I save transaction ID, I am already at success for this, my issue is, I am unable to pass it it PRIOR_AUT_CAPTURE transaction... – Zaffar Saffee Jan 28 '13 at 17:44
  • you saw this http://stackoverflow.com/questions/14328475/auth-net-issue-on-capture? – Zaffar Saffee Jan 28 '13 at 18:15