2012-08-02 98 views
3

我创建了一个PayPal类,它非常适用于添加单个项目,但是我现在试图让这个项目成为购物车,所以我可以添加多个产品并使用我的徽标自定义页面。添加多个项目到PayPal购物车

任何人都可以提供我如何去做这个事情的任何例子?我浏览了不少网站,但是他们中没有一个似乎很好解释。从我的理解我正在使用贝宝标准。

public static class PayPal 
{ 

    public static string _URLRedirect; 
    public static void ProcessPayment(int Amount, string ItemName) 
    { 

     const string Server_URL = "https://www.sandbox.paypal.com/cgi-bin/webscr?"; 
     const string return_URL = "https://www.paypal.com/xclick/[email protected]"; 
     const string cancelreturn_URL = "http://www.PageWhenCancel.com/cc.fail.aspx"; 

     //Assigning Cmd Path as Statically to Parameter 
     string cmd = "_xclick"; 

     //Assigning business Id as Statically to Parameter 
     string business = "[email protected]";// Enter your business account here 

     //Assigning item name as Statically to Parameter 
     string item_name = ItemName.ToString(); 

     //Passing Amount as Statically to parameter 
     int amount = Amount; 

     //Passing Currency as Statically to parameter 
     string currency_code = "GBP"; 

     string redirect = ""; 

     //Pass your Server_Url,cmd,business,item_name,amount,currency_code variable.   
     redirect += Server_URL; 
     redirect += "cmd=" + cmd; 
     redirect += "&business=" + business; 
     redirect += "&item_name=" + item_name; 
     redirect += "&amount=" + amount; 
     redirect += "&currency_code=" + currency_code; 


     redirect += "&return=" + return_URL; 
     redirect += "&cancel_return" + cancelreturn_URL; 


     //Redirect to the payment page 
     _URLRedirect = redirect.ToString(); 
    } 
} 
+1

无关:C#中的参数应该是Camal-Case:'int Amount,string ItemName'为'int amount,string itemName'。 – 2012-08-02 22:50:47

回答

0

我以前有过这个相同的问题。我必须做的是独立于PayPal创建我自己的购物车。然后,当客户准备结账时,我将其转发给PayPal。我没有发送多个商品和价格,而是将所有商品结合在一起以获得PayPal。

例如,如果客户订购3件不同的商品,每件5美元,我的网站会显示3件商品和3件价格。但是,如果转到PayPal,客户会看到一个项目(即“我的公司订单”)和一个价格(即15美元)。但是当返回到我的网站时,客户会再次看到订购了3件商品。

如果您正在寻找一个良好的购物车系统,有几百个可用的支持贝宝和这种方法。

+0

谢谢泰勒,这正是我现在设置的。你有没有解决你的问题? – Steve 2012-08-02 22:30:07

+0

是的。我停止使用Paypal并切换到[Stripe](http://stripe.com):)。没有时间实施,不花一毛钱。 – 2012-08-02 22:31:31

+0

我会看看,因为它可能是一个选项。可悲的是,我必须得到paypal才能工作。 – Steve 2012-08-02 22:35:57

1

你好,我目前面临类似的问题,直到我意识到,asp.net转发器可以帮助我解决这个问题。

例如在您的应用程序界面上,它必须包含此ff。默认情况下的代码行(以防万一你要想问你的商品列表是动态的):

<form id="Paypal" name="Paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr"> 
method="post"> 
<input type="hidden" name="cmd" value="_cart" /> 
<input type="hidden" name="upload" value="1" /> 
<input type="hidden" name="business" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings[" paypalemail="] %>" /> 
<asp:repeater id="rptItems" runat="server" xmlns:asp="#unknown"> 
<itemtemplate> 
    <input type="hidden" name="item_name_<%# Eval("itemCount") %>" value="<%# Eval("itemValue") %>" /> 
    <input type="hidden" name="quantity_<%# Eval("itemCount") %>" value="<%# Eval("quantityValue") %>" /> 
    <input type="hidden" name="amount_<%# Eval("itemCount") %>" value="<%# Eval("amountValue") %>" /> 
</itemtemplate> 
</asp:repeater> 
<input type="hidden" name="shipping_1" value="5" /> 
<input type="hidden" name="handling_1" value="5" /> 
<input type="hidden" name="tax_1" value="5" /> 
<input type="hidden" name="currency_code" value="USD" /> 
<input type="hidden" name="return" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings[" successurl="] %>" /> 
<input type="hidden" name="cancel_return" value="<%=System.Web.Configuration.WebConfigurationManager.AppSettings[" failedurl="] %>" /> 
<input type="hidden" name="lc" value="test lc country" /> 
<input type="submit" value="Submit" /> 

</form> 

而:

需要的第三方购物车的变量 你的HTML代码至少需要下面隐藏的HTML变量。有关变量的完整列表,请参阅附录A“网站付款标准的HTML变量”。 表4。1级

需要的第三方购物车的变量 名称

说明 item_name1 - 单个项目的 名称

amount_1 - 价格的单个项目或所有项目的总价格购物车中

quantity_1 -单个项目的数量

业务 - 整个购物车中的物品或名称的名称

上传 -
您的PayPal帐户

ITEM_NAME_1的 电子邮件地址 - 指示使用第三方购物车 有两种方法可将您的第三方购物车与Pa yPal和网站支付标准:

传递单个项目的详细信息。

传递总购物车付款总额,而不是单个项目详细信息。

,并在后面的代码,你可以做这样的事情:

if (!Page.IsPostBack) 
    { 
     DataTable dtItems = new DataTable(); 
     dtItems.Columns.Add("itemCount"); 
     dtItems.Columns.Add("itemValue"); 
     dtItems.Columns.Add("quantityValue"); 
     dtItems.Columns.Add("amountValue"); 
     dtItems.Rows.Add("1","Cellphone", "10", "200.00"); 
     dtItems.Rows.Add("2", "Bag", "2", "250.00"); 
     dtItems.Rows.Add("3", "Mouse", "10", "3500.00"); 
     dtItems.Rows.Add("4", "Keyboard", "5", "200.00"); 

     rptItems.DataSource = dtItems; 
     rptItems.DataBind(); 
    } 

和呼啦!当你重定向到沙盒时,你会得到这个结果: Paypal_capture

希望此贴回复了您的关注。 :) :)

+0

我得到了一切,直到'if(!Page.IsPostBack){}',但是如何将转发器中的项目转换为数据表并将其发送到paypal? – needmorebeerformewallaby 2012-08-08 08:12:59

+0

上面的代码仅仅是您如何将项目传递给paypal的示例。我刚刚向您展示了如何通过中继器控件(这是隐藏的字段)填充项目。提交表格后,您的个人物品将被传递到贝宝。 – janrusselcalachan 2012-09-21 02:43:08