Paypal REST API - 在支付过程中传递参数

4
我正在将Paypal直接付款集成到我的ASP.NET MVC 5项目中,使用Paypal的.NET SDK。以下是步骤:
  1. 我调用PayPal.Api.Payment.Create(APIContext)重定向到Paypal网站,并提供成功的URL;
  2. 在回调操作中(对应于成功的URL),调用PayPal.Api.Payment.Execute(APIContext, ExecutionContext)。
我需要的是在调用Payment.Create()时将新订单的ID传递给Paypal,并在Payment.Execute()中接收其值,以便它知道与哪个订单相关联的付款。
是否可能?非常感谢。
1个回答

1
根据SDK和API帮助页面,我会利用发送到Payments.Create()终点的交易中的invoice_number属性。这个交易将成为PayPal响应的一部分,这意味着您可以从API中获取订单号(现在称为invoice_number)。
请查找下面这行代码:invoice_number = YOUR_ORDER_NUMBER 您的PayPal请求:(从SDK示例中获取)
        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(){...},
            description = "This is the payment transaction description.",
            item_list = new ItemList(){...},

            //SET YOUR ORDER NUMBER HERE
            invoice_number = YOUR_ORDER_NUMBER
        };

        // A resource representing a Payer that funds a payment.
        var payer = new Payer(){...};

        // 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 }
        };
        this.flow.AddNewRequest("Create credit card payment", payment);

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

PayPal的回复(来源在此):

enter image description here


嗨Tommy,感谢你的建议,那么如何传递其他参数,比如发送订单的用户的应用程序用户名? - DarioN1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接