-1

So I am currently trying to create a small web store and am using the paypal IPN + Sandbox. Currently my Paypal IPN Script doesn't seem to be working. The payment goes through (Money is transferred) but, nothing in my paypal_ipn script is done (Logs to a text file and adds a row to database).

here is my current paypal ipn file:

<?php
include("../functions.php");
include("../config.php");
// PHP 4.1

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

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
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$address = $_POST['custom_ip'];

    if (!$fp) {
        // HTTP ERROR
        log("[HTTP_ERROR]" . PHP_EOL . var_dump($_POST) . PHP_EOL . "[/HTTP_ERROR]", "payment/success.txt");
    } else {

        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
                log("[PAYMENT]" . PHP_EOL . var_dump($_POST) . PHP_EOL . "[/PAYMENT]", "payment/success.txt");

                mysql_query("INSERT INTO `purchases` (*) VALUES('$item_name', '$item_number', '$payment_amount', '$address', '$payer_email')");

            }
            else if (strcmp ($res, "INVALID") == 0) {
                // log for manual investigation
                log("[FAILED PAYMENT]" . PHP_EOL . var_dump($_POST) . PHP_EOL . "[/FAILED PAYMENT]", "payment/errors.txt");
            }
        }
        fclose ($fp);
    }
?>

Here is my form:

    <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="duncan-facilitator@mymcstatus.net">
        <input type="hidden" name="currency_code" value="USD">
        <input type="hidden" name="item_name" value="<?php print($product['title']); ?>">
        <input type="hidden" name="amount" value="<?php print($product['price']); ?>">
        <input type="hidden" name="return" value="http://website.com/shop/payment/?success">
        <input type="hidden" name="notify_url" value="http://website.com/shop/payment/paypal_ipn.php">
        <input type="hidden" name="custom_ip" value="<?php print($_SERVER['REMOTE_ADDR']); ?>"/>
        <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
        <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

I don't see anything wrong with this, but I am new to this so anything could be..

Thanks for any help.

4

1 回答 1

0

原来这是因为我的代码中有错误:

我声明的函数“log”是一个已经使用过的系统函数,所以我正在解析的参数导致错误。我更改了我的函数名称,一切正常:)

于 2013-08-23T11:12:44.637 回答