加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何从发票ID获取PayPal交易ID

发布时间:2020-12-13 17:17:20 所属栏目:PHP教程 来源:网络整理
导读:我使用的是一个使用 PHP编写的PayPal结账组件的电子商务网站.出于会计目的,我想使用PayPal PHP SOAP API检索一些其他信息. 我发现了如何使用事务id和GetTransactionDetails对象访问事务: // snip - include PayPal libraries and set up APIProfile object
我使用的是一个使用 PHP编写的PayPal结账组件的电子商务网站.出于会计目的,我想使用PayPal PHP SOAP API检索一些其他信息.

我发现了如何使用事务id和GetTransactionDetails对象访问事务:

// 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 -

但是,我需要增强这一点,以便我可以首先使用我在本地MySQL数据库中提供的发票ID(也在PayPal网站上的交易中引用)找出12个字符的字符串事务ID.

我想我必须使用Transaction Search,但我不知道如何使用PHP SOAP API.如何检索发票ID的交易ID?

解决方法

我深入研究了API文档并设法找到它.

// 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-dT00:00:00Z',$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 -

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读