我正在尝试这样做,但是我有些困惑。
red
还是blue
,他们最喜欢的颜色是7
。我该怎么做?我很困惑,因为当客户单击“提交”时,它将直接转到PayPal结帐。我知道表单的action
指向PayPal,但是所有有关使用PayPal编写结帐代码的教程都可以做到这一点。
然后,在成功付款后,如何获得客户喜欢的颜色和编号(因为我不再在index.php
上继续付款。我在listener.php
上听到交易成功。我没有想存储客户喜欢的号码或颜色。我只想存储他们成功购买的商品。
index.php
<?php
function validate_input($favColor, $favNum) {
if (($favColor == "red" || $favColor == "blue") && $favNum == 7) {
return true;
}
return false;
}
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" class="form-validate">
<div class="field-item">
What is your favourite color? <input name="fav-color" type="text" required><br>
What is your favourite number? <input name="fav-num" type="text" required><br>
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="MYHOSTBUTTONVALUE">
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/buy-logo-medium.png" style="margin-top: 10px;" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
</div>
</form>
listener.php
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
header('Location: index.php');
exit();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
$response = curl_exec($ch);
curl_close($ch);
if ($response == "VERIFIED") {
$favColor = CUSTOMERS RESPONSE; // How do I get this?
$favNum = CUSTOMERS RESPONSE; // How do I get this?
$msg = "Customer likes $favColor and $favNum";
$fileName = "purchases.txt";
file_put_contents($fileName, $msg);
}
?>