protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (UseFieldName)
            {
                ErrorMessage = $"{validationContext.DisplayName} {ErrorMessageString}";
            }
            else
            {
                ErrorMessage = ErrorMessageString;
            }

            string accountNumber = (string)value;

            System.Reflection.PropertyInfo otherFieldProperty = validationContext.ObjectType.GetProperty(FieldToValidate);

            if (null == otherFieldProperty)
            {
                return(new ValidationResult($"Unknown property: {FieldToValidate}"));
            }

            Enums.PaymentTypes otherField = (Enums.PaymentTypes)otherFieldProperty.GetValue(validationContext.ObjectInstance, null);

            switch (FieldToValidate)
            {
            case "ShippingPaymentType":
                if (otherField != Enums.PaymentTypes.Shipper &&
                    string.IsNullOrWhiteSpace(accountNumber))
                {
                    return(new ValidationResult(ErrorMessage));
                }
                break;
            }

            return(ValidationResult.Success);
        }
コード例 #2
0
        public Billing(string shipperAccountNumber, Enums.PaymentTypes paymentType, string billingAccountNumber = "")
        {
            this.ShipperAccountNumber = shipperAccountNumber;
            this.ShippingPaymentType  = paymentType;

            if (string.IsNullOrWhiteSpace(billingAccountNumber))
            {
                this.BillingAccountNumber = this.ShipperAccountNumber;
            }
        }
コード例 #3
0
        /// <summary>
        /// Extend functionality of PaymentTypes enum
        /// </summary>
        /// <param name="paymentType">PaymentTypes enum</param>
        /// <returns>Value definition in Description attribute</returns>
        public static string GetValueAsString(this Enums.PaymentTypes paymentType)
        {
            // get the field
            var field            = paymentType.GetType().GetField(paymentType.ToString());
            var customAttributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (customAttributes.Length > 0)
            {
                return((customAttributes[0] as DescriptionAttribute).Description);
            }
            else
            {
                return(paymentType.ToString());
            }
        }
コード例 #4
0
        /// <summary>
        /// Set a payment
        /// </summary>
        /// <param name="paymentType">Payment Type</param>
        /// <param name="payerId">Payment Token</param>
        public void SetPayment(Enums.PaymentTypes paymentType, string payerId)
        {
            switch (paymentType)
            {
            case Enums.PaymentTypes.Apple:
                this.SetApplePayment(payerId);
                break;

            case Enums.PaymentTypes.Blml:
                this.SetBillMeLaterPayment(payerId);
                break;

            case Enums.PaymentTypes.Bpay:
                this.SetBpayPayment(payerId);
                break;

            case Enums.PaymentTypes.Card:
                this.SetCardPayment(payerId);
                break;

            case Enums.PaymentTypes.CarteBleue:
                this.SetCarteBleuePayment(payerId);
                break;

            case Enums.PaymentTypes.Check:
                this.SetCheckPayment(payerId);
                break;

            case Enums.PaymentTypes.Elv:
                this.SetElvPayment(payerId);
                break;

            case Enums.PaymentTypes.GreenDotMoneyPak:
                this.SetGreenDotMoneyPakPayment(payerId);
                break;

            case Enums.PaymentTypes.GiftCard:
                this.SetGiftCardPayment(payerId);
                break;

            case Enums.PaymentTypes.GiroPay:
                this.SetGiroPayPayment(payerId);
                break;

            case Enums.PaymentTypes.Google:
                this.SetGooglePayment(payerId);
                break;

            case Enums.PaymentTypes.Interac:
                this.SetInteracPayment(payerId);
                break;

            case Enums.PaymentTypes.MercadePago:
                this.SetMercadePagoPayment(payerId);
                break;

            case Enums.PaymentTypes.Neteller:
                this.SetNetellerPayment(payerId);
                break;

            case Enums.PaymentTypes.None:
                this.SetNoPayment();
                break;

            case Enums.PaymentTypes.Poli:
                this.SetPoliPayment(payerId);
                break;

            case Enums.PaymentTypes.Paypal:
                this.SetPaypalPayment(payerId);
                break;

            case Enums.PaymentTypes.SingleEuroPaymentsArea:
                this.SetSepaPayment(payerId);
                break;

            case Enums.PaymentTypes.Skrill:
                this.SetSkrillPayment(payerId);
                break;

            case Enums.PaymentTypes.Sofort:
                this.SetSofortPayment(payerId);
                break;

            case Enums.PaymentTypes.Token:
                this.SetTokenPayment(payerId);
                break;

            default:
                throw new RequestException($"ERROR: such payment type not exist: {paymentType.ToString()}");
            }
        }