asp.net-mvc – Paypal REST API – 在付款过程中传递参数

我正在使用Paypal的.NET SDK将Paypal直接支付集成到我的ASP.NET MVC 5项目中.以下是步骤:

>我打电话给PayPal.Api.Payment.Create(APIContext)重定向到Paypal网站,成功的网址;
>在与成功URL对应的回调操作中,调用PayPal.Api.Payment.Execute(APIContext,ExecutionContext).

我需要的是在调用Payment.Create()时将新订单的ID传递给Paypal,并在Payment.Execute()中接收其值,以便它可以知道付款与哪个订单相关联.

可能吗?非常感谢.

最佳答案 基于SDK和API帮助页面,我将利用您要发送到Payments.Create()端点的Transaction中的invoice_number属性.此事务将成为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)的回应:

《asp.net-mvc – Paypal REST API – 在付款过程中传递参数》

点赞