【问题标题】:Adding multiple items to a PayPal cart将多个项目添加到 PayPal 购物车
【发布时间】:2012-08-02 22:15:48
【问题描述】:

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

谁能提供我如何做这件事的任何例子?我浏览了很多网站,但似乎没有一个能很好地解释。据我了解,我正在使用 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();
    }
}

【问题讨论】:

  • 不相关:C# 中的参数应该是 Camal-Case:int Amount, string ItemNameint amount, string itemName

标签: c# paypal


【解决方案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 - 商品名称或整个购物车的名称

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

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

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

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

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

你好!当您重定向到沙盒时,您会得到这个结果:

希望这篇文章能回答您的问题。 :) :)

【讨论】:

  • 我把所有的东西都写到if (!Page.IsPostBack){},但是你如何把转发器中的项目放到数据表中,然后把它们发布到贝宝?
  • 以上代码只是一个示例,说明您将如何将项目传递给贝宝。我刚刚向您展示了如何通过中继器控件(隐藏字段)填充您的项目。提交表格后,您的个人物品将被传递到贝宝。
【解决方案2】:

我过去也遇到过同样的问题。我必须做的是创建自己的购物车,独立于 Paypal。然后,当客户准备结账时,我将其转发给 Paypal。我没有发送多个商品和价格,而是将所有内容组合在一起以使用 Paypal。

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

如果您正在寻找一个好的购物车系统,实际上有数百个支持 Paypal 和这种方法。

【讨论】:

  • 感谢 Tyler,这正是我现在的设置方式。你解决过你的问题吗?
  • 是的。我停止使用 Paypal 并切换到 Stripe :)。无需时间即可实施,而且不花一分钱。
  • 我会看看它可能是一个选项。可悲的是,此刻我必须让贝宝工作。
  • 您的另一个选择是使用Paypal Websites AdvancedPaypal Websites Pro 处理您自己域中的网站。
猜你喜欢
  • 1970-01-01
  • 2018-02-15
  • 2020-01-14
  • 1970-01-01
  • 2017-07-23
  • 2022-11-10
  • 2013-09-27
  • 2015-03-31
  • 1970-01-01
相关资源
最近更新 更多