2014-11-23 4 views
0

PayPal IPN 메시지를 수신하는 PHP 페이지가 있습니다.PayPal IPN messges

나는 바이어 전자 메일 주소와 총 금액을 얻고 데이터베이스 테이블에 추가하기 위해 두 번째 PHP 수신기를 갖고 싶습니다.

둘 이상의 수신기를 설정할 수 있습니까?

이 내 현재 청취자입니다 ...

<?php 

    status_header(200); 

    $debug_log = "ipn_handle_debug.log"; // Debug log file name 

    class paypal_ipn_handler { 

    var $last_error;     // holds the last error encountered 
    var $ipn_log;     // bool: log IPN results to text file? 
    var $ipn_log_file;    // filename of the IPN log 
    var $ipn_response;    // holds the IPN response from paypal 
    var $ipn_data = array();   // array contains the POST values for IPN 
    var $fields = array();   // array holds the fields to submit to paypal 
    var $sandbox_mode = false; 

    function paypal_ipn_handler() 
    { 
     $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; 
     $this->last_error = ''; 
     $this->ipn_log_file = WP_CART_PATH.'ipn_handle_debug.log'; 
     $this->ipn_response = ''; 
    } 

    function validate_and_dispatch_product() 
    { 
     // Check Product Name , Price , Currency , Receivers email , 
     global $products,$currency,$paypal_email; 
     $txn_id = $this->ipn_data['txn_id']; 
     $transaction_type = $this->ipn_data['txn_type']; 
     $payment_status = $this->ipn_data['payment_status']; 
     $transaction_subject = $this->ipn_data['transaction_subject']; 
     $custom_value_str = $this->ipn_data['custom']; 
     //$this->debug_log('custom values from paypal: '.$custom_value_str,true); 
     $first_name = $this->ipn_data['first_name']; 
     $last_name = $this->ipn_data['last_name']; 
     $buyer_email = $this->ipn_data['payer_email']; 
     $street_address = $this->ipn_data['address_street']; 
     $city = $this->ipn_data['address_city']; 
     $state = $this->ipn_data['address_state']; 
     $zip = $this->ipn_data['address_zip']; 
     $country = $this->ipn_data['address_country']; 
     $phone = $this->ipn_data['contact_phone']; 
     $address = $street_address.", ".$city.", ".$state.", ".$zip.", ".$country; 
     $custom_values = wp_cart_get_custom_var_array($custom_value_str); 
     $this->debug_log('Payment Status: '.$payment_status,true); 
     if($payment_status == "Completed" || $payment_status == "Processed"){ 
      //We will process this notification 
     } 
     else{ 
      $this->debug_log('This is not a payment complete notification. This IPN will not be processed.',true); 
      return true; 
     } 
     if ($transaction_type == "cart") 
     { 
      $this->debug_log('Transaction Type: Shopping Cart',true); 
      // Cart Items 
      $num_cart_items = $this->ipn_data['num_cart_items']; 
      $this->debug_log('Number of Cart Items: '.$num_cart_items,true); 

      $i = 1; 
      $cart_items = array(); 
      while($i < $num_cart_items+1) 
      { 
       $item_number = $this->ipn_data['item_number' . $i]; 
       $item_name = $this->ipn_data['item_name' . $i]; 
       $quantity = $this->ipn_data['quantity' . $i]; 
       $mc_gross = $this->ipn_data['mc_gross_' . $i]; 
       $mc_currency = $this->ipn_data['mc_currency']; 

       $current_item = array(
        'item_number' => $item_number, 
        'item_name' => $item_name, 
        'quantity' => $quantity, 
        'mc_gross' => $mc_gross, 
        'mc_currency' => $mc_currency, 
       ); 

       array_push($cart_items, $current_item); 
       $i++; 
      } 
     } 
     else 
     { 
      $cart_items = array(); 
      $this->debug_log('Transaction Type: Buy Now',true); 
      $item_number = $this->ipn_data['item_number']; 
      $item_name = $this->ipn_data['item_name']; 
      $quantity = $this->ipn_data['quantity']; 
      $mc_gross = $this->ipn_data['mc_gross']; 
      $mc_currency = $this->ipn_data['mc_currency']; 

      $current_item = array(
       'item_number' => $item_number, 
       'item_name' => $item_name, 
       'quantity' => $quantity, 
       'mc_gross' => $mc_gross, 
       'mc_currency' => $mc_currency, 
      ); 
      array_push($cart_items, $current_item); 
     } 

     $product_id_array = Array(); 
     $product_name_array = Array(); 
     $product_price_array = Array(); 
     $attachments_array = Array(); 
     $download_link_array = Array(); 

     $payment_currency = get_option('cart_payment_currency'); 

     foreach ($cart_items as $current_cart_item) 
     { 
      $cart_item_data_num = $current_cart_item['item_number']; 
      $cart_item_data_name = $current_cart_item['item_name']; 
      $cart_item_data_quantity = $current_cart_item['quantity']; 
      $cart_item_data_total = $current_cart_item['mc_gross']; 
      $cart_item_data_currency = $current_cart_item['mc_currency']; 

      $this->debug_log('Item Number: '.$cart_item_data_num,true); 
      $this->debug_log('Item Name: '.$cart_item_data_name,true); 
      $this->debug_log('Item Quantity: '.$cart_item_data_quantity,true); 
      $this->debug_log('Item Total: '.$cart_item_data_total,true); 
      $this->debug_log('Item Currency: '.$cart_item_data_currency,true); 

      // Compare the values 
      if ($payment_currency != $cart_item_data_currency) 
      { 
      $this->debug_log('Invalid Product Currency : '.$payment_currency,false); 
      return false; 
      } 
     }   

     /*** Send notification email ***/ 
     //TODO 
     $post_id = $custom_values['wp_cart_id']; 
     $ip_address = $custom_values['ip']; 
     $applied_coupon_code = $custom_values['coupon_code']; 
     $currency_symbol = get_option('cart_currency_symbol'); 
     $this->debug_log('custom values',true); 
     $this->debug_log_array($custom_values,true); 
     //$this->debug_log('post id: '.$post_id,true); 
     if($post_id) 
     {   
      //security check 
      if(!get_post_status($post_id)) 
      { 
       $this->debug_log('Order ID '.$post_id.' does not exist in the database. This is not a Simple PayPal 

     Shopping Cart order', false); 
       return; 
      } 

      if (get_option('wp_shopping_cart_strict_email_check') != '') 
      { 
       $seller_paypal_email = get_option('cart_paypal_email'); 
       if ($seller_paypal_email != $this->ipn_data['receiver_email']){ 
        $error_msg .= 'Invalid Seller Paypal Email Address : '.$this->ipn_data['receiver_email']; 
        $this->debug_log($error_msg, false); 
        return; 
       } 
       else{ 
        $this->debug_log('Seller Paypal Email Address is Valid: '.$this->ipn_data['receiver_email'],true); 
       } 
      } 

      $transaction_id = get_post_meta($post_id, 'wpsc_txn_id', true); 
      if(!empty($transaction_id)) 
      { 
       if($transaction_id == $txn_id) //this transaction has been already processed once 
       { 
        $this->debug_log('This transaction has been already processed once. Transaction ID: '.$transaction_id, false); 
        return; 
       } 
      } 

      //End of security check 

      $updated_wpsc_order = array(
       'ID'    => $post_id, 
       'post_status' => 'publish', 
       'post_type'  => 'wpsc_cart_orders', 
      ); 
      wp_update_post($updated_wpsc_order); 

      update_post_meta($post_id, 'wpsc_first_name', $first_name); 
      update_post_meta($post_id, 'wpsc_last_name', $last_name); 
      update_post_meta($post_id, 'wpsc_email_address', $buyer_email); 
      update_post_meta($post_id, 'wpsc_txn_id', $txn_id); 
      $mc_gross = $this->ipn_data['mc_gross']; 
      update_post_meta($post_id, 'wpsc_total_amount', $mc_gross); 
      update_post_meta($post_id, 'wpsc_ipaddress', $ip_address); 
      update_post_meta($post_id, 'wpsc_address', $address); 
      update_post_meta($post_id, 'wpspsc_phone', $phone); 
      $status = "Paid"; 
      update_post_meta($post_id, 'wpsc_order_status', $status); 
      update_post_meta($post_id, 'wpsc_applied_coupon', $applied_coupon_code); 
      $cart_items = get_post_meta($post_id, 'wpsc_cart_items', true); 
      $product_details = ""; 
      $item_counter = 1; 
      $shipping = ""; 
      if($cart_items){ 
       foreach ($cart_items as $item){ 
        if($item_counter != 1){ 
         $product_details .= "\n"; 
        } 
        $item_total = $item['price'] * $item['quantity']; 
        $product_details .= $item['name']." x ".$item['quantity']." - ". 

$currency_symbol.wpspsc_number_format_price($item_total)."\n"; 
        if($item['file_url']){ 
         $file_url = base64_decode($item['file_url']); 
         $product_details .= "Download Link: ".$file_url."\n"; 
        } 
        if(!empty($item['shipping'])){ 
         $shipping += $item['shipping'] * $item['quantity']; 
        } 
        $item_counter++; 
       } 
      } 
      if(empty($shipping)){ 
       $shipping = "0.00"; 
     } 
      else{ 
       $baseShipping = get_option('cart_base_shipping_cost'); 
      $shipping = $shipping + $baseShipping; 
       $shipping = wpspsc_number_format_price($shipping); 
      } 
      update_post_meta($post_id, 'wpsc_shipping_amount', $shipping); 
      $args = array(); 
      $args['product_details'] = $product_details; 
      update_post_meta($post_id, 'wpspsc_items_ordered', $product_details); 
      $from_email = get_option('wpspc_buyer_from_email'); 
      $subject = get_option('wpspc_buyer_email_subj'); 
      $body = get_option('wpspc_buyer_email_body'); 
      $args['email_body'] = $body; 
      $body = wpspc_apply_dynamic_tags_on_email_body($this->ipn_data, $args); 
      $headers = 'From: '.$from_email . "\r\n"; 
      if(!empty($buyer_email)){ 
       $args['payer_email'] = $buyer_email; 
       if(get_option('wpspc_send_buyer_email')) 
      { 
        wp_mail($buyer_email, $subject, $body, $headers); 
        $this->debug_log('Product Email successfully sent to '.$buyer_email,true); 
        update_post_meta($post_id, 'wpsc_buyer_email_sent', 'Email sent to: '.$buyer_email);        
       } 
      } 
      $notify_email = get_option('wpspc_notify_email_address'); 
      $seller_email_subject = get_option('wpspc_seller_email_subj'); 
      $seller_email_body = get_option('wpspc_seller_email_body'); 
      $args['email_body'] = $seller_email_body; 
      $args['order_id'] = $post_id; 
      $seller_email_body = wpspc_apply_dynamic_tags_on_email_body($this->ipn_data, $args); 
      if(!empty($notify_email)){ 
       if(get_option('wpspc_send_seller_email')) 
      { 
        wp_mail($notify_email, $seller_email_subject, $seller_email_body, $headers); 
        $this->debug_log('Notify Email successfully sent to '.$notify_email,true); 
       } 
      } 
     } 

     /**** Affiliate plugin integratin ****/ 
     $this->debug_log('Updating Affiliate Database Table with Sales Data if Using the WP Affiliate Platform 

Plugin.',true);  
     if (function_exists('wp_aff_platform_install')) 
     { 
      $this->debug_log('WP Affiliate Platform is installed, registering sale...',true); 
      $referrer = $custom_values['ap_id']; 
      $sale_amount = $this->ipn_data['mc_gross']; 
      if (!empty($referrer)) 
      { 
       do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" => 

$sale_amount, "txn_id" => $txn_id, "buyer_email" => $buyer_email)); 

       $message = 'The sale has been registered in the WP Affiliates Platform Database for referrer: '. 

$referrer.' for sale amount: '.$sale_amount; 
       $this->debug_log($message,true);     
      } 
      else 
      { 
       $this->debug_log('No Referrer Found. This is not an affiliate sale',true); 
      }   
     } 
     else 
     { 
      $this->debug_log('Not Using the WP Affiliate Platform Plugin.',true); 
     } 

     do_action('wpspc_paypal_ipn_processed',$this->ipn_data); 

     return true; 
    } 

    function validate_ipn() 
    { 
     // parse the paypal URL 
     $url_parsed=parse_url($this->paypal_url); 

     // generate the post string from the _POST vars aswell as load the _POST vars into an arry 
     $post_string = ''; 
     foreach ($_POST as $field=>$value) { 
     $this->ipn_data["$field"] = $value; 
     $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; 
     } 

     $this->post_string = $post_string; 
     $this->debug_log('Post string : '. $this->post_string,true); 

     $post_string.="cmd=_notify-validate"; // append ipn command 

     // open the connection to paypal 
     if($this->sandbox_mode){//connect to PayPal sandbox 
      $uri = 'ssl://'.$url_parsed['host']; 
      $port = '443';    
      $fp = fsockopen($uri,$port,$err_num,$err_str,30); 
     } 
     else{//connect to live PayPal site using standard approach 
     $fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30); 
     } 

     if(!$fp) 
     { 
     // could not open the connection. If loggin is on, the error message 
     // will be in the log. 
     $this->debug_log('Connection to '.$url_parsed['host']." failed. fsockopen error no. $errnum: $errstr",false); 
     return false; 

     } 
     else 
     { 
     // Post the data back to paypal 
     fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n"); 
     fputs($fp, "Host: $url_parsed[host]\r\n"); 
     fputs($fp, "User-Agent: Simple PayPal Shopping Cart Plugin\r\n"); 
     fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
     fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); 
     fputs($fp, "Connection: close\r\n\r\n"); 
     fputs($fp, $post_string . "\r\n\r\n"); 

     // loop through the response from the server and append to variable 
     while(!feof($fp)) { 
      $this->ipn_response .= fgets($fp, 1024); 
     } 

     fclose($fp); // close connection 

     $this->debug_log('Connection to '.$url_parsed['host'].' successfuly completed.',true); 
     } 

     //if (eregi("VERIFIED",$this->ipn_response)) 
     if (strpos($this->ipn_response, "VERIFIED") !== false)// Valid IPN transaction. 
     { 
     $this->debug_log('IPN successfully verified.',true); 
     return true; 
     } 
     else 
     { 
     // Invalid IPN transaction. Check the log for details. 
     $this->debug_log('IPN validation failed.',false); 
     return false; 
     } 
    } 

    function log_ipn_results($success) 
    { 
     if (!$this->ipn_log) return; // is logging turned off? 

     // Timestamp 
     $text = '['.date('m/d/Y g:i A').'] - '; 

     // Success or failure being logged? 
     if ($success) $text .= "SUCCESS!\n"; 
     else $text .= 'FAIL: '.$this->last_error."\n"; 

     // Log the POST variables 
     $text .= "IPN POST Vars from Paypal:\n"; 
     foreach ($this->ipn_data as $key=>$value) { 
     $text .= "$key=$value, "; 
     } 

     // Log the response from the paypal server 
     $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response; 

     // Write to log 
     $fp=fopen($this->ipn_log_file,'a'); 
     fwrite($fp, $text . "\n\n"); 

     fclose($fp); // close file 
    } 

    function debug_log($message,$success,$end=false) 
    { 

     if (!$this->ipn_log) return; // is logging turned off? 

     // Timestamp 
     $text = '['.date('m/d/Y g:i A').'] - '.(($success)?'SUCCESS :':'FAILURE :').$message. "\n"; 

     if ($end) { 
     $text .= "\n------------------------------------------------------------------\n\n"; 
     } 

     // Write to log 
     $fp=fopen($this->ipn_log_file,'a'); 
     fwrite($fp, $text); 
     fclose($fp); // close file 
    } 

    function debug_log_array($array_to_write,$success,$end=false) 
    { 
     if (!$this->ipn_log) return; // is logging turned off? 
     $text = '['.date('m/d/Y g:i A').'] - '.(($success)?'SUCCESS :':'FAILURE :'). "\n"; 
     ob_start(); 
     print_r($array_to_write); 
     $var = ob_get_contents(); 
     ob_end_clean();  
     $text .= $var; 

     if ($end) 
     { 
      $text .= "\n------------------------------------------------------------------\n\n"; 
     } 
     // Write to log 
     $fp=fopen($this->ipn_log_file,'a'); 
     fwrite($fp, $text); 
     fclose($fp); // close filee 
    } 
} 

// Start of IPN handling (script execution) 
function wpc_handle_paypal_ipn() 
{ 
    $debug_log = "ipn_handle_debug.log"; // Debug log file name  
    $ipn_handler_instance = new paypal_ipn_handler(); 

    $debug_enabled = false; 
    $debug = get_option('wp_shopping_cart_enable_debug'); 
    if ($debug){ 
     $debug_enabled = true; 
    } 

    if ($debug_enabled) 
    { 
     echo 'Debug is enabled. Check the '.$debug_log.' file for debug output.'; 
     $ipn_handler_instance->ipn_log = true; 
     //$ipn_handler_instance->ipn_log_file = realpath(dirname(__FILE__)).'/'.$debug_log; 
    } 
    $sandbox = get_option('wp_shopping_cart_enable_sandbox'); 
    if ($sandbox) // Enable sandbox testing 
    { 
     $ipn_handler_instance->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 
     $ipn_handler_instance->sandbox_mode = true; 
    } 
    $ipn_handler_instance->debug_log('Paypal Class Initiated by '.$_SERVER['REMOTE_ADDR'],true); 
    // Validate the IPN 
    if ($ipn_handler_instance->validate_ipn()) 
    { 
     $ipn_handler_instance->debug_log('Creating product Information to send.',true); 
     if(!$ipn_handler_instance->validate_and_dispatch_product()) 
     { 
      $ipn_handler_instance->debug_log('IPN product validation failed.',false); 
     } 
    } 
    $ipn_handler_instance->debug_log('Paypal class finished.',true,true); 
} 

그래서 내 업데이트 된 코드는 다음과 같이 그리고 내가 읽을 필요가 단지 것 'IPN-listener.php'에 조금 보일 것입니다 포스트 데이터? ...

<?php 

    status_header(200); 

    $debug_log = "ipn_handle_debug.log"; // Debug log file name 


     class paypal_ipn_handler { 
    var $last_error;     // holds the last error encountered 
    var $ipn_log;     // bool: log IPN results to text file? 
    var $ipn_log_file;    // filename of the IPN log 
    var $ipn_response;    // holds the IPN response from paypal 
    var $ipn_data = array();   // array contains the POST values for IPN 
    var $fields = array();   // array holds the fields to submit to paypal 
    var $sandbox_mode = false; 

    function paypal_ipn_handler() 
    { 
     $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; 
     $this->last_error = ''; 
     $this->ipn_log_file = WP_CART_PATH.'ipn_handle_debug.log'; 
     $this->ipn_response = ''; 
} 
function curl_request($url, $req, $ssl) 
{ 
    $curl_result=$curl_err=''; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: ".strlen($req))); 
    curl_setopt($ch, CURLOPT_HEADER , 0); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 90); 

    $curl_result = curl_exec($ch); 
    $curl_err = curl_error($ch); 
    curl_close($ch); 

    return $curl_result;  
} 

    } ////// class paypal_ipn_handler ends here 






////////// A snippet of my coding //////////////// 

    function send_email() 
    {  

     /*** Send notification email -Sends an email and forwards the request on to the IPN listener ***/ 

        wp_mail($buyer_email, $subject, $body, $headers); 
        $this->debug_log('Product Email successfully sent to '.$buyer_email,true); 
        update_post_meta($post_id, 'wpsc_buyer_email_sent', 'Email sent to: '.$buyer_email); 

       curl_request('http://www.domain.com/paypal/ipn/ipn-listener.php', $req, $ssl); 

     return true; 
    } 
?> 

**** UPDATE 코딩 **** 그래서 이제이 잘 여전히 보는가, 이메일을 보내는 동안 내 두 번째 리스너에 전달 처음 IPN 리스너를 업데이트 한?

이제 내 두 번째 IPN 독자는 구매자 이메일과 비용을 읽고 싶습니다. $ buyeremail = $ _GET [ 'payer_email']처럼 간단하게 처리 할 수 ​​있습니까? 당신은 단지 하나의 IPN 스크립트 내에서 처리 할 수 ​​있지만 귀하의 질문에 대답하기 위해 뭔가 같은 소리

<?php 

status_header(200); 

$debug_log = "ipn_handle_debug.log"; // Debug log file name 

class paypal_ipn_handler { 

var $last_error;     // holds the last error encountered 
var $ipn_log;     // bool: log IPN results to text file? 
var $ipn_log_file;    // filename of the IPN log 
var $ipn_response;    // holds the IPN response from paypal 
var $ipn_data = array();   // array contains the POST values for IPN 
var $fields = array();   // array holds the fields to submit to paypal 
var $sandbox_mode = false; 

function paypal_ipn_handler() 
{ 
    $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; 
    $this->last_error = ''; 
    $this->ipn_log_file = WP_CART_PATH.'ipn_handle_debug.log'; 
    $this->ipn_response = ''; 
} 

// Curl function to send POST data to a server. 
function curl_request($url, $req, $ssl) 
{ 
$curl_result=$curl_err=''; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $req); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: ".strlen($req))); 
curl_setopt($ch, CURLOPT_HEADER , 0); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl); 
curl_setopt($ch, CURLOPT_TIMEOUT, 90); 

$curl_result = curl_exec($ch); 
$curl_err = curl_error($ch); 
curl_close($ch); 

return $curl_result;  
} 

/Set config fields 
$sandbox = isset($_POST['test_ipn']) ? true : false; 
$ppHost = $sandbox ? 'www.sandbox.paypal.com' : 'www.paypal.com'; 
$ssl = $_SERVER['SERVER_PORT'] == '443' ? true : false; 

// Loop through POST data and generate NVP string to return back to PayPal (or forward on to secondary listeners) 
$req = ''; 
foreach ($_POST as $key => $value) 
$req .= "&$key.=".urlencode(stripslashes($value)); 



////////// A snippet of my coding //////////////// 

    function send_email() 
    {  

     /*** Send notification email -Sends an email and forwards the request on to the IPN listener ***/ 

        wp_mail($buyer_email, $subject, $body, $headers); 
        $this->debug_log('Product Email successfully sent to '.$buyer_email,true); 
        update_post_meta($post_id, 'wpsc_buyer_email_sent', 'Email sent to: '.$buyer_email); 

       curl_request('http://www.domain.com/paypal/ipn/second-listener.php', $req, $ssl); 

     return true; 
    } 
?> 

답변

0

daisy-chain multiple IPN's scripts together 당신이 할 수있는 것입니다.

기본적으로 자습서에 제공된 curl_request() 함수를 IPN 클래스에 추가하고 적절하게 조정해야합니다.

function curl_request($url, $req, $ssl) 
{ 
    $curl_result=$curl_err=''; 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: ".strlen($req))); 
    curl_setopt($ch, CURLOPT_HEADER , 0); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 90); 

    $curl_result = curl_exec($ch); 
    $curl_err = curl_error($ch); 
    curl_close($ch); 

    return $curl_result;  
} 

당신은 당신이 알고있는 다른 기능 중 하나가 항상 다음과 같이 실행 내에서 호출 것 :

curl_request('http://www.domain.com/paypal/ipn/ipn-listener.php', $req, $ssl); 
+0

으로 시도 할 수 있습니다 예, 그것은 내가 필요로 할 것 같은 소리가 나고, 고마워. 위의 질문에 리스너 코드를 추가했습니다. 여기서 abouts는 데이지 체인 스크립트를 추가 할 수 있습니까? – user826436

+0

내가 링크 된 자습서를 읽었습니까? 꽤 명확한 샘플이 있습니다. –

+0

예, 읽었습니다. 조금 혼란 스럽습니다. 웹 사이트에 표시된대로 설정하고 데이터베이스에 특정 데이터를 삽입 한 다음 다른 수신기로 전달하는 코드를 추가해야합니까? – user826436

0

예는 이 방법

$raw_post_data = file_get_contents('php://input'); 
     $raw_post_array = explode('&', $raw_post_data); 
     $myPost   = array(); 
     foreach ($raw_post_array as $keyval) 
     { 
      $keyval    = explode('=', $keyval); 
      if (count($keyval) == 2) 
       $myPost[$keyval[0]] = urldecode($keyval[1]); 
     } 
     // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' 
     $req = 'cmd=_notify-validate'; 
     if (function_exists('get_magic_quotes_gpc')) 
     { 
      $get_magic_quotes_exists = true; 
     } 
     foreach ($myPost as $key => $value) 
     { 
      if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) 
      { 
       $value = urlencode(stripslashes($value)); 
      } 
      else 
      { 
       $value = urlencode($value); 
      } 
      $req .= "&$key=$value"; 
     } 
     $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); 
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $req); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); 
     if (!($res = curl_exec($ch))) 
     { 
      curl_close($ch); 
      common::activity_log("CURL EXECUTION", "CURL IS NOT EXECUTED"); 
     } 
     curl_close($ch); 
     // inspect IPN validation result and act accordingly 
     if (strcmp($res, "VERIFIED") == 0) 
     { 
      // The IPN is verified, process it 
      $this->load->model('order_model', 'order'); 
      $orderInfo = $this->order->get_record_for_field('order_key', $myPost['invoice']); 
      // The IPN is verified, process it 
      if (!empty($orderInfo)) 
      { 
       $this->order->order_id = $orderInfo['0']->order_id; 
       $this->order->ipn_log = json_encode($myPost); 
       $this->order->save(); 
       # Log the email in database too. 
       $this->load->model('Email_Log_Model', 'emails'); 
       $this->emails->to_email  = '[email protected]'; 
       $this->emails->from_email = '[email protected]'; 
       $this->emails->subject  = 'paypal valid invalid'; 
       $this->emails->body   = json_encode($myPost); 
       $this->emails->status  = 0; 
       $this->emails->save(); 
      } 
      else 
      { 
       common::activity_log("INVALID ORDER KEY", "order key is not valid"); 
      } 
     } 
     else if (strcmp($res, "INVALID") == 0) 
     { 
      // IPN invalid, log for manual investigation 
      common::activity_log("PAYPAL RESPONSE", "paypal didnt send this info"); 
     }