# Problem with signature

**URL:** <https://community.rapyd.net/t/problem-with-signature/195>\
**Category:** ⚙️ API\
**Created:** [April 30, 2021, 3:06pm UTC](https://community.rapyd.net/t/problem-with-signature/195 "2021-04-30T15:06:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![onesoft](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rapyd.net/onesoft/32/832_2.png) [@onesoft](https://community.rapyd.net/u/onesoft)\
**Post date:** [April 30, 2021, 3:06pm UTC](https://community.rapyd.net/t/problem-with-signature/195/1 "2021-04-30T15:06:10Z")

</div>

Hi,

I’m trying to make my first API call - or second to first, as I don’t have any problems getting the countries list.

As soon as my httpbody isn’t empty, I’m getting UNAUTHENTICATED\_API\_CALL ,“message”:“Invalid signature”

I’m calling /v1/checkout

I’m using C# (4.7.2) and using Newtonsoft.Json to sterilize my request class, like this:

```
private static string SerializeBody(object from)
        {
            return from != null ? JsonConvert.SerializeObject(
                    from,
                    Formatting.None,
                    new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                    }
                ) : string.Empty;
        }

```

Ending out with a string looking as this:

{“amount”:4130.00,“complete\_payment\_url”:“[http://oneshop.local/da-DK/gateway/Retur/Ok/649687b8-3308-420c-a0ff-c0b71c87ec74",“cancel\_checkout\_url”:“http://oneshop.local/da-DK/Checkout/Status/649687b8-3308-420c-a0ff-c0b71c87ec74”,“country”:“DK”,“currency”:"DKK](http://oneshop.local/da-DK/gateway/Retur/Ok/649687b8-3308-420c-a0ff-c0b71c87ec74%22,%22cancel_checkout_url%22:%22http://oneshop.local/da-DK/Checkout/Status/649687b8-3308-420c-a0ff-c0b71c87ec74%22,%22country%22:%22DK%22,%22currency%22:%22DKK)”}

I’m pretty sure its the body serialization that is the problem as I have tried to make the same call to /v1/checkout with an empty body, and then I’m getting a MISSING\_FIELDS - [COUNTRY] error

Does anybody have a suggestion as to what I’m doing wrong with the http-body

---

<div class="post-metadata">

**Author:** ![onesoft](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rapyd.net/onesoft/32/832_2.png) [@onesoft](https://community.rapyd.net/u/onesoft)\
**Post date:** [April 30, 2021, 6:53pm UTC](https://community.rapyd.net/t/problem-with-signature/195/2 "2021-04-30T18:53:19Z")

</div>

I have found the problem, the amount is serialized with decimales when it’s an integer

> [@onesoft](#):
>
> {“amount”:4130.00

When the amount is changed to 4130 the request is accepted.

---

<div class="post-metadata">

**Author:** ![drew.harris](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rapyd.net/drew.harris/32/1259_2.png) [@drew.harris](https://community.rapyd.net/u/drew.harris)\
**Post date:** [April 30, 2021, 6:57pm UTC](https://community.rapyd.net/t/problem-with-signature/195/3 "2021-04-30T18:57:54Z")

</div>

Thank you @onesoft for posting your question and solution. 👍

---

<div class="post-metadata">

**Author:** ![onesoft](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rapyd.net/onesoft/32/832_2.png) [@onesoft](https://community.rapyd.net/u/onesoft)\
**Post date:** [May 1, 2021, 2:17am UTC](https://community.rapyd.net/t/problem-with-signature/195/4 "2021-05-01T02:17:56Z")

</div>

This was a fun challenge 😒

Here is my current solution for c#:

RoundedCurrencyAmount to hold the amount and take care of the rounding

```
public class RoundedCurrencyAmount
{
    private static readonly string[] _threeDigitsCurrencies = {"BHD", "IQD", "JOD", "KWD", "LYD", "OMR", "TND"};
    private static readonly string[] _fourDigitsCurrencies = { "CLF", "UYW"};

    private readonly decimal _amountTotal;

    public RoundedCurrencyAmount(decimal amountTotal, string currencyIsoCode)
    {
        CurrencyIsoCode = currencyIsoCode;
        _amountTotal = amountTotal;
    }

    public string CurrencyIsoCode { get; private set; }

    [Localizable(false)]
    public override string ToString()
    {
        if (_amountTotal % 1 == 0)
            return _amountTotal.ToString("F0", CultureInfo.InvariantCulture);

        if(_threeDigitsCurrencies.Contains(CurrencyIsoCode))
            return _amountTotal.ToString("F3", CultureInfo.InvariantCulture);

        if (_fourDigitsCurrencies.Contains(CurrencyIsoCode))
            return _amountTotal.ToString("F4", CultureInfo.InvariantCulture);

        return _amountTotal.ToString("F2", CultureInfo.InvariantCulture);
    }
}

```

The request class:

```
public class RapydCreateCheckoutPageRequest
{
    public RapydCreateCheckoutPageRequest(decimal amountTotal, string currencyCode)
    {
        Amount = new RoundedCurrencyAmount(amountTotal, currencyCode);
    }

    /// <summary>
    /// The amount of the payment, in units of the currency defined in currency. 
    /// Decimal, including the correct number of decimal places for the currency exponent, as defined in ISO 4217:2015. 
    /// If the amount is a whole number, use an integer and not a decimal
    /// </summary>
    [JsonProperty(@"amount")]
    public RoundedCurrencyAmount Amount { get; }
  ....
}

```

For serialization with newtonsoft:

```
class RoundedCurrencyAmountJsonConverter : JsonConverter
{
    public override bool CanRead => false;

    public override object ReadJson(
           JsonReader reader, 
           Type objectType, 
            object existingValue, 
            JsonSerializer serializer)
    {
        throw new NotImplementedException();
    }

    public override bool CanConvert(Type objectType)
    {
        return objectType == typeof(RoundedCurrencyAmount);
    }

    public override void WriteJson(
                   JsonWriter writer, object value, JsonSerializer serializer)
    {
        var item = (RoundedCurrencyAmount)value;
        writer.WriteRawValue(item.ToString());
    }
}

```

and finally the updated sterilizeBody function:

```
private static string SerializeBody(object from)
{
    var s = from as string;
    if(s != null)
        return s;

    return from != null ? JsonConvert.SerializeObject(
            from,
            Formatting.None,
                
            new JsonSerializerSettings
            {
                Converters = new List<JsonConverter> { new RoundedCurrencyAmountJsonConverter()},
                NullValueHandling = NullValueHandling.Ignore,
            }
        ) : string.Empty;
    }
```
