Get customer details after transaction

£可爱£侵袭症+ 提交于 2019-12-24 06:07:02

问题


I'm struggling to decide between Paypal NVP and REST APIs.

The REST API seems to be newer and better but I can't find a way to get customer details after a transaction occured.

Basically I want to set up a billing plan for recurring payments and then get customer details via API so they do not have to enter them through my website.

Paypal Express checkout seems to be what I should use here.

The NVP API offers a GetExpressCheckoutDetails method to get these details.

I didn't find something similar for the REST API.

Since the REST API seems to go through Express Checkout as well there should be a solution.

How can I get customer details after activating the billing agreement?


回答1:


I ran into this same problem a month ago and after reading the docs, there's currently no way to accomplish this with the REST API. If there is a way, it's not documented.

The only way I found to do this is with the NVP API and possibly the SOAP API. The NVP API will give you back most of the fields that you want but if you've stored custom fields for a transaction, it will only give you 3 of the custom fields but not all of them (weird).

I haven't tried the NVP method GetExpressCheckoutDetails but I have used the GetTransactionDetails method. It will give you back the transaction details. It returns a text block that you must parse. Each field is URL encoded and separated by an ampersand. Here's an example in 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);

Here's the formatted return body:

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
)

Warning:

This only applies if you're storing custom fields in a PayPal transaction.

PayPal's NVP API only returns up to 3 custom fields for a transaction, even though you can store up to 7 custom fields in a transaction. Even crazier, one of the custom fields it returns is a duplicate of the second custom field. At least that's the case when I try to retrieve a custom fields from a transaction.



来源:https://stackoverflow.com/questions/37974187/get-customer-details-after-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!