【发布时间】:2013-12-30 23:37:42
【问题描述】:
我想知道是否可以在收到 PayPal 捐赠时执行 SQL 查询。
流程如下:
- 用户向 PayPal 帐户捐款。
- SQL 插入/更新将积分奖励给捐赠者。
就像在某些 MMORPG 中一样。您付费获得积分。
【问题讨论】:
我想知道是否可以在收到 PayPal 捐赠时执行 SQL 查询。
流程如下:
就像在某些 MMORPG 中一样。您付费获得积分。
【问题讨论】:
您可以构建一个表单以在 PayPal 上设置付款,类似这样...
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="your@email-registered-with-paypal.com">
<input type="hidden" name="notify_url" value="http://yourdomain.com/notifypage.aspx">
<input type="hidden" name="invoice" value="{username or similar}">
<input type="hidden" name="item_name" value="Donation">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="9.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
</form>
付款成功后,从 PayPal 服务器调用 notify_url 并回传信息,包括您在表单中指定的发票编号。
在 Page_Load() 方法中的 notifypage.aspx 中,您需要验证帖子是否来自 PayPal,然后读取发布的表单变量并相应地更新您的数据库,使用发票值匹配付款给您的用户数据库。有点像..
protected void Page_Load(object sender, EventArgs e)
{
//Post back to either sandbox or live
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
if (strResponse == "VERIFIED")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
var userName = Request["invoice"];
//update database
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}
更多信息请访问https://www.paypal.com/uk/cgi-bin/webscr?cmd=p/acc/ipn-info-outside
【讨论】:
是的,您可以设置 PayPal 即时付款通知 (IPN)。
这将允许您为收到的每笔付款运行一个脚本。 See Here。
这里是PayPal API 和这里是PayPal C# Samples.
要将 C# SDK 作为依赖项安装到您的项目中,请运行以下 nuget 命令。
nuget install PayPalRestApiSDK
【讨论】: