我正在尝试允许网络表单使用 PayPal 立即购买。 The relevant page is here.
基于用户选择的单选按钮,取决于他们被“重定向”到哪个 Paypal 按钮。 订阅很简单 - 它们只是一个简单的重定向。
最后一个选项要求用户选择 field 。 为此,我需要使用下面的表格:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="10956105">
<table>
<tr><td><input type="hidden" name="on0" value="Venue">Venue</td></tr><tr><td>
<input type="text" name="os0" maxlength="60"></td></tr>
</table>
<input type="image" src="https://www.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
但是,当然,我想在不使用该表单的情况下完成此操作。
到目前为止我所拥有的是:
if (singleOneOff.Checked)
{
paypalForm.Text = getPaypalForm(venueSelect.SelectedItem.Text);
var strJS = getPayPalPostJS("_xclick");
paypalJs.Text = strJS;
var xxx = "dd";
}
这确定是否选中了特定的单选按钮。
获取PaypalForm
private String getPaypalForm(string venue)
{
StringBuilder strForm = new StringBuilder();
strForm.Append(@"<form action=""https://www.paypal.com/cgi-bin/webscr"" name=""_xclick"" method=""post"">");
strForm.Append(@"<input type=""hidden"" name=""cmd"" value=""_s-xclick"">");
strForm.Append(@"<input type=""hidden"" name=""hosted_button_id"" value=""10956105"">");
strForm.Append(@"<input type=""hidden"" name=""on0"" value=""Venue"">");
strForm.Append(@"<input type=""text"" name=""os0"" value=""{0}"" maxlength=""60"">");
strForm.Append("</form>");
return String.Format(strForm.ToString(), venue);
}
getPayPalPostJS
private String getPayPalPostJS(string strFormId)
{
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var paypalForm = document.forms.namedItem('{0}');");
strScript.Append("paypalForm.submit();");
strScript.Append("</script>");
return String.Format(strScript.ToString(), strFormId);
}
但是,如果我选择单选按钮和地点,然后按下按钮,则不会发生任何事情......
有什么想法是我哪里出错了吗?
我遵循了这个指南:http://www.netomatix.com/development/postrequestform.aspx
最佳答案
这是针对 ASP.NET/PayPal 单一表单问题的更简洁的服务器端解决方案:
http://codersbarn.com/post/2008/03/08/Solution-to-ASPNET-Form-PayPal-Problem.aspx
关于c# - 在 C# ASP.net 中生成 PayPal 按钮的 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009808/