如何添加贝宝购买按钮,在aspx页面项目 [英] how to add Paypal buy buttons to items in aspx page

查看:269
本文介绍了如何添加贝宝购买按钮,在aspx页面项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们的IAM新手到贝宝。我有一个沙盒测试项目onpaypal并创建了一个
项目购买按钮,被嵌入HTML code ..
现在每当我插入ASPX页面的HTML code忽略了最低重定向到PayPal网站。
也许是因为,涵盖了HTML code中的表单标签..
这里是code贝宝购买按钮一个项目

hi guys iam a newbie to paypal. i got a sandbox test item onpaypal and created an item Buy button which is embedded html code.. now whenever i insert the html code in aspx page it dosen't redirect to the paypal site. Maybe because of the form tag that covers the html code.. here is the code for paypal buy button for an item

<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="3GWR6RV47BCVE">
<input type="image" src="https://www.paypalobjects.com/en_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.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

现在的有人帮,我试图在纯HTML文件这个code和它的工作,但只要我把它放在一个形式RUNAT服务器标签上的ASPX它重定向页面本身..谢谢。

推荐答案

的问题是,ASP.NET页面界定了所有的控制都放在(特别是如果你使用的是母版页)一个表单和HTML不允许嵌套形式的标签。

The problem is that ASP.NET pages define a form within which all the controls are placed (especially if you are using a master page) and HTML does not allow nested form tags.

有解决此几种方法,包括使用一个普通的ASP图像按钮描述<一个href=\"http://www.softcircuits.com/Blog/post/2009/01/22/Implementing-Non-ASPNET-Posts-in-ASPNET.aspx\">here.

There are several ways around this including using a normal ASP image button as described here.

您也可以使用在此描述的锚链接<一个href=\"http://www.softcircuits.com/Blog/post/2010/02/14/Quick-and-Dirty-Buy-Now-Buttons-in-ASPNET.aspx\">blog.然而正如笔者所指出的,用户可以保存网页的源文件,编辑它(例如改价),然后重新加载它,然后单击链接。

You can also use an anchor link as described in this blog. However as noted by the author, the user can save the page source, edit it (e.g. change the price) and then reload it and click the link.

在事实存储在网页的源的信息已经被滥用潜力的任何方法。所以我喜欢的方式,就是用一个ASP图像按钮的组合和锚链接的方法,但要实现这个按钮点击事件中断绝:

In fact any method that stores the information in the source of the webpage has potential to be abused. Therefore the approach I like, is to use a combination of an ASP image button and the anchor link approach but to implement this on the sever within the button click event:

1)在你的ASP页面定义一个要PayPal按钮进入图像按钮。您可以设置为IMAGEURL贝宝提供的preferred按钮类型。

1) In your ASP page define an image button where you want the PayPal button to go. You can set the ImageURL to the preferred button type provided by PayPal.

<asp:ImageButton
    ID="PayPalBtn"
    runat="server"
    ImageUrl="https://www.paypalobjects.com/en_GB/i/btn/btn_buynow_LG.gif"
    onclick="PayPalBtn_Click" />

2)使用该按钮的Click事件生成服务器端所需要的信息,然后将浏览器重定向到PayPal网站。

2) Use the Click event of the button to generate the required information on the server side and then redirect the browser to the PayPal site.

protected void PayPalBtn_Click(object sender, ImageClickEventArgs e)
{
    string business = "<insert your paypal email or merchant id here>";
    string itemName = "<insert the item name here>";
    double itemAmount = 123.451;
    string currencyCode = "GBP";

    StringBuilder ppHref = new StringBuilder();

    ppHref.Append("https://www.paypal.com/cgi-bin/webscr?cmd=_xclick");
    ppHref.Append("&business=" + business);
    ppHref.Append("&item_name=" + itemName);
    ppHref.Append("&amount=" + itemAmount.ToString("#.00"));
    ppHref.Append("&currency_code=" + currencyCode);

    Response.Redirect(ppHref.ToString(), true);
}

免责声明:它仍可能为用户滥用这一做法(虽然现在有点困难),所以它始终是最好的检查有什么货物调度之前已支付

Disclaimer: It may still be possible for users to abuse this approach (although it is now a bit harder) so it is always best to check what has been paid before dispatching goods.

这篇关于如何添加贝宝购买按钮,在aspx页面项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆