2013-08-21 50 views
1

我最近試圖通過magentos SOAPv2適配器連接到一個magento網上商店。
Sharpdevelop確實生成了一些獲取WSDL的c#wrappers。
我可以登錄和查詢訂單,但是當涉及到付款方式時,我想知道爲什麼沒有辦法獲得交易ID。 這裏是我的嘗試:Magento:通過soap獲取交易ID

salesOrderEntity ent = ms.salesOrderInfo(mlogin,"<my_order_id>"); 

salesOrderEntity類包含一個salesOrderPaymentEntity它應該包含一個屬性last_trans_id,但事實並非如此。
有沒有人有想法從付款信息中獲取交易ID?我甚至沒有在sharpdevelop生成的代理代碼中找到對last_trans_id的引用。

在此先感謝您的任何建議。 -chris-

回答

1

過了一段時間後,我再次拿起這個問題,並找到了解決方案在我的情況。
salesOrderEntity包含salesOrderStatusHistoryEntity對象的列表。
而那些包含一個名爲「註釋」字段凡在我的情況下,交易ID可以以文本方式通過發現像

交易ID:「800736757864 ...」

幫我。

+0

+1感謝您的指針。絕對荒謬的是,我們必須從銷售訂單歷史記錄中的評論中挖掘訂單的交易ID。 – McNab

0

克里斯的OP已經回答了這個問題,但只是爲此增加一些額外的價值Q &這是我工作的代碼。

作爲一些背景,我使用Transaction ID的原因是因爲它們被Paypal使用。我正在編寫一個cron作業,將Paypal API訂單從過去的24小時中提取出來,然後我們通過SOAP將所有訂單從過去24小時的SOAP中提取出來,獲取交易ID並將它們與Paypal列表進行匹配。這是爲了確保沒有不在Magento上的Paypal訂單,偶爾我們會得到IPN失敗,從而阻止Magento報價轉換爲訂單,並且客戶通過Paypal收費,但是沒有產品發送給他們,因爲訂單從未創建。如果發生不匹配,則會向客戶服務發送電子郵件警報。

$startDate = gmdate('Y-m-d H:i:s', strtotime('-1 day', time())); 

$complex_params =array(
    array('key'=>'created_at','value'=>array('key' =>'from','value' => $startDate)) 
); 

$result = $client_v2->salesOrderList($session_id, array('complex_filter' => $complex_params)); 


// We've got all the orders, now we need to run through them and get the transaction id from the order info 

// We create an array just to hold the transaction Ids 
$ikoTransactionIds = array(); 

foreach ($result as $invoice) { 

    $invoiceInfo = $client_v2->salesOrderInfo($session_id, $invoice->increment_id); 

    $history = $invoiceInfo->status_history; 

    $comments = $history[0]->comment; 

    // Only the Paypal based records have transaction Ids in the comments, orders placed via credit card do not. In these cases $comments are null 
    if ($comments) { 

     // Check if the text 'Transaction ID:' exists at all 
     if ((strpos($comments, "Transaction ID:")) !== FALSE) { 

      list($before, $transactionId) = explode('Transaction ID: ', $comments); 

      // Remove the trailing period 
      $transactionId = rtrim($transactionId ,"."); 

      // Remove the quotes 
      $transactionId = str_replace('"', '', $transactionId); 

      // We add the id to our array of ids for this Magento install 
      $ikoTransactionIds[] = $transactionId; 

     } 

    } 

}