本文主要是介绍asp.net mvc paypal web网站支付,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/// <summary>/// 生成提交表单
/// </summary>
/// <param name="businessName">收款账号</param>
/// <param name="dataTitle">标题</param>
/// <param name="notifyUrl">及时回调地址</param>
/// <param name="returnUrl">用户返回地址</param>
/// <param name="cancelUrl">用户取消支付地址</param>
/// <param name="price">价格</param>
/// <param name="orderNo">订单号</param>
/// <returns>string</returns>
public string GetPayPalFormHtml(string businessName, string dataTitle, string notifyUrl, string returnUrl, string cancelUrl, decimal price, string orderNo)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("支付跳转中,请稍后。。。");
//https://www.sandbox.paypal.com/cgi-bin/webscr
//https://www.paypal.com/cgi-bin/webscr
sb.AppendFormat("<form id=\"alipaysubmit\" name=\"alipaysubmit\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">");
sb.AppendFormat(" <input type=\"hidden\" name=\"cmd\" value=\"_xclick\">");
sb.AppendFormat(" <input type=\"hidden\" name=\"business\" value=\"{0}\">", businessName);
sb.AppendFormat(" <input type=\"hidden\" name=\"item_name\" value=\"{0}\">", dataTitle);
sb.AppendFormat(" <input type=\"hidden\" name=\"amount\" value=\"{0}\">", price.ToDecimal2Yen());
sb.AppendFormat(" <input type=\"hidden\" name=\"currency_code\" value=\"USD\">");
sb.AppendFormat(" <input type=\"hidden\" name=\"lc\" value=\"US\">");
sb.AppendFormat(" <input type=\"hidden\" name=\"no_shipping\" value=\"1\">");
sb.AppendFormat(" <input type=\"hidden\" name=\"notify_url\" value=\"{0}\">", notifyUrl);
sb.AppendFormat(" <input type=\"hidden\" name=\"return\" value=\"{0}\">", returnUrl);
sb.AppendFormat(" <input type=\"hidden\" name=\"cancel_return\" value=\"{0}\">", cancelUrl);
sb.AppendFormat(" <input type=\"hidden\" name=\"custom\" value=\"{0}\">", orderNo);
sb.AppendFormat(" <input type=\"hidden\" name=\"charset\" value=\"utf-8\" />");
sb.AppendFormat("</form>");
sb.Append("<script>document.oncontextmenu = function (){return false};setTimeout(function () {document.forms['alipaysubmit'].submit(); }, 1000);</script>");
return sb.ToString();
}
/// <summary>
/// 支付完成返回地址
/// </summary>
/// <returns></returns>
public ActionResult PayPalOrderReturn()
{
try
{
//订单号
string orderNo= Request["custom"].ToString2();
//支付价格
decimal price = Request["mc_gross"].ToDecimal2();
//支付账号
string business = Request["business"].ToString();
//客户有已认证的PayPal账户
string payerStatus = Request["payer_status"].ToString();
//付款状态
string paymentStatus = Request["payment_status"].ToString2();
//付款状态只能为“Completed”才是处理成功,http://www.cnblogs.com/toosuo/archive/2012/12/18/2823526.html 参考状态
if (paymentStatus == "Completed" && business == ACCOUNT) //ACCOUNT为收款账号
{
//处理支付成功逻辑
}
else
{
throw new Exception("支付失败信息有误");
}
return RedirectToAction("PaySuccess", new { orderNo= orderNo});
}
catch (Exception ex)
{
throw new Exception("支付失败信息有误");
}
}
/// <summary>
/// 支付完成及时回调地址
/// </summary>
/// <returns></returns>
public ActionResult PayPalOrderNotify()
{
try
{
//订单号
string orderNo= Request["custom"].ToString2();
//支付价格
decimal price = Request["mc_gross"].ToDecimal2();
//支付账号
string business = Request["business"].ToString();
//客户有已认证的PayPal账户
string payerStatus = Request["payer_status"].ToString();
//付款状态
string paymentStatus = Request["payment_status"].ToString2();
//付款状态只能为“Completed”才是处理成功,http://www.cnblogs.com/toosuo/archive/2012/12/18/2823526.html 参考状态
if (paymentStatus == "Completed" && business == ACCOUNT)
{
//处理支付成功逻辑
}
else
{
throw new Exception("支付失败信息有误");
}
return RedirectToAction("PaySuccess", new { orderNo= orderNo});
}
catch (Exception ex)
{
throw new Exception("支付失败信息有误");
}
}
/// <summary>
/// 用户取消支付的订单
/// </summary>
/// <returns></returns>
public ActionResult PayPalOrderCancel()
{
//处理取消逻辑
}
这篇关于asp.net mvc paypal web网站支付的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!