如何重定向用户从C#参数到PayPal [英] How to redirect user to paypal with parameters from c#

查看:252
本文介绍了如何重定向用户从C#参数到PayPal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有简单的表格像这样的波纹管我可以用它来重定向用户到PayPal完成支付:

If I have simple form like this one bellow I can use it to redirect user to paypal to complete payment:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" ...
    <input type="hidden" name="custom" value="<%= someVariable %>" />
    <input type="submit" value="ok" />
</form>

当我必须做一些动作之前重定向用户到PayPal我需要正常

ASP 按钮,将圆顶一些动作之前重定向用户到PayPal。

我的问题是如何从C#code-背后做到这一点?

我可以从上面的表格通过所有必需的隐藏字段,如自定义这是非常重要的。

As I have to do some actions before redirect user to paypal I need to make normal
asp button that will dome some actions before redirect user to paypal.
My question is how I can do this from c# code-behind?
It's important that I can pass all required hidden fields like 'custom' from form above.

推荐答案

传统ASP.Net不允许多个表格标记。

Traditional ASP.Net doesn't allow multiple form tag.

下面的示例code将让你发布的格式贝宝从code的后面。

The following sample code will let you post the form to PayPal from code behind.

protected void BuyButton_Click(object sender, EventArgs e)
{
   string url = TestMode ? 
      "https://www.sandbox.paypal.com/us/cgi-bin/webscr" : 
      "https://www.paypal.com/us/cgi-bin/webscr";

   var builder = new StringBuilder();
   builder.Append(url);
   builder.AppendFormat("?cmd=_xclick&business={0}", HttpUtility.UrlEncode(Email));
   builder.Append("&lc=US&no_note=0&currency_code=USD");
   builder.AppendFormat("&item_name={0}", HttpUtility.UrlEncode(ItemName));
   builder.AppendFormat("&invoice={0}", TransactionId);
   builder.AppendFormat("&amount={0}", Amount);
   builder.AppendFormat("&return={0}", HttpUtility.UrlEncode(ReturnUrl));
   builder.AppendFormat("&cancel_return={0}", HttpUtility.UrlEncode(CancelUrl));
   builder.AppendFormat("&undefined_quantity={0}", Quantity);
   builder.AppendFormat("&item_number={0}", HttpUtility.UrlEncode(ItemNumber));

   Response.Redirect(builder.ToString());
}

下面是关于贝宝标准字段的详细信息 - <一个href=\"https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/\"相对=nofollow> HTML变量贝宝付款标准

Here are more information about PayPal Standard Fields - HTML Variables for PayPal Payments Standard

这篇关于如何重定向用户从C#参数到PayPal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆