Razorpay CallBack_URL on Failure C# MVC - c#

Razorpay Payment Gateway integration in asp.net MVC.
I am not getting error code in my callback Url on payment failure.
On sucess I am getting razorpay_payment_id ,razorpay_order_id and razorpay_signature . But on failure the not receive the error array as expected. Please let me know if I am missing something and the documentation on callback URL is not much of help
I have set the parameter Redirect : true
[HttpPost]
public ActionResult VerifyPayment(string razorpay_payment_id, string razorpay_order_id, string razorpay_signature,string [] error)

Related

Read the URL parameter which is set after the hash symbol using ASP.NET Core MVC

Let's say we have a controller like this:
public class HomeController : Controller
{
[HttpGet]
public IActionResult Foo(string token)
{
return RedirectToAction(nameof(Index));
}
}
When I type the following URL address in the webbrowser:
https://localhost:44348/home/foo#dsfdsf
I would like to be able to read the dsfdsf after the hash symbol and bind it to the token variable.
Now I'm receiving null value. I'm getting such URL from the 3rd party app and I need to consume the response somehow and read the data from the query string.
I played with [FromQuery] attribute but I haven't managed it to work so far.
Any ideas?
Cheers
I have a work around for you, but first of all lets get more into the problem.
The strings after the hash symbol which are called Fragment values are not query parameters but they are strings to be read by the client-side (living in the browser) and the server cannot read them because they are not sent to the server by the browser.
Some authentication providers like Google and Azure send the access token as Fragment value for security reasons so that they are not transferred over the internet after they get sent as direct response from the authentication provider.
The only way you can come around that is to use javascript to convert the fragment values to query parameters by replacing the '#' with '?' and redirecting to the endpoint in your server controller.
I suppose the easiest way is to handle all that from server, meaning you get get the request in server, send a javascript code to the browser on the fly, that replaces the '#' into '?' and redirects to your second endpoint which reads the token as strong parameter.
Here how you can do it in ASP.NET Core 3.1:
[AllowAnonymous]
[HttpGet("authredirect")]
[Produces("text/html")]
public virtual ContentResult ConvertUrlFragmentToQueryParamThenRedirect()
{
return Content("<html><script>window.location.href=window.location.href.replace('#', '?').replace('authredirect', 'authparams')</script></html>", "text/html");
}
[AllowAnonymous]
[HttpGet("authparams")]
public virtual void GetAccessToken([FromQuery] string access_token)
{
// now you have your access token server side here
}
Please remember to set your redirectUrl to the correct one, in this case 'YOUR REDIRECT URL/authredirect'.

How to verify Slack Events API Request Url in ASP.Net Core Mvc application?

I'm working on Slack integration in an ASP.Net Core MVC 2 application.
I have done it for Searching and Posting messages to Slack channels. Now I'm stuck at integrating Events API in this application. Basically, at the moment I'm not able to verify my Request Url as mentioned here Events API Subscription
Following is my action method that we have give to Slack where they will send the verification json object which will be mapped to request parameter of my action and is as follows:
{
"token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
"challenge": "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P",
"type": "url_verification"
}
[HttpPost]
public IActionResult Event(EventsRequest request)
{
if (request != null)
{
if (request.type.Equals("url_verification"))
return Content(request.challenge);
else
ViewBag.Challenge = request.challenge;
}
return View();
}
Here is my EventsRequest class:
public class EventsRequest
{
public string token { get; set; }
public string challenge { get; set; }
public string type { get; set; }
}
I have deployed this application locally on IIS and have applied InBound rules to make it accessible publicly and it is accessible. But issues arise when I give the following URL to Slack for verification:
http://IP_Address/Slack/Event
Following is the screenshot of the response that Slack gives
Can someone tell what's wrong here? I tried to hit this URL with Postman and I was able to get the desired results.
You can try these:
As suggested in https://api.slack.com/events-api#subscriptions
Your Event Request URL must be confirmed before saving this form. If
your server takes some time to "wake up" and your initial attempt at
URL verification fails due to a timeout, use the retry button to
attempt verification again.
If it fails at first attempt make sure server is up & running and try next time.
After you've completed typing your URL, we'll dispatch a HTTP POST to
your request URL. We'll verify your SSL certificate and we'll send a
application/json POST body containing three fields:
{
"token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
"challenge": "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P",
"type": "url_verification"
}
You need to replace example json with the real values generated for you url configuration and verification.
Make sure url for verification is set correctly before generating challenge and is not changed afterwards.
Make sure no mismatch in url scheme like http in one place and https at other.
Try adding from body in post request:
[HttpPost]
public IActionResult Event([FromBody]EventsRequest request)

asp.net MVC controller - What should controller return if user is unauthorized?

So I have this code inside the controller of my MVC for a page
[HttpGet, Route]
[Authorize(nameof(Access))]
public async Task<ActionResult> ListStuff()
{
var canRead = HasAccess()
if(!canRead)
{
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
}
I'm using C# attributes for security validation and what I want is if the attribute with the 'HasAccess()' function returns false then the page show show an 'unauthorized' error, as you guys can see I tried throwing an HttpResponseException, I'm pretty sure this isn't the proper way to do it. Any suggestions?
You send a GET http request to your running service, eg:http://localhost:8080/Myservice.svc/$metadata. I've used postman in the past to help with sending http requests.
Link to free postman

ccavenue get payment status from response url

I am using iframe approach in a .net mvc app and we are setting one return url while sending the request.
My question is how can i know the payment status & ccavenue payment reference no and other payment related params from response url
My retun url action is something like this
[HttpGet]
public ActionResult ResponseCCPayment()
{
//but how to read reposne params from here
return Content("got response frm ccveue");
}
From CCAvenue documentation i can see
redirect_url CCAvenue will post the status of the order along with the parameters to this URL
But no details on what parameters. Can someone help to get this
Login to the merchant account. There you have an option to download the relevant documents about the returned parameters list. (Merchant Account : https://login.ccavenue.com/jsp/merchant/merchantLogin.jsp)
In the Merchant Account you can configure a url to which a asynchronous response will be sent when a customer has made a payment. In this asynchronous response, you can get those payment related info.
There is also a separate REST api method, that takes the order id as argument and return payment related details.
Hope this helps.

What would cause a MVC4 controller to only return a status code and no partial view?

This is sort of an odd question but then I have a very odd situation. On my development server (IIS & IIS Express) I make a ajax request and return a form. The user then posts the form back via an ajax post and if there are any validation errors the controller sends back the partial view with a response code of 400. In my ajax method I intercept any 400 errors and redisplay the form with the validation errors.
My problem is that when I upload my app to my production server all I get on a validation error is the 400 response with no partial view. I don't know even where to begin? Here is what I have tried, what libraries I am using, and some sample code.
ASP.net MVC4,
Fluent Validation,
jQuery, unobtrusive validation, malsup-ajaxsubmit
On my production server...
My partial view that loads the form works as expected. This tells me that the application is having no problem finding my view as the same view is redisplayed if validation fails.
My controller using fluent validation is correctly detecting a model state error and responding with a 400 (just no view with it).
My ajax post using ajaxsubmit is posting to the server correctly using ajax.
Using firebug I step through my ajax method and an 400 error is indeed returned but the only content on xhr.responseText is "Bad Request". NO partial view. Again my development machine works perfectly.
Here is some code.
My Form Get Request:
public ActionResult CreateMedicalEvent(int userId)
{
var model = new EventModel { MedicalEventUserId = userId };
return PartialView("_Event.Create", model);
}
My Form Post:
[HttpPost]
public ActionResult CreateMedicalEvent(EventModel model)
{
if (!ModelState.IsValid)
{
Response.StatusCode = 400;
return PartialView("_Event.Create", model);//this does not get returned on production server
}
//the rest of my code if validation passess
}
My ajax method:
$('.se-form').ajaxForm({
delegation: true,
beforeSubmit: function() {
ajaxHelpers.modalProcess();//modal progress bar
},
success: function(data) {
$.modal.close();
//handle a successful post
},
error: function(xhr) {
$.modal.close();
if (xhr.status == 400) {
slideEdit.seObj.empty();//this is my form object
slideEdit.seObj.append(xhr.responseText);//all I get is "Bad Request" from production server
$.validator.unobtrusive.parse($('form', slideEdit.seObj));
ajaxHelpers.bindDates(); //because we need to bind event AND format date, we have to do this here
utilities.formatDecimal();
} else {
ajaxHelpers.exc(xhr);
}
}
});
I wish there was more code to post but this isn't all that complicated. Am I missing some weird dll file on my production server? Both servers have MVC4 installed. Lost. Pleas help. Thanks.
Adding to #STW 's answer, try adding to your web.config
<system.webServer>
<httpErrors errorMode=”Detailed” />
</system.webserver>
to see the IIS error response.
Also see these links for more
Understanding 400 Bad Request Exception
and ASPNET MVC IIS7 and Bad Request
A 400 indicates a bad request, meaning MVC didn't think it could handle the request being sent--the controller action won't even be invoked in this case. Try enabling detailed error output, or running the request against the site in Visual Studio and see if you can get the exception details. It could be happening in Routing, Controller construction, Action Invoking, or maybe Model Binding.
In my case, I accidentally had the PartialView.cshtml file in the wrong View directory. Moved it over to the right View directory and no more 400 bad request. Doh!

Categories