Esempio n. 1
0
        public void InitUi()
        {
            var settings = new Settings(this);

            var paymentMethodTypes = GetPaymentMethodTypes(settings);

            var amount            = new BigDecimal(BigInteger.One);
            var paymentParameters = new PaymentParameters(new Amount(amount, Rub),
                                                          "АСБ Подписка",
                                                          "Для получения возможности отправки тревоги, необходимо оплатить подписку.",
                                                          "live_NjQwOTI43n8qs0roPyYJGGSb5248EIztMBFQaTyfJZ4",
                                                          "640928",
                                                          paymentMethodTypes);

            var uiParameters = new UiParameters(settings.ShowYandexCheckoutLogo, new ColorScheme(settings.GetPrimaryColor));

            MockConfiguration mockConfiguration;

            if (settings.IsTestModeEnabled)
            {
                mockConfiguration = new MockConfiguration(settings.ShouldCompletePaymentWithError,
                                                          settings.IsPaymentAuthPassed,
                                                          settings.GetLinkedCardsCount,
                                                          new Amount(new BigDecimal(settings.GetServiceFee), Rub));
            }
            else
            {
                mockConfiguration = null;
            }

            var testParameters = new TestParameters(true, false, mockConfiguration);
            var intent         = Checkout.CreateTokenizeIntent(this, paymentParameters, testParameters, uiParameters);

            StartActivityForResult(intent, RequestCodeTokenize);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the location.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private int CreateLocation(PaymentParameters parameters, RockContext rockContext)
        {
            if (string.IsNullOrWhiteSpace(parameters.Street1) ||
                string.IsNullOrWhiteSpace(parameters.City) ||
                string.IsNullOrWhiteSpace(parameters.State) ||
                string.IsNullOrWhiteSpace(parameters.PostalCode))
            {
                GenerateResponse(HttpStatusCode.BadRequest, "Street1, City, State, and PostalCode are required");
            }

            if (parameters.State == null || parameters.State.Length != 2)
            {
                GenerateResponse(HttpStatusCode.BadRequest, "State must be a 2 letter string");
            }

            var location = new Location
            {
                Street1    = parameters.Street1,
                Street2    = parameters.Street2,
                City       = parameters.City,
                State      = parameters.State,
                PostalCode = parameters.PostalCode,
                Country    = parameters.Country ?? "USA"
            };

            new LocationService(rockContext).Add(location);
            rockContext.SaveChanges();
            return(location.Id);
        }
Esempio n. 3
0
 public void Visit(TejaratParsianGateway tejaratParsianGateway, PaymentParameters parameters)
 {
     tejaratParsianGateway.Pin          = parameters.Pin;
     tejaratParsianGateway.Amount       = parameters.Amount.ToString();
     tejaratParsianGateway.PurchaseLink = parameters.PurchaseLink;
     tejaratParsianGateway.Token        = parameters.Token;
     tejaratParsianGateway.OrderId      = parameters.OrderId.ToString();
     tejaratParsianGateway.ReturnUrl    = parameters.ReturnUrl;
 }
Esempio n. 4
0
        public static IPayment GetIpgPayment(PaymentParameters parameters)
        {
            var visitor = new FillRequiredFields();

            switch (parameters.IpgId)
            {
            case 1001:
            {
                var irankish = new IranKishGateway();
                irankish.AcceptVisitor(visitor, parameters);
                return(irankish);
            }

            case 1002:
            {
                var sdsw1 = new SadadSwitch1Gateway();
                sdsw1.AcceptVisitor(visitor, parameters);
                return(sdsw1);
            }

            case 1003:
            {
                var sadad2 = new SadadSwitch2Gateway();
                sadad2.AcceptVisitor(visitor, parameters);
                return(sadad2);
            }

            case 1004:
            {
                var tejaratparsian = new TejaratParsianGateway();
                tejaratparsian.AcceptVisitor(visitor, parameters);
                return(tejaratparsian);
            }

            case 1005:
            {
                var behpardakht = new BehPardakhtGateway();
                behpardakht.AcceptVisitor(visitor, parameters);
                return(behpardakht);
            }

            case 1007:
            {
                var asanpardakht = new AsanPardakhtGateway();
                asanpardakht.AcceptVisitor(visitor, parameters);
                return(asanpardakht);
            }

            case 1008:
            {
                var mabna = new MabnaCardGateway();
                mabna.AcceptVisitor(visitor, parameters);
                return(mabna);
            }
            }
            return(null);
        }
Esempio n. 5
0
 public void Visit(SadadSwitch1Gateway sadadSwitch1Gateway, PaymentParameters parameters)
 {
     sadadSwitch1Gateway.MerchantId     = parameters.MerchantId;
     sadadSwitch1Gateway.TerminalId     = parameters.TerminalId;
     sadadSwitch1Gateway.TransactionKey = parameters.TransactionKey;
     sadadSwitch1Gateway.Amount         = parameters.Amount;
     sadadSwitch1Gateway.OrderId        = parameters.OrderId;
     sadadSwitch1Gateway.ReturnUrl      = parameters.ReturnUrl;
     sadadSwitch1Gateway.PurchaseLink   = parameters.PurchaseLink;
     sadadSwitch1Gateway.RequestKey     = parameters.RequestKey;
 }
Esempio n. 6
0
 public void Visit(MabnaCardGateway mabnaCardGateway, PaymentParameters parameters)
 {
     mabnaCardGateway.Crn          = parameters.Crn;
     mabnaCardGateway.Mid          = parameters.Mid;
     mabnaCardGateway.Tid          = parameters.Tid;
     mabnaCardGateway.PrivateKey   = parameters.Privatekey;
     mabnaCardGateway.PublicKey    = parameters.Publickey;
     mabnaCardGateway.Amount       = parameters.Amount.ToString();
     mabnaCardGateway.Trn          = parameters.Trn;
     mabnaCardGateway.ReturnUrl    = parameters.ReturnUrl;
     mabnaCardGateway.PurchaseLink = parameters.PurchaseLink;
 }
Esempio n. 7
0
        /// <summary>
        /// Creates the saved account.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="paymentDetail">The payment detail.</param>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private FinancialPersonSavedAccount CreateSavedAccount(PaymentParameters parameters, FinancialPaymentDetail paymentDetail, FinancialGateway financialGateway, Person person, RockContext rockContext)
        {
            var lastFour = paymentDetail.AccountNumberMasked.Substring(paymentDetail.AccountNumberMasked.Length - 4);
            var name     = string.Empty;

            if (parameters.AccountType.ToLower() != "credit")
            {
                if (string.IsNullOrWhiteSpace(parameters.RoutingNumber))
                {
                    GenerateResponse(HttpStatusCode.BadRequest, "RoutingNumber is required for ACH transactions");
                    return(null);
                }

                if (string.IsNullOrWhiteSpace(parameters.AccountNumber))
                {
                    GenerateResponse(HttpStatusCode.BadRequest, "AccountNumber is required");
                    return(null);
                }

                name = "Bank card ***" + lastFour;
                var bankAccountService   = new FinancialPersonBankAccountService(rockContext);
                var accountNumberSecured = FinancialPersonBankAccount.EncodeAccountNumber(parameters.RoutingNumber, parameters.AccountNumber);
                var bankAccount          = bankAccountService.Queryable().Where(a =>
                                                                                a.AccountNumberSecured == accountNumberSecured &&
                                                                                a.PersonAliasId == person.PrimaryAliasId.Value).FirstOrDefault();

                if (bankAccount == null)
                {
                    bankAccount = new FinancialPersonBankAccount();
                    bankAccount.PersonAliasId        = person.PrimaryAliasId.Value;
                    bankAccount.AccountNumberMasked  = paymentDetail.AccountNumberMasked;
                    bankAccount.AccountNumberSecured = accountNumberSecured;
                    bankAccountService.Add(bankAccount);
                }
            }
            else
            {
                name = "Credit card ***" + lastFour;
            }

            var savedAccount = new FinancialPersonSavedAccount {
                PersonAliasId      = person.PrimaryAliasId,
                FinancialGatewayId = financialGateway.Id,
                Name = name,
                FinancialPaymentDetailId = paymentDetail.Id
            };

            new FinancialPersonSavedAccountService(rockContext).Add(savedAccount);
            rockContext.SaveChanges();
            return(savedAccount);
        }
Esempio n. 8
0
 public void Visit(BehPardakhtGateway behPardakhtGateway, PaymentParameters parameters)
 {
     behPardakhtGateway.TerminalId      = parameters.TerminalId;
     behPardakhtGateway.UserName        = parameters.Username;
     behPardakhtGateway.UserPassword    = parameters.Password;
     behPardakhtGateway.Amount          = parameters.Amount.ToString();
     behPardakhtGateway.OrderId         = parameters.OrderId.ToString();
     behPardakhtGateway.ReturnUrl       = parameters.ReturnUrl;
     behPardakhtGateway.PurchaseLink    = parameters.PurchaseLink;
     behPardakhtGateway.Token           = parameters.Token;
     behPardakhtGateway.AdditionalData  = parameters.AdditionalData;
     behPardakhtGateway.PayerId         = parameters.PayerId;
     behPardakhtGateway.SaleReferenceId = parameters.SaleReferenceId;
 }
Esempio n. 9
0
 public void Visit(SadadSwitch2Gateway sadadSwitch2Gateway, PaymentParameters parameters)
 {
     sadadSwitch2Gateway.MerchantId           = parameters.MerchantId;
     sadadSwitch2Gateway.TerminalId           = parameters.TerminalId;
     sadadSwitch2Gateway.TransactionKey       = parameters.TransactionKey;
     sadadSwitch2Gateway.Amount               = parameters.Amount;
     sadadSwitch2Gateway.OrderId              = parameters.OrderId.ToString();
     sadadSwitch2Gateway.RestTokenWebservice  = parameters.RestTokenWebservice;
     sadadSwitch2Gateway.RestVerifyWebservice = parameters.RestVerifywebServicelink;
     sadadSwitch2Gateway.ReturnUrl            = parameters.ReturnUrl;
     sadadSwitch2Gateway.PurchaseLink         = parameters.PurchaseLink;
     sadadSwitch2Gateway.Token           = parameters.Token;
     sadadSwitch2Gateway.PaymentIdentity = parameters.PaymentIdentity;
 }
Esempio n. 10
0
 public void Visit(IranKishGateway iranKish, PaymentParameters parameters)
 {
     iranKish.Amount           = parameters.Amount.ToString();
     iranKish.Description      = parameters.Description;
     iranKish.MerchantId       = parameters.MerchantId;
     iranKish.OrderId          = parameters.OrderId.ToString();
     iranKish.PeymentId        = parameters.PeymentId;
     iranKish.PurchaseLink     = parameters.PurchaseLink;
     iranKish.ReturnUrl        = parameters.ReturnUrl;
     iranKish.SpecialPeymentId = parameters.SpecialPeymentId;
     iranKish.Sha1Key          = parameters.Sha1Key;
     iranKish.Token            = parameters.Token;
     iranKish.ReferenceNumber  = parameters.ReferenceNumber;
 }
Esempio n. 11
0
 public void Visit(AsanPardakhtGateway asanPardakhtGateway, PaymentParameters parameters)
 {
     asanPardakhtGateway.MerchantId      = int.Parse(parameters.MerchantId);
     asanPardakhtGateway.Username        = parameters.Username;
     asanPardakhtGateway.Password        = parameters.Password;
     asanPardakhtGateway.Key             = parameters.Key;
     asanPardakhtGateway.Iv              = parameters.Iv;
     asanPardakhtGateway.Amount          = parameters.Amount.ToString();
     asanPardakhtGateway.OrderId         = parameters.OrderId.ToString();
     asanPardakhtGateway.ReturnUrl       = parameters.ReturnUrl;
     asanPardakhtGateway.ExtraInfo       = parameters.ExtraInfo;
     asanPardakhtGateway.PurchaseLink    = parameters.PurchaseLink;
     asanPardakhtGateway.ReturningParams = parameters.ReturningParams;
 }
Esempio n. 12
0
        /// <summary>
        /// Creates the payment detail.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="person">The person.</param>
        /// <param name="billingLocationId">The billing location identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private FinancialPaymentDetail CreatePaymentDetail(PaymentParameters parameters, Person person, int billingLocationId, RockContext rockContext)
        {
            if (string.IsNullOrWhiteSpace(parameters.AccountNumber))
            {
                GenerateResponse(HttpStatusCode.BadRequest, "AccountNumber is required");
                return(null);
            }

            if (string.IsNullOrWhiteSpace(parameters.AccountType))
            {
                GenerateResponse(HttpStatusCode.BadRequest, "AccountType is required");
                return(null);
            }

            var accountType  = parameters.AccountType.ToLower();
            var allowedTypes = new String[] { "checking", "savings", "credit" };

            if (!allowedTypes.Contains(accountType))
            {
                GenerateResponse(HttpStatusCode.BadRequest, "AccountType must be one of " + string.Join(", ", allowedTypes));
                return(null);
            }

            var maskedAccountNumber = Mask(parameters.AccountNumber);
            var nameOnCard          = (parameters.FirstName ?? person.FirstName) + " " + (parameters.LastName ?? person.LastName);

            var paymentDetail = new FinancialPaymentDetail
            {
                AccountNumberMasked = maskedAccountNumber,
                NameOnCardEncrypted = Rock.Security.Encryption.EncryptString(nameOnCard),
                BillingLocationId   = billingLocationId
            };

            if (parameters.AccountType.ToLower() == "credit")
            {
                paymentDetail.ExpirationMonthEncrypted = Rock.Security.Encryption.EncryptString(parameters.ExpirationMonth.ToString());
                paymentDetail.ExpirationYearEncrypted  = Rock.Security.Encryption.EncryptString(parameters.ExpirationYear.ToString());
            }

            new FinancialPaymentDetailService(rockContext).Add(paymentDetail);
            rockContext.SaveChanges();
            return(paymentDetail);
        }
Esempio n. 13
0
        /// <summary>
        /// Gets the payment information.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="totalAmount">The total amount.</param>
        /// <param name="paymentDetail">The payment detail.</param>
        /// <returns></returns>
        private PaymentInfo GetPaymentInfo( PaymentParameters parameters, Person person, RockContext rockContext, decimal totalAmount, FinancialPaymentDetail paymentDetail )
        {
            PaymentInfo paymentInfo = null;

            if ( parameters.AccountType.ToLower() == "credit" )
            {
                if ( parameters.ExpirationMonth < 1 || parameters.ExpirationMonth > 12 )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, "ExpirationMonth is required and must be between 1 and 12 for credit transactions" );
                }

                var currentDate = DateTime.Now;
                var maxYear = currentDate.Year + 30;

                if ( parameters.ExpirationYear < currentDate.Year || parameters.ExpirationYear > maxYear )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, string.Format( "ExpirationYear is required and must be between {0} and {1} for credit transactions", currentDate.Year, maxYear ) );
                }

                if ( parameters.ExpirationYear <= currentDate.Year && parameters.ExpirationMonth < currentDate.Month )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, "The ExpirationMonth and ExpirationYear combination must not have already elapsed for credit transactions" );
                }

                if ( string.IsNullOrWhiteSpace( parameters.Street1 ) ||
                    string.IsNullOrWhiteSpace( parameters.City ) ||
                    string.IsNullOrWhiteSpace( parameters.State ) ||
                    string.IsNullOrWhiteSpace( parameters.PostalCode ) )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, "Street1, City, State, and PostalCode are required for credit transactions" );
                }

                paymentInfo = new CreditCardPaymentInfo()
                {
                    Number = parameters.AccountNumber,
                    Code = parameters.CCV ?? string.Empty,
                    ExpirationDate = new DateTime( parameters.ExpirationYear, parameters.ExpirationMonth, 1 ),
                    BillingStreet1 = parameters.Street1 ?? string.Empty,
                    BillingStreet2 = parameters.Street2 ?? string.Empty,
                    BillingCity = parameters.City ?? string.Empty,
                    BillingState = parameters.State ?? string.Empty,
                    BillingPostalCode = parameters.PostalCode ?? string.Empty,
                    BillingCountry = parameters.Country ?? "USA"
                };
            }
            else
            {
                if ( string.IsNullOrWhiteSpace( parameters.RoutingNumber ) )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, "RoutingNumber is required for ACH transactions" );
                    return null;
                }

                paymentInfo = new ACHPaymentInfo()
                {
                    BankRoutingNumber = parameters.RoutingNumber,
                    BankAccountNumber = parameters.AccountNumber,
                    AccountType = parameters.AccountType.ToLower() == "checking" ? BankAccountType.Checking : BankAccountType.Savings
                };
            }

            paymentInfo.Amount = totalAmount;
            paymentInfo.FirstName = parameters.FirstName ?? person.FirstName;
            paymentInfo.LastName = parameters.LastName ?? person.LastName;
            paymentInfo.Email = parameters.Email ?? person.Email;
            paymentInfo.Phone = parameters.PhoneNumber ?? string.Empty;
            paymentInfo.Street1 = parameters.Street1 ?? string.Empty;
            paymentInfo.Street2 = parameters.Street2 ?? string.Empty;
            paymentInfo.City = parameters.City ?? string.Empty;
            paymentInfo.State = parameters.State ?? string.Empty;
            paymentInfo.PostalCode = parameters.PostalCode ?? string.Empty;
            paymentInfo.Country = parameters.Country ?? "USA";

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

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

            return paymentInfo;
        }
Esempio n. 14
0
        /// <summary>
        /// Creates the location.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private int CreateLocation( PaymentParameters parameters, RockContext rockContext )
        {
            if ( string.IsNullOrWhiteSpace( parameters.Street1 ) ||
                string.IsNullOrWhiteSpace( parameters.City ) ||
                string.IsNullOrWhiteSpace( parameters.State ) ||
                string.IsNullOrWhiteSpace( parameters.PostalCode ) )
            {
                GenerateResponse( HttpStatusCode.BadRequest, "Street1, City, State, and PostalCode are required" );
            }

            if ( parameters.State == null || parameters.State.Length != 2 )
            {
                GenerateResponse( HttpStatusCode.BadRequest, "State must be a 2 letter string" );
            }

            var location = new Location
            {
                Street1 = parameters.Street1,
                Street2 = parameters.Street2,
                City = parameters.City,
                State = parameters.State,
                PostalCode = parameters.PostalCode,
                Country = parameters.Country ?? "USA"
            };

            new LocationService( rockContext ).Add( location );
            rockContext.SaveChanges();
            return location.Id;
        }
Esempio n. 15
0
 public abstract void AcceptVisitor(IVisitor visitor, PaymentParameters parameters);
Esempio n. 16
0
        /// <summary>
        /// Gets the payment information.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="totalAmount">The total amount.</param>
        /// <param name="paymentDetail">The payment detail.</param>
        /// <returns></returns>
        private PaymentInfo GetPaymentInfo(PaymentParameters parameters, Person person, RockContext rockContext, decimal totalAmount, FinancialPaymentDetail paymentDetail)
        {
            PaymentInfo paymentInfo = null;

            if (parameters.AccountType.ToLower() == "credit")
            {
                if (parameters.ExpirationMonth < 1 || parameters.ExpirationMonth > 12)
                {
                    GenerateResponse(HttpStatusCode.BadRequest, "ExpirationMonth is required and must be between 1 and 12 for credit transactions");
                }

                var currentDate = DateTime.Now;
                var maxYear     = currentDate.Year + 30;

                if (parameters.ExpirationYear < currentDate.Year || parameters.ExpirationYear > maxYear)
                {
                    GenerateResponse(HttpStatusCode.BadRequest, string.Format("ExpirationYear is required and must be between {0} and {1} for credit transactions", currentDate.Year, maxYear));
                }

                if (parameters.ExpirationYear <= currentDate.Year && parameters.ExpirationMonth < currentDate.Month)
                {
                    GenerateResponse(HttpStatusCode.BadRequest, "The ExpirationMonth and ExpirationYear combination must not have already elapsed for credit transactions");
                }

                if (string.IsNullOrWhiteSpace(parameters.Street1) ||
                    string.IsNullOrWhiteSpace(parameters.City) ||
                    string.IsNullOrWhiteSpace(parameters.State) ||
                    string.IsNullOrWhiteSpace(parameters.PostalCode))
                {
                    GenerateResponse(HttpStatusCode.BadRequest, "Street1, City, State, and PostalCode are required for credit transactions");
                }

                paymentInfo = new CreditCardPaymentInfo()
                {
                    Number            = parameters.AccountNumber,
                    Code              = parameters.CCV ?? string.Empty,
                    ExpirationDate    = new DateTime(parameters.ExpirationYear, parameters.ExpirationMonth, 1),
                    BillingStreet1    = parameters.Street1 ?? string.Empty,
                    BillingStreet2    = parameters.Street2 ?? string.Empty,
                    BillingCity       = parameters.City ?? string.Empty,
                    BillingState      = parameters.State ?? string.Empty,
                    BillingPostalCode = parameters.PostalCode ?? string.Empty,
                    BillingCountry    = parameters.Country ?? "USA"
                };
            }
            else
            {
                if (string.IsNullOrWhiteSpace(parameters.RoutingNumber))
                {
                    GenerateResponse(HttpStatusCode.BadRequest, "RoutingNumber is required for ACH transactions");
                    return(null);
                }

                paymentInfo = new ACHPaymentInfo()
                {
                    BankRoutingNumber = parameters.RoutingNumber,
                    BankAccountNumber = parameters.AccountNumber,
                    AccountType       = parameters.AccountType.ToLower() == "checking" ? BankAccountType.Checking : BankAccountType.Savings
                };
            }

            paymentInfo.Amount     = totalAmount;
            paymentInfo.FirstName  = parameters.FirstName ?? person.FirstName;
            paymentInfo.LastName   = parameters.LastName ?? person.LastName;
            paymentInfo.Email      = parameters.Email ?? person.Email;
            paymentInfo.Phone      = parameters.PhoneNumber ?? string.Empty;
            paymentInfo.Street1    = parameters.Street1 ?? string.Empty;
            paymentInfo.Street2    = parameters.Street2 ?? string.Empty;
            paymentInfo.City       = parameters.City ?? string.Empty;
            paymentInfo.State      = parameters.State ?? string.Empty;
            paymentInfo.PostalCode = parameters.PostalCode ?? string.Empty;
            paymentInfo.Country    = parameters.Country ?? "USA";

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

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

            return(paymentInfo);
        }
Esempio n. 17
0
        /// <summary>
        /// Creates the payment detail.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="person">The person.</param>
        /// <param name="billingLocationId">The billing location identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private FinancialPaymentDetail CreatePaymentDetail( PaymentParameters parameters, Person person, int billingLocationId, RockContext rockContext )
        {
            if ( string.IsNullOrWhiteSpace( parameters.AccountNumber ) )
            {
                GenerateResponse( HttpStatusCode.BadRequest, "AccountNumber is required" );
                return null;
            }

            if ( string.IsNullOrWhiteSpace( parameters.AccountType ) )
            {
                GenerateResponse( HttpStatusCode.BadRequest, "AccountType is required" );
                return null;
            }

            var accountType = parameters.AccountType.ToLower();
            var allowedTypes = new String[] { "checking", "savings", "credit" };

            if (!allowedTypes.Contains(accountType) )
            {
                GenerateResponse( HttpStatusCode.BadRequest, "AccountType must be one of " + string.Join(", ", allowedTypes) );
                return null;
            }

            var maskedAccountNumber = Mask( parameters.AccountNumber );
            var nameOnCard = ( parameters.FirstName ?? person.FirstName ) + " " + ( parameters.LastName ?? person.LastName );

            var paymentDetail = new FinancialPaymentDetail
            {
                AccountNumberMasked = maskedAccountNumber,
                NameOnCardEncrypted = Rock.Security.Encryption.EncryptString(nameOnCard),
                BillingLocationId = billingLocationId
            };

            if ( parameters.AccountType.ToLower() == "credit" )
            {
                paymentDetail.ExpirationMonthEncrypted = Rock.Security.Encryption.EncryptString( parameters.ExpirationMonth.ToString() );
                paymentDetail.ExpirationYearEncrypted = Rock.Security.Encryption.EncryptString( parameters.ExpirationYear.ToString() );
            }

            new FinancialPaymentDetailService( rockContext ).Add( paymentDetail );
            rockContext.SaveChanges();
            return paymentDetail;
        }
Esempio n. 18
0
        /// <summary>
        /// Creates the saved account.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="paymentDetail">The payment detail.</param>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private FinancialPersonSavedAccount CreateSavedAccount( PaymentParameters parameters, FinancialPaymentDetail paymentDetail, FinancialGateway financialGateway, Person person, RockContext rockContext)
        {
            var lastFour = paymentDetail.AccountNumberMasked.Substring(paymentDetail.AccountNumberMasked.Length - 4);
            var name = string.Empty;

            if ( parameters.AccountType.ToLower() != "credit" )
            {
                if ( string.IsNullOrWhiteSpace( parameters.RoutingNumber ) )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, "RoutingNumber is required for ACH transactions" );
                    return null;
                }

                if ( string.IsNullOrWhiteSpace( parameters.AccountNumber ) )
                {
                    GenerateResponse( HttpStatusCode.BadRequest, "AccountNumber is required" );
                    return null;
                }

                name = "Bank card ***" + lastFour;
                var bankAccountService = new FinancialPersonBankAccountService( rockContext );
                var accountNumberSecured = FinancialPersonBankAccount.EncodeAccountNumber( parameters.RoutingNumber, parameters.AccountNumber );
                var bankAccount = bankAccountService.Queryable().Where( a =>
                    a.AccountNumberSecured == accountNumberSecured &&
                    a.PersonAliasId == person.PrimaryAliasId.Value ).FirstOrDefault();

                if ( bankAccount == null )
                {
                    bankAccount = new FinancialPersonBankAccount();
                    bankAccount.PersonAliasId = person.PrimaryAliasId.Value;
                    bankAccount.AccountNumberMasked = paymentDetail.AccountNumberMasked;
                    bankAccount.AccountNumberSecured = accountNumberSecured;
                    bankAccountService.Add( bankAccount );
                }
            }
            else
            {
                name = "Credit card ***" + lastFour;
            }

            var savedAccount = new FinancialPersonSavedAccount {
                PersonAliasId = person.PrimaryAliasId,
                FinancialGatewayId = financialGateway.Id,
                Name = name,
                FinancialPaymentDetailId = paymentDetail.Id
            };

            new FinancialPersonSavedAccountService(rockContext).Add( savedAccount );
            rockContext.SaveChanges();
            return savedAccount;
        }
 public override void AcceptVisitor(IVisitor visitor, PaymentParameters parameters)
 {
     visitor.Visit(this, parameters);
 }
Esempio n. 20
0
        public HttpResponseMessage SavePaymentAccount([FromBody] PaymentParameters paymentParameters)
        {
            var rockContext = new RockContext();

            try
            {
                rockContext.WrapTransaction(() =>
                {
                    var person = GetExistingPerson(paymentParameters.PersonId, rockContext);

                    if (person == null)
                    {
                        GenerateResponse(HttpStatusCode.BadRequest, "An existing person is required to save a payment");
                    }

                    var gatewayComponent = GatewayContainer.GetComponent(gatewayName);

                    if (gatewayComponent == null)
                    {
                        GenerateResponse(HttpStatusCode.InternalServerError, "There was a problem creating the gateway component");
                    }

                    var financialGateway = new FinancialGatewayService(rockContext).Queryable().FirstOrDefault(g => g.EntityTypeId == gatewayComponent.EntityType.Id);

                    if (financialGateway == null)
                    {
                        GenerateResponse(HttpStatusCode.InternalServerError, "There was a problem creating the financial gateway");
                    }

                    var locationId    = CreateLocation(paymentParameters, rockContext);
                    var paymentDetail = CreatePaymentDetail(paymentParameters, person, locationId, rockContext);
                    var savedAccount  = CreateSavedAccount(paymentParameters, paymentDetail, financialGateway, person, rockContext);
                    var paymentInfo   = GetPaymentInfo(paymentParameters, person, rockContext, 0, paymentDetail);

                    string errorMessage;
                    var transaction = gatewayComponent.Authorize(financialGateway, paymentInfo, out errorMessage);

                    if (transaction == null || !string.IsNullOrWhiteSpace(errorMessage))
                    {
                        GenerateResponse(HttpStatusCode.InternalServerError, errorMessage ?? "The gateway had a problem and/or did not create a transaction as expected");
                    }

                    transaction.FinancialPaymentDetail   = null;
                    transaction.SourceTypeValueId        = DefinedValueCache.Read(new Guid(Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_WEBSITE)).Id;
                    transaction.TransactionDateTime      = RockDateTime.Now;
                    transaction.AuthorizedPersonAliasId  = person.PrimaryAliasId;
                    transaction.AuthorizedPersonAlias    = person.PrimaryAlias;
                    transaction.FinancialGateway         = financialGateway;
                    transaction.FinancialGatewayId       = financialGateway.Id;
                    transaction.TransactionTypeValueId   = DefinedValueCache.Read(new Guid(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION)).Id;
                    transaction.FinancialPaymentDetailId = paymentDetail.Id;
                    savedAccount.TransactionCode         = transaction.TransactionCode;
                    SaveLocationToFamilyIfNone(person, locationId, rockContext);
                    savedAccount.ReferenceNumber = gatewayComponent.GetReferenceNumber(transaction, out errorMessage);
                    rockContext.SaveChanges();
                });
            }
            catch (HttpResponseException exception)
            {
                return(exception.Response);
            }
            catch (Exception exception)
            {
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                response.Content = new StringContent(exception.Message);
                return(response);
            }

            return(new HttpResponseMessage(HttpStatusCode.NoContent));
        }