0

在实施 Paypal 时,我设法将其设置为发送设定值,例如 25 英镑,但不是篮子中的变量,例如“GrandTotal”,这取决于客户在购物车中输入的内容(我创建了自己的购物车。 )

<form action="paypal.com/cgi-bin/webscr"; method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you@youremail.com">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="amount" value="25.00"> 
<input type="image" src="paypal.com/en_US/i/btn/x-click-but01.gif"; name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form>

您知道如何发送变量而不是设定数量吗?下面的代码是否接近解决方案?

<input type="hidden" name="amount" value="GrandTotal">
4

2 回答 2

0

您不能form tag在 ASP.Net 页面中插入您的页面(除非 iframe),因为 ASP.Net 只允许在页面中使用一个表单标签。

你想在后面的代码中类似这样。它基本上收集用户输入的金额和数量,然后将其发送回 PayPal。

protected void PayButton_Click(object sender, EventArgs e) {

 string paypalUrl = IsTestMode ? 
   "https://www.sandbox.paypal.com/us/cgi-bin/webscr" : 
   "https://www.paypal.com/us/cgi-bin/webscr";

 var builder = new StringBuilder();

 builder.Append(paypalUrl);

 builder.AppendFormat("?cmd=_xclick&business={0}", 
    HttpUtility.UrlEncode(you@youremail.com));

 builder.Append("&lc=US&no_note=0&currency_code=GBP");

 builder.AppendFormat("&item_name={0}", 
    HttpUtility.UrlEncode(YourItemName));

 builder.AppendFormat("&amount={0}", AmountTextBox.Text);

 builder.AppendFormat("&return={0}", 
    HttpUtility.UrlEncode("http://mysite.cm/ReturnUrl"));

 builder.AppendFormat("&cancel_return={0}", 
    HttpUtility.UrlEncode("http://mysite.cm/CancelUrl"));

 builder.AppendFormat("&undefined_quantity={0}", QuantityTextBox.Text);

 HttpContext.Current.Response.Redirect(builder.ToString());

}
于 2013-04-03T14:14:57.447 回答
0

您可以通过在输入字段标签中添加 runat="server" 来制作输入字段服务器端,并可以从 .cs 文件中设置它的值

field.value=总计;

您的 aspx 页面代码

<form name="_xclick" target="paypal" action="https://www.paypal.com/cgi-bin/webscr"
method="post" runat="server">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="you@youremail.com" />
<input type="hidden" name="item_name" value="Item Name" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="amount" id="amount" runat="server" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/view_cart.gif" border="0"
    name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="display" value="1">
</form>

您的页面代码受保护的代码后面的代码 void Page_Load(object sender, EventArgs e) {

    if(!IsPostBack)
    {

        amount.Value = "25.25";
    }

}
于 2013-04-03T12:37:29.767 回答