以HTML方式实现Paypal在线支付

 提交Paypal页面:

 <form target="_self" action="https://www.paypal.com/cgi-bin/webscr"  method="post" name="E_FORM">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_xclick">  <%--_xclick代表已做好购物车--%>
<input type="hidden" name="business" value="<%= business %>">  <%--付入帐户--%>
<input type="hidden" name="item_name" value="<%= item_name %>">  <%--名称/可以是订单号--%>
<input type="hidden" name="item_number" value="<%= item_number %>">  <%--可以记录其他信息,如用户ID等--%>
<input type="hidden" name="amount" value="<%= amount %>">  <%--金额--%>
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="quantity" value="1">  <%--数量--%>
<input type="hidden" name="currency_code" value="USD">  <%--币种--%>
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="rm" value="2">  <%--值为2时,支付完成返回值--%>
<input type="hidden" name="return" value="http://">  <%--返回页面--%>
</form>

更多提交变量可以参考Paypal官方网站:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables

接收Paypal返回值:

 Request.Form["payment_status"].ToString().Trim();  返回支付状态:Completed 代表支付成功。

Request.Form["item_name"].ToString().Trim();  就是提交时的 item_name

Request.Form["item_number"].ToString().Trim();  就是提交时的 item_number

Request.Form["business"].ToString().Trim();  就是付入帐户,正常情况提交时的 business

Request.Form["verify_sign"].ToString().Trim();  加密串

Request.Form["payment_gross"].ToString().Trim();  总支付金额

Request.Form["mc_currency"].ToString().Trim();  币种

更多接收变量可以参考Paypal官方网站:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables

或我的博客: http://blog.sina.com.cn/s/blog_5e06afe00100ehjx.html


下面是验证支付的真实性:

 private bool VerifyIPN()
{
    string strFormValues = Request.Form.ToString();
    string strNewValue;
    string strResponse;
    string serverURL = "https://www.sandbox.paypal.com/cgi-bin/webscr";

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL);
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    strNewValue = strFormValues + "&cmd=_notify-validate";
    req.ContentLength = strNewValue.Length;

    StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
    stOut.Write(strNewValue);
    stOut.Close();

    StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
    strResponse = stIn.ReadToEnd();
    stIn.Close();

    return strResponse == "VERIFIED";
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值