c# - 在 C# ASP.net 中生成 PayPal 按钮的 POST 请求

标签 c# asp.net paypal

我正在尝试允许网络表单使用 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/

相关文章:

Linux 上 .NET Core 中的 C# : Referencing or using . so 文件

c# - 在 ASP.NET 中动态填充时间下拉菜单

c# - 如何在 .NET 中获取给定字符串的单向哈希?

node.js - 通过 node.js 中的 Paypal 自适应支付 API 发送隐式支付时出错

c# - NEST 搜索整个文档 C# Elasticsearch

c# - 如何在 C# 中绘制流数据图表

c# - 已签名的超值的解析器?

Paypal 整合直接接受信用卡付款

ios - 有没有办法验证电子邮件地址是否是有效的 Paypal 电子邮件

c# - 如何处理这种树遍历