System.FormatException: The input string '2.00' was not in a correct format from PollTransaction()


#1

I am able to initiate a transaction fine by using the below code:

var invoiceNumber = Random.Shared.Next(1, 1001);
        paynow.Instance.ResultUrl = $"http://domain.com/return?invoice={hashids.Encode(invoiceNumber)}";
        var dict = new Dictionary<string,decimal>();
        dict.Add("Bananas", 1);
        dict.Add("Apples", 1);
        var payment = paynow.Instance.CreatePayment($"Invoice-{hashids.Encode(invoiceNumber)}",
            dict,"email@address.domain");
        var response = await paynow.Instance.SendAsync(payment);

However, when I try to poll for the transaction I get an exception that says:

System.FormatException: The input string '2.00' was not in a correct format

I am polling for the transaction like this:

if (response.Success())
        {
            // Get the url to redirect the user to so they can make payment
            var link = response.RedirectLink();
            // Get the poll url of the transaction
            var pollUrl = response.PollUrl();
            var list = new List<string>();
            list.Add(pollUrl);
            list.Add(link);

            try
            {
                var pollResponse = await paynow.Instance.PollTransactionAsync(pollUrl);
            }
            catch (Exception ex)
            {
                // ignored
            }
            return Results.Ok(list);
        }

I have even setup a separate endpoint to poll the transaction and it gets the same error.

Am I using the wrong method to initiate the transaction?
Is this polling endpoint deprecated?
I took these snippets step by step following the integration documentation from the .Net SDK in the PayNow docs.

If anyone knows any work-arounds or a way to do this better please let me know.


#2

Good day. Can you please share your Paynow Integration ID with us on our WhatsApp support number +263 719 900 809 so that we can look into the issue.

Please do not share the Integration ID here on a public forum


#3

Good day @steve

Please follow the guide below, log and share the response you get from Paynow


#4

Hi @elphas

Since this issue was caused by Decimal Culture on my local machine, a way to work around this is to set the culture in the project to expect decimals with a . (dot) and not with a , (comma).

So the fix can be either changing the culture in your system setting from Europe or South Africa or whatever its set to, to US and restarting your machine or if its a server where you may not be able to do this you can configure this at a project level as follows:

var builder = WebApplication.CreateBuilder(args);
var culture = new CultureInfo("en-US");
var supportedCultures = new[] { culture };

``rest of setup code``

var app = builder.Build();

app.UseRequestLocalization(new RequestLocalizationOptions
{
    DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture(culture),
    SupportedCultures = supportedCultures,
    SupportedUICultures = supportedCultures
});

To test that your project now expects . (dots) for decimals and not , (commas) you can do the following anywhere in the code:

Console.WriteLine(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); 

This should print a . (dot) and not a , (comma).

These 2 solutions have worked for me so far, although this decimal issue I believe has already been patched by the PayNow team but its always good to document different solutions to a problem incase it comes back again.

Thanks for your help @elphas & @Tapiwa263


#5

Thank you, @steve

That’s useful information. Have a great day.