我正在尝试找到一种将Paypal捐赠按钮添加到asp.net Webform的方法,因为它包裹在我无法添加的表单周围。有没有办法添加它。或者只是一个链接按钮。

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="xxxx">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

最佳答案

您可以做几件事。

使用表单制作一个静态HTML页面,并在aspx页面上使用iframe。

<iframe src="paypal.html"></iframe>


在按钮上单击表单后面的代码以进行表单发布(未经测试的代码,但是在SO上还有更多示例,例如如何在后面的代码中进行表单发布)

protected void Button1_Click(object sender, EventArgs e)
{
    using (WebClient client = new WebClient())
    {
        byte[] response = client.UploadValues("https://www.paypal.com/cgi-bin/webscr", new NameValueCollection()
        {
            { "cmd", "_s-xclick" },
            { "hidden", "xxxx" }
        });

        string result = Encoding.UTF8.GetString(response);
    }
}


您可以尝试使用表单值作为查询字符串进行链接。在各个论坛上都有对此的引用。

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=xxxx">PayPal</a>


最后,您可以与PayPal API进行通信

https://developer.paypal.com/docs/api/

07-28 02:44
查看更多