将多个项目添加到 PayPal 购物车 [英] Adding multiple items to a PayPal cart

查看:33
本文介绍了将多个项目添加到 PayPal 购物车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 PayPal 创建了一个非常适合添加单个项目的类,但是我现在正尝试将其作为购物车使用,以便我可以添加多个产品并使用我的徽标自定义页面.

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

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.

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

推荐答案

您好,我目前正面临着类似的问题,直到我意识到 asp.net 中继器可以帮助我解决这个问题.

Hello I'm currently facing similar problem until i realize that asp.net repeater can help me resolve this.

例如在您的应用程序界面上,它必须包含此 ff.默认情况下的代码行(以防万一您希望您的项目列表是动态的):

For example on your application interface, it must contain this 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>

鉴于:

所需的第三方购物车变量您的 HTML 代码至少需要以下隐藏的 HTML 变量.有关变量的完整列表,请参阅附录 A,网站支付标准的 HTML 变量".表4.1

Required Third Party Shopping Cart Variables Your HTML code requires at least the following hidden HTML variables. For a complete list of variables, see Appendix A, "HTML Variables for Website Payments Standard." Table 4.1

所需的第三方购物车变量姓名

Required Third Party Shopping Cart Variables Name

说明item_name1 -单品名称

amount_1 -购物车中单件商品的价格或所有商品的总价

amount_1 - Price of a single item or the total price of all items in the shopping cart

数量_1 -单件数量

业务 -
您的 PayPal 帐户的电子邮件地址

business -
Email address of your PayPal account

item_name_1 -商品名称或整个购物车的名称

item_name_1 - Name of the item or a name for the entire shopping cart

上传 -表示使用第三方购物车有两种方法可以将您的第三方购物车与 PayPal 和网站支付标准集成:

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:

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

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:

希望这篇文章能解答您的疑虑.:) :)

Hope this post answered your concern. :) :)

这篇关于将多个项目添加到 PayPal 购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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