예제 #1
0
        /// <summary>
        /// Handles the Click event of the btnSavePaymentInfo control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSavePaymentInfo_Click(object sender, EventArgs e)
        {
            var    accountService  = new FinancialPersonSavedAccountService();
            var    configValues    = (Dictionary <string, object>)Session["CachedMergeFields"];
            string accountNickname = txtPaymentNick.Text;
            Person person          = FindPerson();

            var account = accountService.Queryable().Where(a => a.Name == accountNickname &&
                                                           a.PersonId == person.Id).FirstOrDefault();

            if (account == null)
            {
                account = new FinancialPersonSavedAccount();
                accountService.Add(account, person.Id);
            }

            account.Name = accountNickname;
            // #TODO WITH GATEWAY CALL
            account.TransactionCode = "Unknown";

            account.PersonId            = person.Id;
            account.MaskedAccountNumber = configValues["PaymentLastFour"].ToString();

            if (!string.IsNullOrEmpty(txtCreditCard.Text))
            {
                account.PaymentMethod = PaymentMethod.CreditCard;
            }
            else if (!string.IsNullOrEmpty(txtAccountNumber.Text))
            {
                account.PaymentMethod = PaymentMethod.ACH;
            }

            accountService.Save(account, person.Id);
            divPaymentNick.Visible = false;
        }
예제 #2
0
        public void RockCleanup_Execute_ShouldUpdatePeopleWithFinancialPersonSavedAccountToAccountProtectionProfileHigh()
        {
            var personGuid = Guid.NewGuid();
            var personWithFinancialPersonBankAccount = new Person
            {
                FirstName = "Test",
                LastName  = personGuid.ToString(),
                Email     = $"{personGuid}@test.com",
                Guid      = personGuid
            };

            using (var rockContext = new RockContext())
            {
                var personService = new PersonService(rockContext);
                personService.Add(personWithFinancialPersonBankAccount);
                rockContext.SaveChanges();

                personWithFinancialPersonBankAccount = personService.Get(personWithFinancialPersonBankAccount.Id);

                var financialGateway    = new FinancialGatewayService(rockContext).Get("6432D2D2-32FF-443D-B5B3-FB6C8414C3AD".AsGuid());
                var creditCardTypeValue = DefinedTypeCache.Get(SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE.AsGuid()).DefinedValues.OrderBy(a => Guid.NewGuid()).First().Id;
                var currencyTypeValue   = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()).Id;
                var definedValueService = new DefinedValueService(rockContext);

                var financialPersonSavedAccount = new FinancialPersonSavedAccount
                {
                    Name                   = "Test Saved Account",
                    PersonAliasId          = personWithFinancialPersonBankAccount.PrimaryAliasId.Value,
                    FinancialGateway       = financialGateway,
                    FinancialPaymentDetail = new FinancialPaymentDetail
                    {
                        AccountNumberMasked = "1111",
                        CreditCardTypeValue = definedValueService.Get(creditCardTypeValue),
                        CurrencyTypeValue   = definedValueService.Get(currencyTypeValue),
                        NameOnCard          = "Test User"
                    }
                };

                var service = new FinancialPersonSavedAccountService(rockContext);
                service.Add(financialPersonSavedAccount);
                rockContext.SaveChanges();
            }

            ExecuteRockCleanupJob();

            using (var rockContext = new RockContext())
            {
                var actualPerson = new PersonService(rockContext).Get(personGuid);
                Assert.That.AreEqual(AccountProtectionProfile.High, actualPerson.AccountProtectionProfile);
            }
        }
        /// <summary>
        /// Handles the Click event of the btnSaveAccount control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void SaveNewFinancialPersonSavedAccount(FinancialScheduledTransaction financialScheduledTransaction)
        {
            var rockContext = new RockContext();

            var scheduledTransaction = this.GetFinancialScheduledTransaction(rockContext);
            var targetPerson         = scheduledTransaction.AuthorizedPersonAlias.Person;

            var financialGatewayComponent = this.FinancialGatewayComponent;
            var financialGateway          = this.FinancialGateway;

            var savedAccount = new FinancialPersonSavedAccount();

            var paymentDetail = financialScheduledTransaction.FinancialPaymentDetail;

            savedAccount.PersonAliasId           = targetPerson.PrimaryAliasId;
            savedAccount.ReferenceNumber         = paymentDetail.GatewayPersonIdentifier;
            savedAccount.Name                    = tbSaveAccount.Text;
            savedAccount.TransactionCode         = financialScheduledTransaction.TransactionCode;
            savedAccount.GatewayPersonIdentifier = paymentDetail.GatewayPersonIdentifier;
            savedAccount.FinancialGatewayId      = financialGateway.Id;
            savedAccount.FinancialPaymentDetail  = new FinancialPaymentDetail();
            savedAccount.FinancialPaymentDetail.AccountNumberMasked   = paymentDetail.AccountNumberMasked;
            savedAccount.FinancialPaymentDetail.CurrencyTypeValueId   = paymentDetail.CurrencyTypeValueId;
            savedAccount.FinancialPaymentDetail.CreditCardTypeValueId = paymentDetail.CreditCardTypeValueId;
            savedAccount.FinancialPaymentDetail.NameOnCard            = paymentDetail.NameOnCard;
            savedAccount.FinancialPaymentDetail.ExpirationMonth       = paymentDetail.ExpirationMonth;
            savedAccount.FinancialPaymentDetail.ExpirationYear        = paymentDetail.ExpirationYear;
            savedAccount.FinancialPaymentDetail.BillingLocationId     = paymentDetail.BillingLocationId;

            var savedAccountService = new FinancialPersonSavedAccountService(rockContext);

            savedAccountService.Add(savedAccount);
            rockContext.SaveChanges();

            savedAccount.FinancialPaymentDetail.FinancialPersonSavedAccountId = savedAccount.Id;
        }
예제 #4
0
        public SaveFinancialAccountFormResult SaveFinancialAccount(Guid gatewayGuid, [FromBody] SaveFinancialAccountFormArgs args)
        {
            // Validate the args
            if (args?.TransactionCode.IsNullOrWhiteSpace() != false)
            {
                return(new SaveFinancialAccountFormResult
                {
                    Title = "Sorry",
                    Detail = "The account information cannot be saved as there's not a valid transaction code to reference",
                    IsSuccess = false
                });
            }

            if (args.SavedAccountName.IsNullOrWhiteSpace())
            {
                return(new SaveFinancialAccountFormResult
                {
                    Title = "Missing Account Name",
                    Detail = "Please enter a name to use for this account",
                    IsSuccess = false
                });
            }

            var currentPerson = GetPerson();
            var isAnonymous   = currentPerson == null;

            using (var rockContext = new RockContext())
            {
                if (isAnonymous)
                {
                    if (args.Username.IsNullOrWhiteSpace() || args.Password.IsNullOrWhiteSpace())
                    {
                        return(new SaveFinancialAccountFormResult
                        {
                            Title = "Missing Information",
                            Detail = "A username and password are required when saving an account",
                            IsSuccess = false
                        });
                    }

                    var userLoginService = new UserLoginService(rockContext);

                    if (userLoginService.GetByUserName(args.Username) != null)
                    {
                        return(new SaveFinancialAccountFormResult
                        {
                            Title = "Invalid Username",
                            Detail = "The selected Username is already being used. Please select a different Username",
                            IsSuccess = false
                        });
                    }

                    if (!UserLoginService.IsPasswordValid(args.Password))
                    {
                        return(new SaveFinancialAccountFormResult
                        {
                            Title = "Invalid Password",
                            Detail = UserLoginService.FriendlyPasswordRules(),
                            IsSuccess = false
                        });
                    }
                }

                // Load the gateway from the database
                var financialGatewayService = new FinancialGatewayService(rockContext);
                var financialGateway        = financialGatewayService.Get(gatewayGuid);
                var gateway = financialGateway?.GetGatewayComponent();

                if (gateway is null)
                {
                    return(new SaveFinancialAccountFormResult
                    {
                        Title = "Invalid Gateway",
                        Detail = "Sorry, the financial gateway information is not valid.",
                        IsSuccess = false
                    });
                }

                // Load the transaction from the database
                var financialTransactionService = new FinancialTransactionService(rockContext);
                var transaction            = financialTransactionService.GetByTransactionCode(financialGateway.Id, args.TransactionCode);
                var transactionPersonAlias = transaction?.AuthorizedPersonAlias;
                var transactionPerson      = transactionPersonAlias?.Person;
                var paymentDetail          = transaction?.FinancialPaymentDetail;

                if (transactionPerson is null || paymentDetail is null)
                {
                    return(new SaveFinancialAccountFormResult
                    {
                        Title = "Invalid Transaction",
                        Detail = "Sorry, the account information cannot be saved as there's not a valid transaction to reference",
                        IsSuccess = false
                    });
                }

                // Create the login if needed
                if (isAnonymous)
                {
                    var user = UserLoginService.Create(
                        rockContext,
                        transactionPerson,
                        AuthenticationServiceType.Internal,
                        EntityTypeCache.Get(SystemGuid.EntityType.AUTHENTICATION_DATABASE.AsGuid()).Id,
                        args.Username,
                        args.Password,
                        false);

                    var mergeFields = Lava.LavaHelper.GetCommonMergeFields(null, currentPerson);
                    // TODO mergeFields.Add( "ConfirmAccountUrl", RootPath + "ConfirmAccount" );
                    mergeFields.Add("Person", transactionPerson);
                    mergeFields.Add("User", user);

                    var emailMessage = new RockEmailMessage(SystemGuid.SystemCommunication.SECURITY_CONFIRM_ACCOUNT.AsGuid());
                    emailMessage.AddRecipient(new RockEmailMessageRecipient(transactionPerson, mergeFields));
                    // TODO emailMessage.AppRoot = ResolveRockUrl( "~/" );
                    // TODO emailMessage.ThemeRoot = ResolveRockUrl( "~~/" );
                    emailMessage.CreateCommunicationRecord = false;
                    emailMessage.Send();
                }

                var savedAccount = new FinancialPersonSavedAccount
                {
                    PersonAliasId           = transactionPersonAlias.Id,
                    ReferenceNumber         = args.TransactionCode,
                    GatewayPersonIdentifier = args.GatewayPersonIdentifier,
                    Name                   = args.SavedAccountName,
                    TransactionCode        = args.TransactionCode,
                    FinancialGatewayId     = financialGateway.Id,
                    FinancialPaymentDetail = new FinancialPaymentDetail
                    {
                        AccountNumberMasked   = paymentDetail.AccountNumberMasked,
                        CurrencyTypeValueId   = paymentDetail.CurrencyTypeValueId,
                        CreditCardTypeValueId = paymentDetail.CreditCardTypeValueId,
                        NameOnCard            = paymentDetail.NameOnCard,
                        ExpirationMonth       = paymentDetail.ExpirationMonth,
                        ExpirationYear        = paymentDetail.ExpirationYear,
                        BillingLocationId     = paymentDetail.BillingLocationId
                    }
                };

                var financialPersonSavedAccountService = new FinancialPersonSavedAccountService(rockContext);
                financialPersonSavedAccountService.Add(savedAccount);
                rockContext.SaveChanges();

                return(new SaveFinancialAccountFormResult
                {
                    Title = "Success",
                    Detail = "The account has been saved for future use",
                    IsSuccess = true
                });
            }
        }