我想知道是否可以在收到PayPal捐款时执行SQL查询。
流程如下:
就像在一些MMORPG中一样。你支付得分。
答案 0 :(得分:1)
是的,您可以设置PayPal即时付款通知(IPN) 这将允许您为收到的每笔付款运行脚本。 See Here。
以下是PayPal API,以下是PayPal C# Samples.
要在项目中安装C#SDK作为依赖项,请运行以下nuget命令。
nuget install PayPalRestApiSDK
答案 1 :(得分:1)
您可以构建一个表单来在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
找到更多信息