Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带standart按钮的PayPal IPN表示结果无效_Php_Paypal_Paypal Ipn_Paypal Sandbox - Fatal编程技术网

Php 带standart按钮的PayPal IPN表示结果无效

Php 带standart按钮的PayPal IPN表示结果无效,php,paypal,paypal-ipn,paypal-sandbox,Php,Paypal,Paypal Ipn,Paypal Sandbox,我不知道为什么我得到了无效的结果,而IPN模拟器一切正常 IPNSampleCode.php 我的波顿: 当我创建我的按钮时,我将IPN代码url添加到finish字段中。 也许我不必使用按钮,那么我应该使用什么呢?谢谢您的帮助。看起来不错,但在查找已验证的: 。。。 如果strcmp trim$res,则已验证==0{ 使用HTTP 1.1时,有效负载可能包含回车符和换行符 <?php // STEP 1: Read POST data // reading posted

我不知道为什么我得到了无效的结果,而IPN模拟器一切正常

IPNSampleCode.php

我的波顿:

当我创建我的按钮时,我将IPN代码url添加到finish字段中。
也许我不必使用按钮,那么我应该使用什么呢?谢谢您的帮助。

看起来不错,但在查找已验证的:

。。。 如果strcmp trim$res,则已验证==0{

使用HTTP 1.1时,有效负载可能包含回车符和换行符

    <?php

// STEP 1: Read POST data

// reading posted data from directly from $_POST causes serialization 
// issues with array data in POST
// reading raw POST data from input stream instead. 
$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 post from PayPal system and add 'cmd'
$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";
}


// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); // change to [...]sandbox.paypal[...] when using sandbox to test
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'));

// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path 
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);


// STEP 3: Inspect IPN validation result and act accordingly
echo $res;
if (strcmp ($res, "VERIFIED") == 0) {
    // check whether 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

    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    if ($_POST['mc_gross'] != NULL)
        $payment_amount = $_POST['mc_gross'];
    else
        $payment_amount = $_POST['mc_gross1'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
    $custom = $_POST['custom'];

    // Insert your actions here


    if($payment_status == "Completed" && $receiver_email == "naujas@mt2014.com"){

            $db = new mysqli('localhost', 'myDetails', 'myDetails', 'myDetails');
            if($db->connect_errno > 0){
                die('Unable to connect to database [' . $db->connect_error . ']');
            }
            //


            $time = strtotime(date("Y-m-d"));
            $final = date("Y-m-d", strtotime("+12 month", $time));
            $db->query("UPDATE users SET active_till='2012-05-05' WHERE email='naujas@mt2014.com';");
        $db->close();
        }
} else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    echo "err";
}
?>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QKH6ANQ9ZGXUU">
<table>
<tr><td><input type="hidden" name="on0" value="Period:">Period:</td></tr><tr><td><select name="os0">
    <option value="1 month">1 month €50.00 EUR</option>
    <option value="3 months">3 months €130.00 EUR</option>
    <option value="6 months">6 months €200.00 EUR</option>
    <option value="1 year">1 year €350.00 EUR</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="EUR">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>