简体   繁体   English

将多个商品添加到PayPal购物车

[英]Adding multiple items to a PayPal cart

I have created a class for PayPal that works great for adding single items however I am now trying to get this working as a cart so i can add multiple products and customise the page with my logo. 我已经为PayPal创建了一个类,它非常适合添加单个项目,但我现在正试图将其作为购物车使用,这样我就可以添加多个产品并使用我的徽标自定义页面。

Can anyone provide any examples of how I go about doing this? 任何人都可以提供我如何做这个的例子吗? I have looked around quite a few websites however none of them seem to really explain very well. 我浏览过很多网站,但似乎没有一个网站能够很好地解释。 From what I understand I am doing using PayPal Standard. 根据我的理解,我正在使用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/Sample@gmail.com";
        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 = "payments@xxx.xx.xx";// 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();
    }
}

Hello I'm currently facing similar problem until i realize that asp.net repeater can help me resolve this. 您好我正面临类似的问题,直到我意识到asp.net转发器可以帮我解决这个问题。

For example on your application interface, it must contain this ff. 例如,在您的应用程序界面上,它必须包含此ff。 line of code by default (just in case you wanted your items list to be dynamic): 默认情况下的代码行(以防您希望项目列表是动态的):

<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>

whereas: 然而:

Required Third Party Shopping Cart Variables Your HTML code requires at least the following hidden HTML variables. 必需的第三方购物车变量您的HTML代码至少需要以下隐藏的HTML变量。 For a complete list of variables, see Appendix A, “HTML Variables for Website Payments Standard.” Table 4.1 有关变量的完整列表,请参阅附录A“网站付款标准的HTML变量”。表4.1

Required Third Party Shopping Cart Variables Name 必需的第三方购物车变量名称

Description item_name1 - Name of a single item 描述item_name1 - 单个项目的名称

amount_1 - Price of a single item or the total price of all items in the shopping cart amount_1 - 单个商品的价格或购物车中所有商品的总价

quantity_1 - Quantity of a single item quantity_1 - 单个项目的数量

business - 业务 -
Email address of your PayPal account 您的PayPal帐户的电子邮件地址

item_name_1 - Name of the item or a name for the entire shopping cart item_name_1 - 项目名称或整个购物车的名称

upload - Indicates the use of third party shopping cart There are two ways to integrate your third party shopping cart with PayPal and Website Payments Standard: 上传 - 表示使用第三方购物车有两种方法可将第三方购物车与PayPal和网站付款标准集成:

Pass the details of the individual items. 传递单个项目的详细信息。

Pass the aggregate amount of the total cart payment, rather than the individual item details. 通过总购物车付款的总金额,而不是单个项目的详细信息。

and on your code behind, you can do something like this: 在你的代码背后,你可以做这样的事情:

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();
   }

and holla! 和霍拉! you'll get this result when you redirect to sandbox: 当您重定向到沙箱时,您将获得此结果: Paypal_capture

Hope this post answered your concern. 希望这篇文章能回答你的疑虑。 :) :) :) :)

I have had this same issue in the past. 我过去也遇到过同样的问题。 What I had to do was create my own cart independent of Paypal. 我必须做的是独立于Paypal创建我自己的购物车。 Then, when the customer was ready to check out, I forward them to Paypal. 然后,当客户准备结账时,我将它们转发给Paypal。 Instead of sending multiple items and prices, I combine everything together for Paypal. 而不是发送多个项目和价格,我将所有内容组合在一起用于Paypal。

For example if the customer orders 3 different items @ $5 each, my site would show 3 items and 3 prices. 例如,如果客户订购3个不同的商品@ $ 5,我的网站将显示3个商品和3个价格。 However, upen being forwarded to Paypal, the customer would see one item (ie "My Company Order") and one price (ie $15). 但是,如果转移到Paypal,客户会看到一个项目(即“我的公司订单”)和一个价格(即15美元)。 But when returned to my site, the customer would once again see that there were 3 items ordered. 但当返回我的网站时,客户将再次看到订购了3件商品。

If you are looking for a good cart system, there are literally hundreds available that support Paypal and this method. 如果您正在寻找一个好的购物车系统,那么有数百种可用的支持Paypal和这种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM