簡體   English   中英

貝寶IPN PHP腳本

[英]paypal IPN php script

我只是意識到我的php中的paypal ipn處理程序不再起作用(並且我什么也沒改變),我使用了paypal提供的示例php腳本。

我試圖通過進行幾次測試來隔離問題,這時我可以說問題不是“ VERIFIED”或“ INVALID”,而是來自以下幾行:

[...]

fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
        // check the payment_status is Completed

[...]

任何人都知道貝寶是否更改了某些內容或為什么它不起作用?

謝謝'

ps:如果我將代碼放在所有的貝寶測試之前(在“ if(!$ fp)”行之前),就可以正常工作

這是我的代碼,我評論“數據庫進程”在哪里起作用,在哪里不起作用。

<?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value)
{
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$payment_status = $_POST['payment_status'];


// DATABASE PROCESS WORKS (BEFORE THE PAYPAL TESTS)



if (!$fp)
{
    // HTTP ERROR
}
else
   {

// DATABASE PROCESS WORKS

    fputs ($fp, $header . $req);
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment


// DATABASE PROCESS NOT WORKING

        }
        else if (strcmp ($res, "INVALID") == 0)
        {
            // log for manual investigation

// DATABASE PROCESS NOT WORKING
        }
    }
fclose ($fp);
}

?>

嘗試在x.xom https://www.x.com/instant-payment-notification-4上使用更新的腳本

它使用CURL而不是fsock

如果未針對套接字正確配置服務器或未配置openSSL模塊,則會發生此錯誤。

要么

您可以嘗試以下使用file_get_contents而不是$ fp代碼的代碼示例

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// for live mode
$url="https://www.paypal.com/cgi-bin/webscr";
// for developement mode
$url="https://www.sandbox.paypal.com/cgi-bin/webscr";

// instead of use of fopen you can use
$res=file_get_contents($url"?".$req);
// compare response
if (strcmp (trim($res), "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp (trim($res), "INVALID") == 0) {
// log for manual investigation
}

?>

如果file_get_contents無法正常工作,則可以使用CURL獲取響應...

讓我知道是否有任何疑問?

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM