【问题标题】:Passing a cart total variable to Paypal in asp.net在 asp.net 中将购物车总变量传递给 Paypal
【发布时间】:2013-03-25 01:08:32
【问题描述】:

在实施 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">

【问题讨论】:

    标签: asp.net paypal


    【解决方案1】:

    您不能在 ASP.Net 页面中插入您的 form tag(除非 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());
    
    }
    

    【讨论】:

      【解决方案2】:

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

      field.value=GrandTotal;

      您的 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>
      

      页面代码背后的代码 protected void Page_Load(object sender, EventArgs e) {

          if(!IsPostBack)
          {
      
              amount.Value = "25.25";
          }
      
      }
      

      【讨论】:

      • 感谢您的回复。对不起,我是一个绝对的新手,我不明白 .cs 文件中的内容,你能扩展一下吗?
      猜你喜欢
      • 2013-03-25
      • 2012-09-24
      • 2015-01-08
      • 2018-01-28
      • 2017-12-17
      • 2012-03-28
      • 2012-08-30
      • 2022-08-23
      • 1970-01-01
      相关资源
      最近更新 更多