/// <summary>
        /// Sets from payment information.
        /// </summary>
        /// <param name="paymentInfo">The payment information.</param>
        /// <param name="paymentGateway">The payment gateway.</param>
        /// <param name="rockContext">The rock context.</param>
        public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext)
        {
            if (AccountNumberMasked.IsNullOrWhiteSpace() && paymentInfo.MaskedNumber.IsNotNullOrWhiteSpace())
            {
                AccountNumberMasked = paymentInfo.MaskedNumber;
            }

            if (!CurrencyTypeValueId.HasValue && paymentInfo.CurrencyTypeValue != null)
            {
                CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id;
            }

            if (!CreditCardTypeValueId.HasValue && paymentInfo.CreditCardTypeValue != null)
            {
                CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id;
            }

            if (paymentInfo is CreditCardPaymentInfo)
            {
                var ccPaymentInfo = (CreditCardPaymentInfo)paymentInfo;

                string nameOnCard  = paymentGateway.SplitNameOnCard ? ccPaymentInfo.NameOnCard + " " + ccPaymentInfo.LastNameOnCard : ccPaymentInfo.NameOnCard;
                var    newLocation = new LocationService(rockContext).Get(
                    ccPaymentInfo.BillingStreet1, ccPaymentInfo.BillingStreet2, ccPaymentInfo.BillingCity, ccPaymentInfo.BillingState, ccPaymentInfo.BillingPostalCode, ccPaymentInfo.BillingCountry);

                if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace())
                {
                    NameOnCardEncrypted = Encryption.EncryptString(nameOnCard);
                }

                if (!ExpirationMonth.HasValue)
                {
                    ExpirationMonthEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Month.ToString());
                }

                if (!ExpirationYear.HasValue)
                {
                    ExpirationYearEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Year.ToString());
                }

                if (!BillingLocationId.HasValue && newLocation != null)
                {
                    BillingLocationId = newLocation.Id;
                }
            }
            else if (paymentInfo is SwipePaymentInfo)
            {
                var swipePaymentInfo = (SwipePaymentInfo)paymentInfo;

                if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace())
                {
                    NameOnCardEncrypted = Encryption.EncryptString(swipePaymentInfo.NameOnCard);
                }

                if (!ExpirationMonth.HasValue)
                {
                    ExpirationMonthEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Month.ToString());
                }

                if (!ExpirationYear.HasValue)
                {
                    ExpirationYearEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Year.ToString());
                }
            }
            else
            {
                var newLocation = new LocationService(rockContext).Get(
                    paymentInfo.Street1, paymentInfo.Street2, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode, paymentInfo.Country);

                if (!BillingLocationId.HasValue && newLocation != null)
                {
                    BillingLocationId = newLocation.Id;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Sets any payment information that the <seealso cref="GatewayComponent">paymentGateway</seealso> didn't set
        /// </summary>
        /// <param name="paymentInfo">The payment information.</param>
        /// <param name="paymentGateway">The payment gateway.</param>
        /// <param name="rockContext">The rock context.</param>
        public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext)
        {
            /* 2020-08-27 MDP
             * This method should only update values haven't been set yet. So
             *  1) Make sure paymentInfo has the data (isn't null or whitespace)
             *  2) Don't overwrite data in this (FinancialPaymentDetail) that already has the data set.
             */

            if (AccountNumberMasked.IsNullOrWhiteSpace() && paymentInfo.MaskedNumber.IsNotNullOrWhiteSpace())
            {
                AccountNumberMasked = paymentInfo.MaskedNumber;
            }

            if (paymentInfo is ReferencePaymentInfo referencePaymentInfo)
            {
                if (GatewayPersonIdentifier.IsNullOrWhiteSpace())
                {
                    GatewayPersonIdentifier = referencePaymentInfo.GatewayPersonIdentifier;
                }

                if (!FinancialPersonSavedAccountId.HasValue)
                {
                    FinancialPersonSavedAccountId = referencePaymentInfo.FinancialPersonSavedAccountId;
                }
            }

            if (!CurrencyTypeValueId.HasValue && paymentInfo.CurrencyTypeValue != null)
            {
                CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id;
            }

            if (!CreditCardTypeValueId.HasValue && paymentInfo.CreditCardTypeValue != null)
            {
                CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id;
            }

            if (paymentInfo is CreditCardPaymentInfo)
            {
                var ccPaymentInfo = ( CreditCardPaymentInfo )paymentInfo;

                string nameOnCard  = paymentGateway.SplitNameOnCard ? ccPaymentInfo.NameOnCard + " " + ccPaymentInfo.LastNameOnCard : ccPaymentInfo.NameOnCard;
                var    newLocation = new LocationService(rockContext).Get(
                    ccPaymentInfo.BillingStreet1, ccPaymentInfo.BillingStreet2, ccPaymentInfo.BillingCity, ccPaymentInfo.BillingState, ccPaymentInfo.BillingPostalCode, ccPaymentInfo.BillingCountry);

                if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace())
                {
                    NameOnCardEncrypted = Encryption.EncryptString(nameOnCard);
                }

                if (!ExpirationMonth.HasValue)
                {
                    ExpirationMonthEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Month.ToString());
                }

                if (!ExpirationYear.HasValue)
                {
                    ExpirationYearEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Year.ToString());
                }

                if (!BillingLocationId.HasValue && newLocation != null)
                {
                    BillingLocationId = newLocation.Id;
                }
            }
            else if (paymentInfo is SwipePaymentInfo)
            {
                var swipePaymentInfo = ( SwipePaymentInfo )paymentInfo;

                if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace())
                {
                    NameOnCardEncrypted = Encryption.EncryptString(swipePaymentInfo.NameOnCard);
                }

                if (!ExpirationMonth.HasValue)
                {
                    ExpirationMonthEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Month.ToString());
                }

                if (!ExpirationYear.HasValue)
                {
                    ExpirationYearEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Year.ToString());
                }
            }
            else
            {
                var newLocation = new LocationService(rockContext).Get(
                    paymentInfo.Street1, paymentInfo.Street2, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode, paymentInfo.Country);

                if (!BillingLocationId.HasValue && newLocation != null)
                {
                    BillingLocationId = newLocation.Id;
                }
            }
        }