How to access 3rd party transaction information in Paypal

后端 未结 1 624
-上瘾入骨i
-上瘾入骨i 2021-01-07 08:11

I\'m trying to figure out how to access transaction information from a third party user (to include in a dashboard) from Paypal.

Ideally I need to be able to pull in

相关标签:
1条回答
  • 2021-01-07 08:47

    After struggling with this for sometime I found a simple, but crude implementation here - List of PayPal transactions.

    The original code didn't work - here's a corrected version

    <?php 
     $info = 'USER=[API_USERNAME]'
        .'&PWD=[API_PASSWORD]'
        .'&SIGNATURE=[API_SIGNATURE]'
        .'&METHOD=TransactionSearch'
        .'&TRANSACTIONCLASS=RECEIVED'
        .'&STARTDATE=2013-01-08T05:38:48Z'
        .'&ENDDATE=2013-07-14T05:38:48Z'
        .'&VERSION=94';
    
    $curl = curl_init('https://api-3t.paypal.com/nvp');
    curl_setopt($curl, CURLOPT_FAILONERROR, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
    curl_setopt($curl, CURLOPT_POSTFIELDS,  $info);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_POST, 1);
    
    $result = curl_exec($curl);
    
    # Bust the string up into an array by the ampersand (&)
     # You could also use parse_str(), but it would most likely limit out
     $result = explode("&", $result);
    
    # Loop through the new array and further bust up each element by the equal sign (=)
    # and then create a new array with the left side of the equal sign as the key and the       right side of the equal sign as the value
       foreach($result as $value){
    $value = explode("=", $value);
    $temp[$value[0]] = $value[1];
    }
    
    
    for($i=0; $i<(count($temp)/11)-1; $i++){
        $returned_array[$i] = array(
        "timestamp"         =>    urldecode($temp["L_TIMESTAMP".$i]),
        "timezone"          =>    urldecode($temp["L_TIMEZONE".$i]),
        "type"              =>    urldecode($temp["L_TYPE".$i]),
        "email"             =>    urldecode($temp["L_EMAIL".$i]),
        "name"              =>    urldecode($temp["L_NAME".$i]),
        "transaction_id"    =>   urldecode($temp["L_TRANSACTIONID".$i]),
        "status"            =>    urldecode($temp["L_STATUS".$i]),
        "amt"               =>    urldecode($temp["L_AMT".$i]),
        "currency_code"     =>    urldecode($temp["L_CURRENCYCODE".$i]),
        "fee_amount"        =>    urldecode($temp["L_FEEAMT".$i]),
        "net_amount"        =>    urldecode($temp["L_NETAMT".$i]));
    }
    
    var_dump($returned_array);
    

    This is obviously not production code, but it's good enough to work backwards from.

    0 讨论(0)
提交回复
热议问题