Esempio n. 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            var incoming     = JObject.Load(reader);
            var sourceAction = new PaymentIntentSourceAction();

            // Parse type
            var typeString = incoming.SelectToken("type")?.ToString();
            PaymentIntentSourceActionType type;

            if (!TryParseEnum <PaymentIntentSourceActionType>(typeString, out type))
            {
                type = PaymentIntentSourceActionType.Unknown;
            }

            sourceAction.Type = type;

            // Parse value according to type
            if (this.TypesToMapperFuncs.ContainsKey(type))
            {
                var mapperFunc  = this.TypesToMapperFuncs[type];
                var valueString = incoming.SelectToken("value")?.ToString();
                sourceAction.Value = mapperFunc(valueString);
            }
            else
            {
                sourceAction.Value = null;
            }

            return(sourceAction);
        }
Esempio n. 2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var sourceAction = new PaymentIntentSourceAction();

            if (reader.TokenType == JsonToken.Null)
            {
                sourceAction.Type = PaymentIntentSourceActionType.None;
                return(sourceAction);
            }

            var incoming = JObject.Load(reader);

            if (incoming.SelectToken("type")?.ToString() == "authorize_with_url")
            {
                sourceAction.Type             = PaymentIntentSourceActionType.AuthorizeWithUrl;
                sourceAction.AuthorizeWithUrl = Mapper <PaymentIntentSourceActionAuthorizeWithUrl> .MapFromJson(incoming.SelectToken("value")?.ToString());
            }
            else
            {
                sourceAction.Type = PaymentIntentSourceActionType.Unknown;
            }

            return(sourceAction);
        }