Adding multiple items to a PayPal cart

痴心易碎 提交于 2019-12-19 09:43:12

问题


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.

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

回答1:


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

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>

whereas:

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

Description item_name1 - Name of a single item

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

quantity_1 - Quantity of a single item

business -
Email address of your PayPal account

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

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. :) :)




回答2:


I have had this same issue in the past. What I had to do was create my own cart independent of Paypal. Then, when the customer was ready to check out, I forward them to Paypal. Instead of sending multiple items and prices, I combine everything together for Paypal.

For example if the customer orders 3 different items @ $5 each, my site would show 3 items and 3 prices. However, upen being forwarded to Paypal, the customer would see one item (ie "My Company Order") and one price (ie $15). But when returned to my site, the customer would once again see that there were 3 items ordered.

If you are looking for a good cart system, there are literally hundreds available that support Paypal and this method.



来源:https://stackoverflow.com/questions/11786608/adding-multiple-items-to-a-paypal-cart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!