Beispiel #1
0
        public string GetMerchantParameters(PaymentRequest paymentRequest)
        {
            //var settings = new JsonSerializerSettings
            //{
            //    DefaultValueHandling = DefaultValueHandling.Ignore,
            //    NullValueHandling = NullValueHandling.Ignore,
            //    Context = new StreamingContext(StreamingContextStates.All, paymentRequest.Ds_Merchant_Currency)
            //};
            //string json = JsonConvert.SerializeObject(paymentRequest, Formatting.Indented, settings);
            //return Base64.EncodeUtf8To64(json);

            var options = new JsonSerializerOptions
            {
                DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
                WriteIndented          = true
            };

            PaymentRequest copyRequest = paymentRequest.Clone();

            int truncate  = (int)Math.Truncate(copyRequest.Ds_Merchant_Amount);
            int remainder = (int)Math.Truncate((copyRequest.Ds_Merchant_Amount - truncate) * 100);
            int amount;

            if (copyRequest.Ds_Merchant_Currency == Currency.JPY)
            {
                amount = truncate;
            }
            else
            {
                amount = truncate * 100 + remainder;
            }
            copyRequest.Ds_Merchant_Amount = amount;

            string json = JsonSerializer.Serialize(copyRequest, options);

            return(Base64.EncodeUtf8To64(json));
        }