使用贝宝结账将用户添加到sql数据库


Using paypal checkout ot add a user to sql database

我正在尝试创建一个php文件,该文件将由贝宝结账调用,并将人员的电子邮件和密码添加到sql数据库中,以便他们可以登录。

我在网上找到了一个文件,但我让我的按钮把客户发给了它。但我一定做错了什么。

如有任何帮助,我们将不胜感激。

    <?php
// 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";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0'r'n";
$header .= "Content-Type: application/x-www-form-urlencoded'r'n";
$header .= "Content-Length: " . strlen($req) . "'r'n'r'n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$password = crypt($_POST['os0']);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check 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
    $table = "checkout";
    include("checkout-config.php");
 // Connect to Mysql Database
mysql_connect("$dbhost","$dblogin","$dbpass");
mysql_select_db($dbname) or die("Unable to select database");
mysql_query("INSERT INTO $table
(email, password) VALUES ('$_GET[payer_email]', '$password')");
echo "Paid";
//Header( "Location: http://www.rollestonelectric.com/paid.php" );
}
else if (strcmp ($res, "INVALID") == 0) {
echo "Unpaid";
//Header( "Location: http://www.rollestonelectric.com/unpaid.php" );
// log for manual investigation
}
}
fclose ($fp);
}

您找到的文件是IPN侦听器文件。IPN:即时支付通知

即时支付通知(IPN)是一种消息服务,用于通知与PayPal交易相关的事件。您可以使用IPN消息实现后台和管理功能的自动化,例如完成订单、跟踪客户、提供状态和其他交易相关信息。

是的,你们走在正确的轨道上。要在签出后将详细信息插入sql数据库,您需要使用IPN。

Steps:

  • 打开Paypal商户账户中的IPN
  • 您需要指定IPN返回URL,例如:www.yourdomain.com/testlistener.php,其中testlistener.php是您在帐户中在线找到的php文件
  • 用户点击PayPal按钮启动结账流程;您的web应用程序进行API调用;您的后台系统进行API调用;或者PayPal观察事件
  • PayPal HTTP向您的侦听器发布一条IPN消息,通知您此事件。侦听器返回一个空的HTTP200响应
  • 您的侦听器HTTP将完整的、未更改的消息张贴回PayPal。注意:此消息必须包含与PayPal的原始IPN相同的字段,顺序相同,所有字段的前面都是cmd=_notify-validate。此外,此消息必须使用与原始消息相同的编码
  • PayPal会发回一个单词——"已验证"(如果消息与原件匹配)或"无效"(如果信息与原件不匹配)

有关更多帮助,请参阅此链接。