2013-10-23 64 views
1

我是如此新的電子商務,我已經開發使用PHP基於https://github.com/smhack/Ticket門票系統,以及一切正常,payement工程(貝寶購物車)等。 。(我正在使用PayPal Sandbox)PHP Paypal IPN處理將不起作用

我已經在IPN模擬器上測試了我的IPN,但它在我的項目中工作,但我無法弄清爲什麼IPN上的PHP代碼沒有考慮(Insert on數據庫,發送確認郵件)

HTML:

<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
    <input type="hidden" name="cmd" value="_xclick"> 
    <input type="hidden" name="business" value="[email protected]"> 
    <input type="hidden" name="currency_code" value="USD"> 
    <input type="hidden" name="item_name" value="<?php echo $classTitle;?>"> 
    <input type="hidden" name="item_number" value="Class"> 
    <input type="hidden" name="custom" value="<?php echo $id;?>"> 
    <input type="hidden" name="amount" value="<?php echo $price;?>"> 
    <input type="hidden" name="return" value="http://www.croisentoi.com/ticket/"> 
    <input type="hidden" name="notify_url" value="http://www.croisentoi.com/ticket/ipn.php"> 
    <input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> 
</form> 

ipn.php:

<?php 

    include('ipnlistener.php'); 
    include("config.php"); 

    if($sqlTicketservertype = 'mysql'){ 
    $db = new PDO('mysql:host='.$sqlTicketserver.';dbname='.$sqlTicketdbname, $sqlTicketusername, $sqlTicketpassword); 
    } 
    // tell PHP to log errors to ipn_errors.log in this directory 
    ini_set('log_errors', true); 
    ini_set('error_log', dirname(__FILE__).'/ipn_errors.log'); 

    $listener = new IpnListener(); 
    $listener->use_sandbox = true; 

    try { 
     $verified = $listener->processIpn(); 
    } catch (Exception $e) { 
     // fatal error trying to process IPN. 
    error_log($e->getMessage()); 
     exit(0); 
    } 

    if ($verified) { 
     // IPN response was "VERIFIED" 
     $email = $_POST['payer_email']; 
     $txn = $_POST['txn_id']; 
     $firstName = $_POST['first_name']; 
     $lastName = $_POST['last_name']; 
     $paymentDate = $_POST['payment_date']; 

     $query = $db->PREPARE("INSERT INTO tickets (email, txn, firstName, lastName, paymentDate ) VALUES ('$email', '$txn', '$firstName', '$lastName', '$paymentDate' )"); 
     $query->execute(); 

     mail('[email protected]', 'Valid IPN', $listener->getTextReport()); 
    } else { 
     // IPN response was "INVALID" 
     mail('[email protected]mail.com', 'Invalid IPN', $listener->getTextReport()); 
    } 

?> 

我認爲,當payement正常的IPN應該被執行。那麼爲什麼這個文件不被讀取?你有什麼想法嗎?

編輯:該項目託管在http://croisentoi.com/ticket

謝謝

回答

1

你在貝寶沙盒網站打開IPN通知過,爲了它從你的PHP腳本。來吧,與IPN的網址打開它(你可以在以後使用覆蓋在你的PHP腳本「返回」屬性此網址):

https://www.sandbox.paypal.com/cgi-bin/customerprofileweb?cmd=_profile-ipn-notify

+0

謝謝普拉拉德。我現在啓用了它們,並在'Url of notification'字段中設置了IPN php文件的url。我繼續付款,當付款完成後,我重定向到我的網站,但沒有執行任何操作,數據庫仍然是空的。 我忘了什麼嗎?謝謝。 – Copernic

+1

@Mehdi - 在通知URL中,檢查POST變量。當貝寶向你發送IPN通知時,它會添加很多post數據,例如order_name,order_qty,custom等等。我現在不記得確切的名字,但其中有很多。遍歷$ _POST php數組來獲取它們。 –

+0

我可以看到你已經在你的代碼中處理了一些變量,但檢查它們的確切名稱。對於時間而言,請註釋掉這段代碼,並在響應中寫下所有的$ _POST變量來檢查paypal發送的內容。 –