public async Task ExecuteAsync(
            UserId userId,
            string paymentOriginKey,
            PaymentOriginKeyType paymentOriginKeyType,
            ValidCountryCode billingCountryCode,
            ValidCreditCardPrefix creditCardPrefix,
            ValidIpAddress ipAddress)
        {
            userId.AssertNotNull("userId");

            // The credit card has changed so the original transaction key can no longer be used for tax purposes
            // as it is based on the original card prefix.
            var origin = new UserPaymentOrigin(
                userId.Value,
                null,
                paymentOriginKey,
                paymentOriginKeyType,
                billingCountryCode == null ? null : billingCountryCode.Value,
                creditCardPrefix == null ? null : creditCardPrefix.Value,
                ipAddress == null ? null : ipAddress.Value,
                null,
                default(PaymentStatus));

            using (var connection = this.connectionFactory.CreateConnection())
            {
                await connection.UpsertAsync(
                    origin,
                    UserPaymentOrigin.Fields.PaymentOriginKey
                    | UserPaymentOrigin.Fields.PaymentOriginKeyType
                    | UserPaymentOrigin.Fields.CountryCode
                    | UserPaymentOrigin.Fields.CreditCardPrefix
                    | UserPaymentOrigin.Fields.IpAddress
                    | UserPaymentOrigin.Fields.OriginalTaxamoTransactionKey);
            }
        }
예제 #2
0
        public static bool TryParse(string value, out ValidCountryCode parsedValue, out IReadOnlyCollection <string> errorMessages)
        {
            var errorMessageList = new List <string>();

            errorMessages = errorMessageList;

            if (IsEmpty(value))
            {
                // TryParse should never fail, so report null as an error instead of ArgumentNullException.
                errorMessageList.Add("Value required");
            }
            else
            {
                value = value.Trim().ToUpperInvariant();

                if (value.Length < MinLength || value.Length > MaxLength)
                {
                    errorMessageList.Add(string.Format("Length must be from {0} to {1} characters", MinLength, MaxLength));
                }

                if (value.Any(v => !char.IsLetter(v)))
                {
                    errorMessageList.Add("Invalid format");
                }
            }

            if (errorMessageList.Count > 0)
            {
                parsedValue = null;
                return(false);
            }

            parsedValue = new ValidCountryCode
            {
                Value = value
            };

            return(true);
        }
예제 #3
0
        public static bool TryParse(string value, out ValidCountryCode parsedValue)
        {
            IReadOnlyCollection <string> errorMessages;

            return(TryParse(value, out parsedValue, out errorMessages));
        }