Oleg_46
Новичок
Столкнулся с такой проблемой.
PayPal в песочнице и на боевом сервере возвращает "invalid".
Может кто чего посоветует
Форма.
Код
PayPal в песочнице и на боевом сервере возвращает "invalid".
Может кто чего посоветует
Форма.
PHP:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" value="UTF-8" name="charset">
<input type="hidden" value="_xclick" name="cmd">
<input type="hidden" value="2" name="rm">
<input type="hidden" value="[email protected]" name="business">
<input type="hidden" value="Oplata zakaza" name="item_name">
<input type="hidden" value="23025" name="item_number">
<input type="hidden" value="1" name="amount">
<input type="hidden" value="http://host.ru/user/basket/payment_success.php" name="return">
<input type="hidden" value="1" name="no_shipping">
<input type="hidden" value="RUB" name="currency_code">
<input type="hidden" value="http://host/user/basket/paypalcheck.php" name="notify_url">
<input type="submit" value="Оплатить через PayPal">
</form>
Код
PHP:
header('HTTP/1.1 200 OK');
//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";
}
debug_output($req, 'a+', SB_BASEDIR.'/debug.txt');
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//successful connection
if ($fp) {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res = trim($res); //NEW & IMPORTANT
if (strcmp($res, 'VERIFIED') == 0) {
//insert order into database
debug_output("Прошли проверку", 'a+', SB_BASEDIR.'/debug.txt');
}
else if (strcmp ($res, 'INVALID') == 0) {
debug_output("Не прошли проверку", 'a+', SB_BASEDIR.'/debug.txt');
}
}
fclose($fp);