我无法将PayPal的IPN集成到我的系统中。在IPN Simulator中,我的侦听器工作正常,但是当我测试沙箱时,PayPal不会访问该文件以通知我对请求的更改。
结帐工作正常,但PayPal未调用我的listener.php。
我什至在文件中故意留有错误,如果执行该文件,则会接收日志。即便如此,什么也没发生,所以当某些请求发生更改时,PayPal似乎没有发送信息
listener.php:
<?php
include "../../includes/functions/functions.php";
$raw_post_data = file_get_contents('php://input');
file_put_contents("Data.txt", $raw_post_data);
$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]);
}
$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";
}
$ch = curl_init('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
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'));
if (!($res = curl_exec($ch))) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);
if (strcmp($res, "VERIFIED") == 0) {
file_put_contents("Data.txt", "OK");
}
}
?>
表格
<form id="paypal<?= $pacoteData->pacotes_id ?>" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<!--Tipo do botão-->
<input type="hidden" name="cmd" value="_xclick" />
<!--Vendedor e URL de retorno, cancelamento e notificação-->
<input type="hidden" name="business" value="jorge.frillocchi-facilitator@gmail.com" />
<input type="hidden" name="return" value="<?= $config->PROTOCOL ?><?= $config->URL ?>?payment=success&pedido=<?= $codigo_pedido ?>" />
<input type="hidden" name="cancel" value="<?= $config->PROTOCOL ?><?= $config->URL ?>" />
<input type="hidden" name="notify_url" value="<?= $config->PROTOCOL ?><?= $config->URL ?>>modules/pagamento/notificacao.php" />
<!--Internacionalização e localização da página de pagamento-->
<input type="hidden" name="charset" value="utf-8" />
<input type="hidden" name="lc" value="BR" />
<input type="hidden" name="country_code" value="BR" />
<input type="hidden" name="currency_code" value="BRL" />
<!--Informações sobre o produto e seu valor-->
<input type="hidden" name="amount" value="<?= number_format($pacoteData->pacotes_valor, 2, ".", ",") ?>" />
<input type="hidden" name="item_name" value="<?= $pacoteData->pacotes_nome . " " . $pacoteData->pacotes_duracao ?> Dias" />
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="invoice" value="<?= $codigo_pedido ?>" />
<!--Botão para submissão do formulário-->
<button type="submit" class="mdc-button mdc-card__action mdc-card__action--button">
<i class="material-icons mdc-button__icon" aria-hidden="true">payment</i>
<span class="mdc-button__label">Assinar com PayPal</span>
</button>
</form>