Get information from PayPal after a transaction

前端 未结 4 1383
故里飘歌
故里飘歌 2020-12-07 15:58

I want to create a simple transaction on my Web Site where after the person\'s transaction completes, I want paypal to redirect the user to go to a place on my site and I w

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 16:28

    $tx=$_REQUEST['tx'];
    
    $paypal_url='https://www.paypal.com/cgi-bin/webscr?cmd=_notify-synch&tx='.$tx.'&at=token here';
    
    $curl = curl_init($paypal_url);
    
    $data = array(
    
    "cmd" => "_notify-synch",
    
    "tx" => $tx,
    
    "at" => "token here"
    
    
    );                                                                    
    
    $data_string = json_encode($data); 
    
    curl_setopt ($curl, CURLOPT_HEADER, 0);
    
    curl_setopt ($curl, CURLOPT_POST, 1);
    
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $data_string);
    
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
    
    curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
    
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
    
    $headers = array (
    
    'Content-Type: application/x-www-form-urlencoded',
    
    'Host: www.paypal.com',
    
    'Connection: close'
    
    );
    
    curl_setopt ($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    
    curl_setopt ($curl, CURLOPT_HTTPHEADER, $headers);
    
    $response = curl_exec($curl);
    
    $lines = explode("\n", $response);
    
    $keyarray = array();
    
    if (strcmp ($lines[0], "SUCCESS") == 0) {
    
    for ($i=1; $i

提交回复
热议问题