我创建了一个“立即付款”paypal按钮,用户可以点击它以预订艺术家。他们需要填写很多细节(艺术家姓名,活动日期,活动地点等),然后最后一个选项是付费。
以下是普通的贝宝形式。我还使用了我的数据库中的一些变量(艺术家的姓名和姓氏,预算,身份证等)
的index.php
$url='https://www.sandbox.paypal.com/cgi-bin/webscr'; ?>
$email='my-email@gmail.com';
<form enctype="multipart/form-data" action='<?php echo $url; ?>' method='post'>
<input type='hidden' name='business' value='<?php echo $email; ?>'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='item_name' value='<?php echo $name . " " . $surname;?>'>
<input type='hidden' name='item_number' value='<?php echo $artist_id;?>'>
<input type='hidden' name='amount' value='<?php echo $price;?>'>
<input type='hidden' name='buyer_name' value='<?php echo $b_name; ?>'>
<input type='hidden' name='buyer_phone' value='<?php echo $phone; ?>'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='EUR'>
<input type='hidden' name='handling' value='0'>
<input type='hidden' name='cancel_return' value='http://mywebsite.com/fail.php'>
<input type='hidden' name='return' value='http://mywebsite.com/success.php'>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
当用户点击按钮时,它会转到paypal网站,在那里显示产品详细信息等。如果付款成功,它会将用户发送到success.php脚本,在那里它应该获取数据(cmd,item_name,item_number ,index等来自index.php
中的表格success.php
<?php
$artist_id = $_POST['item_number'];
$buyer_name = $_POST['buyer_name'];
$buyer_phone = $_POST['buyer_phone'];
$item_transaction = $_POST['tx'];
$item_price = $_POST['amt'];
echo "Name: $item_no , Surname: $buyer_name, Price: $buyer_phone, ID: $item_transaction $item_price<br/>";
//retrieve artist's details
$getArtist = mysql_query("SELECT * FROM artist WHERE artist_id = '$item_no'");
$details = mysql_fetch_array($getArtist);
$name = $details['artist_name']; $surname = $details['artist_surname']; $price = $details['artist_budget']; $artist_id = $details['artist_id'];
//$result = mysql_query("INSERT INTO booked_event (pid, buyer_name, buyer_phone, saledate, transactionid) VALUES('$singer_no', '$buyer_name', '$buyer_phone','$event_date','$item_transaction')");
//if($result){
// echo "<p style='text-align: center;'><img src='images/success.png'><br/><br/>";
// echo "We will contact you as soon as possible for further details! Please check your email<br/>";
// echo "<a href='book.php'><b>Go Back</b></a></p><br/>";
//}else{
// echo "Payment Error";
//}
echo "Name: $name , Surname: $surname, Price: $price, ID: $artist_id";
}
else
{
echo "Payment Failed";
}
?>
问题是我没有收到任何详细信息,以便在有人预订艺术家时将它们存储在数据库中。 我试图回应细节并且它什么都没打印(参见echo“名称:$ item_no,姓:$ buyer_name,价格:$ buyer_phone,ID:$ item_transaction $ item_price)。
有人知道为什么吗?我做错了吗?
答案 0 :(得分:0)
用户完成paypal结账后,paypal不会回复您所在表格中的所有数据。
看看PayPal IPN,这是付款完成后它将把一大堆交易数据发布到您选择的网站上的页面。它包含一个“自定义”变量,您可以将自己的数据发回。