简体   繁体   English

如何处理来自远程REST API(Paypal)的响应?

[英]How do I process a response from a remote REST API (Paypal)?

I'm trying to figure out the Paypal REST API . 我正在尝试找出Paypal REST API

I have an action for the ReturnURL ( /payment/return ) and an action for the CancelUrl ( /payment/cancel ). 我对ReturnURL( /payment/return )有一个操作,对CancelUrl( /payment/cancel )有一个操作。

When I generate the Payment: Payment createdPayment = pymnt.Create(this.accessToken); 当我生成付款时: Payment createdPayment = pymnt.Create(this.accessToken);

I get the approved_url which I need to redirect for my user so he/she can make the actual Paypal Payment. 我得到的approved_url ,我需要为我的用户重定向这样他/她可以使实际的Paypal支付。 When the user is done, Paypal sends back an approved Payment object (JSON). 完成用户操作后,Paypal将发回批准的Payment对象(JSON)。

I am trying to get my hands on that JSON in the return action so it will bind to the Payment object. 我正在尝试在return操作中使用该JSON,因此它将绑定到Payment对象。

This does not work: 这不起作用:

public ActionResult Return(Payment payment)
{
    payerId = Request.Params["PayerID"];
    var paymentId = payment.id; // NullException
    var result = paypalService.ExecutePayment(paymentId, payerId);
    return this.View();
}

How do I bind the response JSON? 如何绑定响应JSON?

just to read json there are many ways to do this but if you do not want to bind you can use dynamic 只是阅读json有很多方法可以做到这一点,但是如果您不想绑定,则可以使用动态

   dynamic reply= JsonConvert.DeserializeObject(jsonstring)

also take a look at this 也看看这个

http://www.masnun.com/2011/07/08/quick-json-parsing-with-c-sharp.html http://www.masnun.com/2011/07/08/quick-json-parsing-with-c-sharp.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM