How create request and redirect client to payment gateway master card in C# using ASP.NET MVC 5?

Viewed 253

This may be code I tried.

I am trying to redirect the client to the payment gateway after payment is done it returns back by return URL.

But I did not figure out how:

[HttpPost]
public ActionResult PaymentGateway()
{
    var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://abc.gateway.mastercard.com/api/rest/version/6/merchant/xxx/order/1/transaction/1");
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;

    string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("xxxx:xxxx"));

    httpWebRequest.Headers.Add("Authorization", "Basic " + credentials);
    httpWebRequest.ContentType = "application/json";
    httpWebRequest.Method = "POST";

    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        string json = "{\"apiOperation\":\"CAPTURE\"," +
                              "\"order.amount\":\"100.000\"}" +
                              "\"order.currency\":\"USD\"}" +
                              "\"browserPayment.redirectUrl\":\"https:\\example.com\callback\"}";

        streamWriter.Write(json);
    }

    // how send request ?
    return ??? ;
}
1 Answers

I implemented a project that only did the purchasing work and then was redirected to another app for payment, and then redirect to the main app after the payment was completed.

You can separate the payment and purchase application

Related