购物车加入购物车Asp.Net C# [英] Shopping Cart Add To Cart Asp.Net C#
本文介绍了购物车加入购物车Asp.Net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我正在努力使用我的代码将paypal沙盒添加到我的页面。
到目前为止,我已设法通过我的Checkout按钮指引我发生付款的paypal页面。
我怎么试过修改我的添加到购物车按钮以添加到paypal购物车而没有任何成功。
这是我的HTML:
Hi I am really struggling with my code to add paypal sandbox to my page.
So far I have managed to get my Checkout button to direct me to the paypal page where payment occurs.
How ever I have tried to modify my add to cart button to add to the paypal cart without any success what so ever.
Here is my HTML:
<asp:DataList ID="dlProducts" runat="server" BackColor="White"
BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
GridLines="Both" RepeatColumns="3"
>
<ItemTemplate>
Product Name:
<asp:Label ID="lblProductNane" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label>
<br />
<asp:Image ID="Image1" runat="server" GenerateEmptyAlternateText="True"
Height="100px" ImageUrl='<%# "~/ProductImages/"+Eval("ImageName") %>'
Width="100px" />
<br />
Price:
<asp:Label ID="lblListPrice" runat="server"
Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
<br />
Qty:
<br />
<asp:LinkButton ID="lnkDetails" runat="server"
CommandArgument='<%# Bind("ProductID") %>' onclick="lnkDetails_Click">Click For Details</asp:LinkButton>
<br />
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<asp:HiddenField Value="lblProductName" runat="server" />
<asp:HiddenField Value="lblListPrice" runat="server" />
<asp:ImageButton AlternateText="PayPal — The safer, easier way to pay online." ID="btnBasket" runat="server" CommandArgument='<%# Bind("ProductID") %>' OnClick="btnBasket_Click" ImageUrl="https://www.paypalobjects.com/en_GB/i/btn/btn_cart_LG.gif" />
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1" I>
</form>
</ItemTemplate>
<SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
</asp:DataList>
这是我的代码:
Here is my code behind:
protected void btnBasket_Click(object sender, System.EventArgs e)
{
Response.Write(PaypalPostForm());
PayPalPostScript(Page);
}
public string PaypalPostForm()
{
string PostURL = "http://www.paypal.com/cgi-bin/webscr";
string cmd = "_cart";
string Upload = "1";
string BusinessEmail = "";
string Currency = "GBP";
string method = "post";
string shipAmount = "4.95";
StringBuilder ppForm = new StringBuilder();
ppForm.AppendFormat("<Form name='frmPP' id='frmPP' action='{0}' method='{1}'>", PostURL, method);
ppForm.AppendFormat("<input type='hidden' name='shipping' value='{0}'>", shipAmount);
ppForm.AppendFormat("<input type='hidden' name='cmd' value='{0}'>", cmd);
ppForm.AppendFormat("<input type='hidden' name='upload' value='{0}'>", Upload);
ppForm.AppendFormat("<input type='hidden' name='business' value='{0}'>", BusinessEmail);
ppForm.AppendFormat("<input type='hidden' name='currency_code' value='{0}'>", Currency);
ppForm.AppendFormat("<input type='hidden' name='item_number_1' value='{0}'>", 1);
for(int i = 0; i<this.dlProducts.Items.Count; i++)
{
Label lbldes = this.dlProducts.Items[i].FindControl("lblProductNane") as Label;
string Description = (lbldes.Text).ToString();
Label lblPri = this.dlProducts.Items[i].FindControl("lblListPrice") as Label;
string Price = (lblPri.Text).ToString();
ppForm.AppendFormat("<input type='hidden' name='item_name_1' value='{0}'>", Description);
ppForm.AppendFormat("<input type='hidden' name='amount_1' value='{0}'>", Price);
}
ppForm.AppendFormat("<input type='hidden' name='quantity_1' value='{0}'>", 1);
ppForm.Append("</form>");
return ToString();
}
private void PayPalPostScript(System.Web.UI.Page Page)
{
//This registers Javascript to the page which is used to post the PayPal Form details
StringBuilder strScript = new StringBuilder();
strScript.Append("<script language='javascript'>");
strScript.Append("var ctlForm = document.getElementById('frmPP');");
strScript.Append("ctlForm.submit();");
strScript.Append("</script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "PPSubmit", strScript.ToString());
}
};
推荐答案
从你的问题我假设你正在尝试连接到Sandbox。所以,请使用SandBox URL。也就是说,[action =https://www.paypal.com/cgi-bin/webscr]适用于Paypal真实账户。
如果你将针对Sandbox测试您的网站,将其更改为:
[action =https://www.sandbox.paypal.com/cgi-bin/webscr]。
From you question I assume that you are trying to connect to Sandbox. So, please use SandBox URL. Namely, this, [action="https://www.paypal.com/cgi-bin/webscr"], is for Paypal real account.
If you are going to test your website against the Sandbox, change it as:
[action="https://www.sandbox.paypal.com/cgi-bin/webscr"].
这篇关于购物车加入购物车Asp.Net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文