如何从发票 ID 获取 PayPal 交易 ID
我与一个电子商务网站合作,该网站使用用 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 -
但是,我需要增强这一点,以便我可以首先使用本地可用的发票 ID 找到 12 个字符的字符串交易 ID MySQL 数据库(PayPal 网站上的交易中也引用了该数据库)。
我想我必须使用 交易搜索 ,但我不知道如何使用 PHP SOAP API 来做到这一点。如何检索发票 ID 的交易 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我深入研究了 API 文档并设法找到了答案。
I dived into the API documentation and managed to find it out.
使用 TransactionSearch API 按发票编号查找交易非常简单。您所需要做的就是将 API 调用中的 INVNUM 参数发送到 PayPal。
例如(基于 PayPal 的 TransactionSearch PHP 示例代码):
到这里一切都如常。示例的唯一更改如下:
此处,通过设置适当的 STARTDATE:
此处,通过添加一个简单的 if 语句来触发是否返回完整的 TransactionSearch API 结果,或仅返回 PayPal 交易 ID (bla.php ?视图=最小):
It's easy enough to use the TransactionSearch API to find a transaction by invoice number. All you need to do is send the INVNUM parameter along in the API call to PayPal.
For example (based on PayPal's TransactionSearch PHP sample code):
Up to here it's all as usual. The only changes to the sample are here:
Here, by setting a proper STARTDATE:
And here, by adding a simple if statement to trigger whether or not to return the full TransactionSearch API result, or only return the PayPal transaction ID (bla.php?view=minimal):