在贝宝支付多个项目

Posted

技术标签:

【中文标题】在贝宝支付多个项目【英文标题】:Paying for multiple items in paypal 【发布时间】:2016-10-03 04:04:58 【问题描述】:

我正在执行以下操作以将多个项目添加到 Paypal,但它不起作用。没有任何项目被添加。但是,如果我只添加一个项目而不添加附加“_1”、“_2”到 item_name 等,那么一切都会完美运行。在这种情况下我做错了什么?

表格

<form name="paypal_auto_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

<input type="hidden" value="2" name="rm">
<input type="hidden" value="_xclick" name="cmd">
<input type="hidden" value="USD" name="currency_code">
<input type="hidden" value="myname@gmail.com" name="business">
<input type="hidden" value="http://[::1]/d/paypal/success" name="return">
<input type="hidden" value="http://[::1]/d/paypal/cancel" name="cancel_return">
<input type="hidden" value="http://[::1]/d/paypal/ipn" name="notify_url">

<input type="hidden" value="Laptop" name="item_name_1">  
<input type="hidden" value="1" name="custom_1">
<input type="hidden" value="1" name="item_number_1">
<input type="hidden" value="500.00" name="amount_1">
<input type="hidden" value="1" name="quantity_1">

<input type="hidden" value="Laptop" name="item_name_2">
<input type="hidden" value="1" name="custom_2">
<input type="hidden" value="1" name="item_number_2">
<input type="hidden" value="500.00" name="amount_2">
<input type="hidden" value="1" name="quantity_2">

<p><input type="submit" value="Click here" name="pp_submit"></p></form>

结果

【问题讨论】:

我不完全确定我看到了任何 php 代码,而且 html 表单也没有竞争...... 我刚刚在问题中添加了相关代码。表格实际上是完整的,它是PHP代码。编辑:现在我也添加了表单代码。 &lt;input type="hidden" value="1" name="upload"&gt; 加这个,看看能不能用 它的 HTML 不是 PHP,是一个错字。 嘿,Farkie,我添加了,但结果是一样的。 【参考方案1】:

请检查 Paypal Api 文档中的所有必填字段。可能缺少某些东西。您的数据中应该有 items 数组。项目(名称、货币、价格、数量)。您还应该有一个对象 Payer(它是付款方式)、redirect Urldetails 对象(税金、运费、小计)、金额对象(货币、总额)、交易对象(描述、发票编号、金额、项目)。我做到了,但在 C# 中。您可以使用可用的库。

    在 C# 中PayPal-NET-SDK 在 PHP 中 PayPal-PHP-SDK 其他检查文档Payments API

选择最适合您的项目的内容。它认为其中之一应该可以帮助您。

这是一个 C# 示例

using PayPal.Api;
using System.Collections.Generic;

namespace PayPal.Sample

public partial class PaymentWithCreditCard : BaseSamplePage

    protected override void RunSample()
    
        // ### Api Context
        // Pass in a `APIContext` object to authenticate 
        // the call and to send a unique request id 
        // (that ensures idempotency). The SDK generates
        // a request id if you do not pass one explicitly. 
        // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
        var apiContext = Configuration.GetAPIContext();

        // A transaction defines the contract of a payment - what is the payment for and who is fulfilling it. 
        var transaction = new Transaction()
        
            amount = new Amount()
            
                currency = "USD",
                total = "7",
                details = new Details()
                
                    shipping = "1",
                    subtotal = "5",
                    tax = "1"
                
            ,
            description = "This is the payment transaction description.",
            item_list = new ItemList()
            
                items = new List<Item>()
                
                    new Item()
                    
                        name = "Item Name",
                        currency = "USD",
                        price = "1",
                        quantity = "5",
                        sku = "sku"
                    
                ,
                shipping_address = new ShippingAddress
                
                    city = "Johnstown",
                    country_code = "US",
                    line1 = "52 N Main ST",
                    postal_code = "43210",
                    state = "OH",
                    recipient_name = "Joe Buyer"
                
            ,
            invoice_number = Common.GetRandomInvoiceNumber()
        ;

        // A resource representing a Payer that funds a payment.
        var payer = new Payer()
        
            payment_method = "credit_card",
            funding_instruments = new List<FundingInstrument>()
            
                new FundingInstrument()
                
                    credit_card = new CreditCard()
                    
                        billing_address = new Address()
                        
                            city = "Johnstown",
                            country_code = "US",
                            line1 = "52 N Main ST",
                            postal_code = "43210",
                            state = "OH"
                        ,
                        cvv2 = "874",
                        expire_month = 11,
                        expire_year = 2018,
                        first_name = "Joe",
                        last_name = "Shopper",
                        number = "4877274905927862",
                        type = "visa"
                    
                
            ,
            payer_info = new PayerInfo
            
                email = "test@email.com"
            
        ;

        // A Payment resource; create one using the above types and intent as `sale` or `authorize`
        var payment = new Payment()
        
            intent = "sale",
            payer = payer,
            transactions = new List<Transaction>()  transaction 
        ;

        // ^ Ignore workflow code segment
        #region Track Workflow
        this.flow.AddNewRequest("Create credit card payment", payment);
        #endregion

        // Create a payment using a valid APIContext
        var createdPayment = payment.Create(apiContext);

        // ^ Ignore workflow code segment
        #region Track Workflow
        this.flow.RecordResponse(createdPayment);
        #endregion

        // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
    


【讨论】:

以上是关于在贝宝支付多个项目的主要内容,如果未能解决你的问题,请参考以下文章

在贝宝沙盒中注册网站支付专业版会重定向到实时贝宝网站

如何在贝宝卡支付字段中禁用填充

asp.net - 无法在贝宝上进行自适应付款

在贝宝沙箱中设置自动返回?

在贝宝(贝宝订阅)中首次定期付款时应用折扣优惠券代码

如何在贝宝的计费周期开始时收取金额