2016-09-18 3 views
0

私はE-Commerce Webサイトをサーバー上で稼動させています。私はPaypal IPN通知を使用して、顧客による支払いに関する通知を顧客に送信します。 私は現在、テストのためにPaypalサンドボックスを使用しています。paypal ipn notify_urlは正常に動作していますが、設定されている返信URLには何も表示されません。

私はpaypalデベロッパーアカウント=> make payment =>私は、ipnリクエストが送られてきたのに私のpaypalアカウントでメッセージを受け取りますが、データベースの注文テーブルにipnリクエストの値を取得しません。 この理由は何でしょうか?

以下のスクリーンショットのようにIPNの詳細を設定しました。 と 私のPaypal開発者アカウントのIPN履歴のスクリーンショットもあります。 誰でも私を助けて、私のデータベースの値が更新されない理由を教えてもらえますか?続き

は私のコードです:

クラス/ Paypal.php

<?php 
class PayPal { 


    private $_environment = 'sandbox'; 
    private $_url_production = 'https://www.paypal.com/cgi-bin/webscr'; 
    private $_url_sandbox = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 
    private $_url; 
    private $_cmd; 
    private $_products = array(); 
    private $_fields = array(); 
    private $_business = '[email protected]'; 
    private $_page_style = 'null'; 
    private $_return; 
    private $_cancel_payment; 
    private $_notify_url; 
    private $_currency_code = 'GBP'; 
    public $_tax_cart = 0; 
    public $_tax = 0; 
    public $_populate = array(); 
    private $_ipn_data = array(); 
    private $_log_file = null; 
    private $_ipn_result; 



    public function __construct($cmd = '_cart') { 

     $this->_url = $this->_environment == 'sandbox' ? 
         $this->_url_sandbox : 
         $this->_url_production; 

     $this->_cmd = $cmd; 

     $this->_return = SITE_URL."/?page=return"; 
     $this->_cancel_payment = SITE_URL."/?page=cancel"; 
     $this->_notify_url = SITE_URL."/?page=ipn"; 
     $this->_log_file = ROOT_PATH.DS."log".DS."ipn.log"; 

    } 


    public function addProduct($number, $name, $price = 0, $qty = 1) { 

     switch($this->_cmd) { 

      case '_cart': 
      $id = count($this->_products) + 1; 
      $this->_products[$id]['item_number_'.$id] = $number; 
      $this->_products[$id]['item_name_'.$id] = $name; 
      $this->_products[$id]['amount_'.$id] = $price; 
      $this->_products[$id]['quantity_'.$id] = $qty; 
      break; 
      case '_xclick': 
      if (empty($this->_products)) { 
       $this->_products[0]['item_number'] = $number; 
       $this->_products[0]['item_name'] = $name; 
       $this->_products[0]['amount'] = $price; 
       $this->_products[0]['quantity'] = $qty; 
      } 
      break; 
     } 
    } 

    private function addField($name = null, $value = null) { 
     if (!empty($name) && !empty($value)) { 
      $field = '<input type="hidden" name="'.$name.'" '; 
      $field .= 'value="'.$value.'" />'; 
      $this->_fields[] = $field; 
     } 
    } 

    private function standardFields() { 
     $this->addField('cmd', $this->_cmd); 
     $this->addField('business', $this->_business); 
     if ($this->_page_style != null) { 
      $this->addField('page_style', $this->_page_style); 
     } 
     $this->addField('return', $this->_return); 
     $this->addField('notify_url', $this->_notify_url); 
     $this->addField('cancel_payment', $this->_cancel_payment); 
     $this->addField('currency_code', $this->_currency_code); 
     $this->addField('rm', 2); 

     switch($this->_cmd) { 
      case '_cart': 
      if ($this->_tax_cart != 0) { 
       $this->addField('tax_cart', $this->_tax_cart); 
      } 
      $this->addField('upload', 1); 
      break; 
      case '_xclick': 
      if ($this->_tax != 0) { 
       $this->addField('tax', $this->_tax); 
      } 
      break; 
     } 
    } 

    private function prePopulate() { 
     if (!empty($this->_populate)) { 
      foreach($this->_populate as $key => $value) { 
       $this->addField($key, $value); 
      } 
     } 
    } 

    private function processFields() { 
     $this->standardFields(); 
     if (!empty($this->_products)) { 
      foreach($this->_products as $product) { 
       foreach($product as $key => $value) { 
        $this->addField($key, $value); 
       } 
      } 
     } 
     $this->prePopulate(); 
    } 

    private function getFields() { 
     $this->processFields(); 
     if (!empty($this->_fields)) { 
      return implode("", $this->_fields); 
     } 
    } 
    private function render() { 
     $out = '<form action="'.$this->_url.'" method="post" id="frm_paypal">'; 
     $out .= $this->getFields(); 
     $out .= '<input type="submit" value="Submit" />'; 
     $out .= '</form>'; 
     return $out; 
    } 

    public function run($transaction_id = null) { 
     if (!empty($transaction_id)) { 
      $this->addField('custom', $transaction_id); 
     } 
     return $this->render(); 
    } 

    private function validateIpn() { 

     $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); 
      if (!preg_match('/paypal\.com$/', $hostname)) { 
      return false; 
     } 
      $objForm = new Form(); 
     $this->_ipn_data = $objForm->getPostArray(); 

     if (
      !empty($this->_ipn_data) && 
      array_key_exists('receiver_email', $this->_ipn_data) && 
      strtolower($this->_ipn_data['receiver_email']) != 
      strtolower($this->_business) 
     ) { 
      return false; 
     } 

     return true;  
    } 
    private function getReturnParams() { 

     $out = array('cmd=_notify-validate'); 
     if (!empty($this->_ipn_data)) { 
      foreach($this->_ipn_data as $key => $value) { 
       $value = function_exists('get_magic_quotes_gpc') ? 
          urlencode(stripslashes($value)) : 
          urlencode($value); 
       $out[] = "{$key}={$value}"; 
      } 
     } 
     return implode("&", $out);  
    } 

    private function sendCurl() { 

     $response = $this->getReturnParams(); 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $this->_url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $response); 
     curl_setopt($ch, T_HEADER, 0); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      "Content-Type: application/x-www-form-urlencoded", 
      "Content-Length: " . strlen($response) 
     )); 
     curl_setopt($ch, CURLOPT_VERBOSE, 1); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 30); 

     $this->_ipn_result = curl_exec($ch); 
     curl_close($ch); 

    } 

    public function ipn() { 
     if ($this->validateIpn()) { 
      $this->sendCurl(); 
      if (strcmp($this->_ipn_result, "VERIFIED") == 0) { 
       $objOrder = new Order(); 

       if (!empty($this->_ipn_data)) { 

        $objOrder->approve(
         $this->_ipn_data, 
         $this->_ipn_result 
        );  
       } 
      }  
     } 
    } 
} 

MOD/paypal.php

<?php 
require_once('../inc/autoload.php'); 
$token2 = Session::getSession('token2'); 
$objForm = new Form(); 
$token1 = $objForm->getPost('token'); 

if ($token2 == Login::string2hash($token1)) { 

    // create order 
    $objOrder = new Order(); 
    if ($objOrder->createOrder()) { 

     // populate order details 
     $order = $objOrder->getOrder(); 
     $items = $objOrder->getOrderItems(); 


     if (!empty($order) && !empty($items)) { 

      $objBasket = new Basket(); 
      $objCatalogue = new Catalogue(); 
      $objPayPal = new PayPal(); 


      foreach($items as $item) { 
       $product = $objCatalogue->getProduct($item['product']); 
       $objPayPal->addProduct(
        $item['product'], 
        $product['name'], 
        $item['price'], 
        $item['qty'] 
       ); 
      } 


      $objPayPal->_tax_cart = $objBasket->_vat; 

      // populate client's details 
      $objUser = new User(); 
      $user = $objUser->getUser($order['client']); 

      if (!empty($user)) { 


       $objCountry = new Country(); 
       $country = $objCountry->getCountry($user['country']); 


       $objPayPal->_populate = array(
        'address1'  => $user['address_1'], 
        'address2'  => $user['address_2'], 
        'city'   => $user['town'], 
        'state'   => $user['county'], 
        'zip'   => $user['post_code'], 
        'country'  => $country['code'], 
        'email'   => $user['email'], 
        'first_name' => $user['first_name'], 
        'last_name'  => $user['last_name']     
       ); 


       // redirect client to PayPal 
       echo $objPayPal->run($order['id']); 



      } 

     } 

    } 

} 

IPN settings IPN Details

これで私を助けてください。

+0

あなたはそのページのメールにあるすべての情報を送ってください。 –

+0

私はpaypal ipnにすべてを送ってきました。返信url(ipnの履歴に表示されています)でipnリクエストを受け取ります。 –

答えて

0

IPNはあなたのリターンURLとは関係ありません。戻り値URLにIPNがトリガーされたときに実行すると予想されるコードを追加する場合は、予期した結果が得られません。

あなたのリターンURLにデータを取得するには、IPNと非常に似ていますが返品URLに送信されるようになっているPDTを使用する必要があります。 IPNはあなたの通知URLに行きます。あなたの戻りURLと一致しないはずです。

関連する問題