简体   繁体   中英

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

I'm trying to figure out the Paypal REST API .

I have an action for the ReturnURL ( /payment/return ) and an action for the CancelUrl ( /payment/cancel ).

When I generate the Payment: 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. When the user is done, Paypal sends back an approved Payment object (JSON).

I am trying to get my hands on that JSON in the return action so it will bind to the Payment object.

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?

just to read json there are many ways to do this but if you do not want to bind you can use dynamic

   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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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