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

时间:2016-10-18 21:25:57

标签: asp.net-mvc paypal

我使用Paypal的.NET SDK将Paypal直接支付整合到我的ASP.NET MVC 5项目中。以下是步骤:

  1. 我打电话给PayPal.Api.Payment.Create(APIContext)重定向到Paypal网站,网址成功;
  2. 在与成功网址对应的回调操作中,调用PayPal.Api.Payment.Execute(APIContext,ExecutionContext)。
  3. 我需要的是在致电Payment.Create()时将新订单的ID传递给PayPal,并在Payment.Execute()中接收其值,以便知道付款的关联顺序。

    有可能吗?非常感谢。

1 个答案:

答案 0 :(得分:1)

基于SDK和API帮助页面,我将利用您要发送到invoice_number端点的事务中的Payments.Create()属性。此交易将成为PayPal回复的一部分,这意味着您可以从API获取OrderNumber(现在称为invoice_number)。

找到以下这一行:invoice_number = YOUR_ORDER_NUMBER

您的PayPal请求:(taken from SDK Samples

        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(Taken From Here)的回复:

enter image description here