C# Integration, not redirecting to paynow


#1

Hi, i am facing a issue when sending payment request from c#. Browser keep loading and not redirecting to paynow. It was successfully running some days ago and suddenly stop working.

public static string CreatePaynowPayment(int appID, string pType)
{
string apikey = “xxxxxx”;
string apiCode = “22156”;
var paynow = new Paynow(apiCode, apikey);
if (pType == “web”)
{
paynow.ResultUrl = baseUrl;
paynow.ReturnUrl = baseUrl + “TradespersonAccount/PaymentSuccess?qid=” + appID + “&ptype=” + pType;
}
else if (pType == “app”)
{
paynow.ResultUrl = baseUrl;
paynow.ReturnUrl = baseUrl + “TradespersonApp/Home/PaymentSuccess?qid=” + appID + “&ptype=” + pType;
}
var payment = paynow.CreatePayment(“Invoice_” + appID,"info@mydomain.com");
float fee = getTradespersonFee();
payment.Add(“Platform Fee”, fee);
var response = paynow.Send(payment);

if (response.Success())
{
    var link = response.RedirectLink();
    var pollUrl = response.PollUrl();

    string result = link + "," + pollUrl;

    return result;
}
return "failed";

}

Not getting any response on calling of var response = paynow.Send(payment);


#2

Good day @csmenaria

If the transaction is not redirecting, the first thing you should check is whether the initiation request was actually successful(which you are already doing).

In the .NET SDK, you must check response.Success() before trying to redirect. If it returns false, Paynow will return the error inside the Data object under the “Error” key.

Here is how you can retrieve it:

var response = paynow.Send(payment);

if (response.Success())
{
    // Redirect user
    Response.Redirect(response.RedirectLink());
}
else
{
    // Get error from Data object
    string errorMessage = response.Data != null && response.Data.ContainsKey("Error")
        ? response.Data["Error"]?.ToString()
        : "Unknown error occurred";

    Console.WriteLine("Paynow initiation failed: " + errorMessage);
}