1

after place order in magento and get order ID how can i add transaction ID to order ? is it possible with API ? i get transaction id from bank server and want to add it to order and complete order status.

4

If want to add Transaction id to order need by load order General process: In magento basis ,if need flow

Step1: Load by order id

$_order=Mage::getModel('sales/order')->load($orderId);

Step2: add Transaction to order and

  $payment = $_order->getPayment();
    $payment = $order->getPayment();
$payment->setTransactionId($yoursetTransactionId)
            ->setCurrencyCode($order->getBaseCurrencyCode())
            ->setPreparedMessage($youcomment)
            ->setParentTransactionId($yoursetTransactionId)
            ->setShouldCloseParentTransaction(true)
            ->setIsTransactionClosed(0)
            ->registerCaptureNotification($BaseGrandtotal);
        $order->save();

Step3: this only create invoice and but for order complete you need create shipment of order.

http://www.magentocommerce.com/api/soap/sales/salesOrderShipment/sales_order_shipment.create.html

Using api then

Step1: create api.xml which is creating custom api

it code is

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <addtransactionid_api translate="title" module="addtransactionid">
                <title>Myapi</title>
                <acl>addtransactionid/api</acl>
                <model>addtransactionid/api</model>
                <methods>                    
                        <addtransaction translate="title" module="addtransactionid">
                            <title>ADD Transaction</title>
                            <acl>addtransactionid/addtransaction</acl>
                        </addtransaction>
                </methods>
            </addtransactionid_api>
        </resources>
        <acl>
            <resources>
                <addtransactionid translate="title" module="addtransactionid">
                    <title>Addtransactionid</title>
                    <sort_order>2000</sort_order>                    
                    <addtransaction translate="title" module="addtransactionid">
                        <title>ADD Transaction</title>
                    </addtransaction>
                </addtransactionid>
            </resources>
        </acl>
    </api>
</config>

Step2: define an model class which set transaction id to order

<?php
    class Amit_Addtransactionid_Model_Api extends Mage_Api_Model_Resource_Abstract
    {        
            public function addTransaction($orderId=null,$TransactionId=null){

                $_order=Mage::getModel('sales/order')->load($orderId);
                if($_order->getId()){
                    $payment = $_order->getPayment();
                $payment->setTransactionId($TransactionId)
                    ->setCurrencyCode()
                    ->setPreparedMessage($message)
                    ->setParentTransactionId($parentTransactionId)
                    ->setShouldCloseParentTransaction(true)
                    ->setIsTransactionClosed(0)
                    ->registerCaptureNotification();
                $_order->save();
                }
            } 
    }

Step3:

This step only create order invoice and  set payment id  to order.
But for  complete order then  you need also create order shipment using below api

http://www.magentocommerce.com/api/soap/sales/salesOrderShipment/sales_order_shipment.create.html

[Edit:FullModule]

Step1: create config.xml for module at app/code/local/Amit/Addtransactionid/etc and it code is

<?xml version="1.0"?>
<config>
  <modules>
    <Amit_Addtransactionid>
      <version>1.0.0</version>
    </Amit_Addtransactionid>
  </modules>
  <global>
    <helpers>
      <addtransactionid>
        <class>Amit_Addtransactionid_Helper</class>
      </addtransactionid>
    </helpers>
    <models>
      <addtransactionid>
        <class>Amit_Addtransactionid_Model</class>
        <resourceModel>addtransactionid_mysql4</resourceModel>
      </addtransactionid>
    </models>
  </global>
</config> 

Step2: create api configuration by create api.xml at app/code/local/Amit/Addtransactionid/etc and it code is

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <addtransactionid_api translate="title" module="addtransactionid">
                <title>Myapi</title>
                <acl>addtransactionid/api</acl>
                <model>addtransactionid/api</model>
                <methods>                    
                        <addtransaction translate="title" module="addtransactionid">
                            <title>ADD Transaction</title>
                            <acl>addtransactionid/addtransaction</acl>
                        </addtransaction>
                </methods>
            </addtransactionid_api>
        </resources>
        <acl>
            <resources>
                <addtransactionid translate="title" module="addtransactionid">
                    <title>Addtransactionid</title>
                    <sort_order>2000</sort_order>                    
                    <addtransaction translate="title" module="addtransactionid">
                        <title>ADD Transaction</title>
                    </addtransaction>
                </addtransactionid>
            </resources>
        </acl>
    </api>
</config>

Step3: create model Api.php file app/code/local/Amit/Addtransactionid/Model add trancation id to order:

code is

<?php
    class Amit_Addtransactionid_Model_Api extends Mage_Api_Model_Resource_Abstract
    {        
            public function addTransaction($orderId=null,$TransactionId=null){

                $_order=Mage::getModel('sales/order')->load($orderId);
                if($_order->getId()){
                    $payment = $_order->getPayment();
                $payment->setTransactionId($TransactionId)
                    ->setCurrencyCode()
                    ->setPreparedMessage($message)
                    ->setParentTransactionId($parentTransactionId)
                    ->setShouldCloseParentTransaction(true)
                    ->setIsTransactionClosed(0)
                    ->registerCaptureNotification();

                $_order->save();
                }
            } 
    }

Step4: create module file at app/etc/modules/Amit_Addtransactionid.xml

code:

<?xml version="1.0"?>
<config>
  <modules>
    <Amit_Addtransactionid>
      <active>true</active>
      <codePool>local</codePool>            
            <depends>
                <Mage_Api />
            </depends>
      <version>1.0.0</version>
    </Amit_Addtransactionid>
  </modules>
</config>

SOAP

$client = new SoapClient('http://yourhost/api/soap/?wsdl');
$session = $client->login('******', '******');
$date = $client->call($session, 'addtransactionid_api.addTransaction',orderid,traid);

XML-RPC

$client = new Zend_XmlRpc_Client('http://yourhost/api/xmlrpc/');
$session = $client->call('login', array('******', '******'));
$date=$client->call('call', array($session, 'addtransactionid_api.addTransaction',orderid,traid));
|improve this answer|||||
  • is there any magento api to do setep 1 & 2 ? – mahdi Sep 21 '14 at 16:00
  • 1
    i have not find it.So i am creating custom module which is set transcation id to orde – Amit Bera Sep 21 '14 at 17:25
  • it`s return fail in this part $_order=Mage::getModel('sales/order')->load($orderId); – mahdi Sep 22 '14 at 7:01
  • with this change problem sloved $order = Mage::getModel('sales/order')->loadByIncrementId('100000234'); thanks – mahdi Oct 15 '14 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.