我很难在Paypal NVP和REST API之间做出决定。
REST API似乎更新更好,但我无法找到在交易发生后获取客户详细信息的方法。
基本上我想为定期付款设置结算方案,然后通过API获取客户详细信息,这样他们就不必通过我的网站输入。
Paypal Express结账似乎是我应该在这里使用的。
NVP API提供GetExpressCheckoutDetails方法来获取这些详细信息。
我没有找到类似REST API的东西。
由于REST API似乎也要通过Express Checkout,因此应该有一个解决方案。
如何在激活结算协议后获取客户详细信息?
答案 0 :(得分:0)
我在一个月前遇到了同样的问题,在阅读了文档后,目前无法通过REST API实现这一目标。如果有办法,则没有记录。
我发现这样做的唯一方法是使用NVP API和可能的SOAP API。 NVP API将为您提供所需的大部分字段,但如果您为事务存储了自定义字段,它只会为您提供3个自定义字段,但不会提供所有字段(很奇怪)。
我没有尝试过NVP方法GetExpressCheckoutDetails,但我使用了GetTransactionDetails方法。它会回复您的交易详情。它返回一个必须解析的文本块。每个字段都是URL编码的,并用&符号分隔。这是PHP中的一个例子:
<?php
// Get cURL resource
$ch = curl_init();
// Set url
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.paypal.com/nvp/');
// Set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
// Set options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/x-www-form-urlencoded; charset=utf-8",
]
);
// Create body
$body = [
"VERSION" => "204.0",
"METHOD" => "GetTransactionDetails",
"USER" => "nvp_api_username_here",
"PWD" => "nvp_api_password_here",
"SIGNATURE" => "nvp_api_signature_here",
"TRANSACTIONID" => "some_paypal_transaction_id_here",
];
$body = http_build_query($body);
// Set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// Send the request and save response to $resp
$resp = curl_exec($ch);
if(!$resp) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
} else {
parse_str($resp, $formated_response);
print_r($formated_response);
}
// Close request to clear up some resources
curl_close($ch);
这是格式化的返回正文:
Array
(
[RECEIVERBUSINESS] => paypal_account_owner_email_address_here@test.com
[RECEIVEREMAIL] => paypal_account_owner_email_address_here@test.com
[RECEIVERID] => 1111111111111
[EMAIL] => buyers_email_address_here@test.com
[PAYERID] => 55551
[PAYERSTATUS] => verified
[COUNTRYCODE] => US
[BUSINESS] => buyers_business_name_here
[ADDRESSOWNER] => PayPal
[ADDRESSSTATUS] => None
[SALESTAX] => 0.00
[SHIPAMOUNT] => 0.00
[SHIPHANDLEAMOUNT] => 0.00
[SHIPDISCOUNT] => 0.00
[INSURANCEAMOUNT] => 0.00
[GIFTRECEIPT] => 0
[TIMESTAMP] => 2016-08-02T17:04:58Z
[CORRELATIONID] => 55552
[ACK] => Success
[VERSION] => 204.0
[BUILD] => 22386173
[FIRSTNAME] => Foo
[LASTNAME] => Bar
[TRANSACTIONID] => 55553
[TRANSACTIONTYPE] => webaccept
[PAYMENTTYPE] => instant
[ORDERTIME] => 2016-08-01T20:49:28Z
[AMT] => 1.00
[TAXAMT] => 0.00
[CURRENCYCODE] => USD
[PAYMENTSTATUS] => Completed
[PENDINGREASON] => None
[REASONCODE] => None
[SHIPPINGMETHOD] => Default
[PROTECTIONELIGIBILITY] => Ineligible
[PROTECTIONELIGIBILITYTYPE] => None
[L_QTY0] => 0
[L_TAXAMT0] => 0.00
[L_SHIPPINGAMT0] => 0.00
[L_HANDLINGAMT0] => 0.00
[L_CURRENCYCODE0] => USD
[L_OPTIONSNAME0] => first_custom_field_label_here
[L_OPTIONSVALUE0] => first_custom_field_value_here
[L_OPTIONSNAME1] => second_custom_field_label_here
[L_OPTIONSVALUE1] => second_custom_field_value_here
[L_OPTIONS1NAME0] => second_custom_field_label_here_duplicate
[L_OPTIONS1VALUE0] => second_custom_field_value_here_duplicate
[L_TAXABLE0] => false
[L_TAXRATE0] => 0.0
[L_AMT0] => 1.00
[INSURANCEOPTIONSELECTED] => 0
[SHIPPINGOPTIONISDEFAULT] => 0
)
警告:强>
仅当您在PayPal交易中存储自定义字段时才适用。
PayPal的NVP API仅为交易返回最多3个自定义字段,即使您最多可以在事务中存储7个自定义字段。即使比较疯狂,它返回的自定义字段之一也是第二个自定义字段的副本。至少在我尝试从事务中检索自定义字段时就是这种情况。