doucheng1884 2011-12-23 14:47
浏览 275
已采纳

如何从发票ID中获取PayPal交易ID

I work with an e-commerce website that uses a PayPal checkout component written in PHP. For accounting purposes I want to retrieve some additional information using the PayPal PHP SOAP API.

I found out how to access the transaction using the transaction id and the GetTransactionDetails object:

// snip - include PayPal libraries and set up APIProfile object -

$trans_details =& PayPal::getType('GetTransactionDetailsRequestType');
$tran_id = $_GET['transactionID'];
$trans_details->setTransactionId($tran_id, 'iso-8859-1');
$caller =& PayPal::getCallerServices($profile);
$response = $caller->GetTransactionDetails($trans_details);
$paymentTransDetails = $response->getPaymentTransactionDetails();

// snip - work with transaction details -

However, I need to enhance this so that I can find out the 12-character string transaction id first by using the invoice id which I have available in a local MySQL database (which is also referenced in the transaction on the PayPal website).

I guess that I have to use Transaction Search for that but I don't know how to do this with the PHP SOAP API. How can I retrieve the transaction id for an invoice id?

  • 写回答

2条回答 默认 最新

  • dscrb00804 2012-01-03 13:09
    关注

    I dived into the API documentation and managed to find it out.

    // snip - include PayPal libraries and set up APIProfile object (variable: profile) - 
    
    $trans_search =& PayPal::getType('TransactionSearchRequestType');
    
    // 01/12/201 as an example date, we always need a start date for the API
    $start_date_str = '01/12/2011'; 
    $start_time = strtotime($start_date_str);
    $iso_start = date('Y-m-d\T00:00:00\Z', $start_time);
    $trans_search->setStartDate($iso_start, 'iso-8859-1');
    
    $invoice_ID = '10942456';  // here we insert the invoice ID we know
    $trans_search->setInvoiceID($invoice_ID);
    
    $caller =& PayPal::getCallerServices($profile);
    
    $response = $caller->TransactionSearch($trans_search); // execute search
    
    $ptsr = $response->getPaymentTransactions();
    $nrecs = sizeof($ptsr);
    $ack = $response->getAck();
    
    if( ($ack != ACK_SUCCESS) 
        && ($ack != ACK_SUCCESS_WITH_WARNING) ) 
        exit; // jump out on error
    
    if($nrecs == 1){ // check whether we found only one transaction (as expected)
        $paymentTransaction = $ptsr[0];
        // we found our transaction ID
        $transID = $paymentTransaction->getTransactionID();  
    }else{
        // invoice ID not unique?! :-(
        exit('Found multiple transactions: '. print_r($ptsr, true)); // jump out        
    }
    
    // snip - work with transaction ID - 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。