Home > Blockchain >  How can I make a return with parameters in a View c# asp .net mvc?
How can I make a return with parameters in a View c# asp .net mvc?

Time:11-16

Sorry for the title, but don't know how to explain it. (.NET ASP MVC) So what I'm trying is to create a payment request via TripleA API(redirect on their page), if the payment is successful, they will redirect on my success page with some parameters, how can I handle those parameters?

What I've tried:

public IActionResult ErrorPage(string payment_reference, string status)
        {
            return View(payment_reference,status);
        }

https://developers.triple-a.io/docs/triplea-api-doc/dd286311a5afc-make-a-payment-request (scroll down to success_url for more info)

CodePudding user response:

To expand on Steve's comment, create a record (less code than a class) as follows...

public record ErrorViewModel(string PaymentReference, string Status);

...then use this when you send data to the view...

public IActionResult ErrorPage(string payment_reference, string status)
        {
            return View(new ErrorViewModel(payment_reference,status));
        }

You'll need to update your view to have the following line at the top...

@model ErrorViewModel

That should be all you need.

CodePudding user response:

Based on the documentation, you expect a request like this,

https://www.myshop.com/payment-success?status=paid&payment_reference=ASDDF...&order_currency=USD&order_amount=10

And you translate that into a controller method,

[HttpGet("payment-success")]
public IActionResult ResultPage(string payment_reference, string status, string order_currency, decimal order_amount)
{
   var result = new ResultViewModel(payment_reference,status, order_currency, order_amount); 
   return View(result);
}

I also noticed that the doc says,

Note: This field is required if integrating using External URL Payment Form. For other integrations, either insert the field with a url, or remove the field completely.

So if you use External URL Payment Form integration, then I don't think you will be able to get the status and reference.

The same applies for cancel_url.

  • Related