微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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)的回应:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐