Information about a credit card payment to be processed by a financial gateway
Inheritance: PaymentInfo
Exemplo n.º 1
0
        /// <summary>
        /// Adds the scheduled payment.
        /// </summary>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="schedule">The schedule.</param>
        /// <param name="paymentInfo">The payment info.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override FinancialScheduledTransaction AddScheduledPayment(FinancialGateway financialGateway, PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (ValidateCard(financialGateway, paymentInfo, out errorMessage))
            {
                var scheduledTransaction = new FinancialScheduledTransaction();
                scheduledTransaction.IsActive                 = true;
                scheduledTransaction.StartDate                = schedule.StartDate;
                scheduledTransaction.NextPaymentDate          = schedule.StartDate;
                scheduledTransaction.TransactionCode          = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
                scheduledTransaction.GatewayScheduleId        = "Subscription_" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
                scheduledTransaction.LastStatusUpdateDateTime = RockDateTime.Now;
                scheduledTransaction.Status        = FinancialScheduledTransactionStatus.Active;
                scheduledTransaction.StatusMessage = "active";

                scheduledTransaction.FinancialPaymentDetail = new FinancialPaymentDetail()
                {
                    ExpirationMonth       = (paymentInfo as ReferencePaymentInfo)?.PaymentExpirationDate?.Month,
                    ExpirationYear        = (paymentInfo as ReferencePaymentInfo)?.PaymentExpirationDate?.Year,
                    CurrencyTypeValueId   = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                    AccountNumberMasked   = paymentInfo.MaskedNumber,
                    CreditCardTypeValueId = CreditCardPaymentInfo.GetCreditCardTypeFromCreditCardNumber(paymentInfo.MaskedNumber)?.Id ?? DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.CREDITCARD_TYPE_VISA.AsGuid())
                };

                return(scheduledTransaction);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Charges the specified payment info.
        /// </summary>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="paymentInfo">The payment info.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override FinancialTransaction Charge(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage)
        {
            errorMessage = string.Empty;

            CreditCardPaymentInfo ccPayment = paymentInfo as CreditCardPaymentInfo;

            if (ccPayment != null)
            {
                if (ccPayment.Code == "911")
                {
                    errorMessage = "Error processing Credit Card!";
                    return(null);
                }
            }

            var transaction = new FinancialTransaction();

            transaction.TransactionCode = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            return(transaction);
        }
Exemplo n.º 3
0
        private bool ValidateCard(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage)
        {
            string cardNumber = string.Empty;

            CreditCardPaymentInfo ccPayment = paymentInfo as CreditCardPaymentInfo;

            if (ccPayment != null)
            {
                if (ccPayment.Code == "911")
                {
                    errorMessage = "Error processing Credit Card!";
                    return(false);
                }

                cardNumber = ccPayment.Number;
            }

            SwipePaymentInfo swipePayment = paymentInfo as SwipePaymentInfo;

            if (swipePayment != null)
            {
                cardNumber = swipePayment.Number;
            }

            if (!string.IsNullOrWhiteSpace(cardNumber))
            {
                var declinedNumers = GetAttributeValue(financialGateway, "DeclinedCardNumbers");
                if (!string.IsNullOrWhiteSpace(declinedNumers))
                {
                    if (declinedNumers.SplitDelimitedValues().Any(n => cardNumber.EndsWith(n)))
                    {
                        errorMessage = "Error processing Credit Card!";
                        return(false);
                    }
                }
            }

            errorMessage = string.Empty;
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Charges the specified payment info.
        /// </summary>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="paymentInfo">The payment info.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override FinancialTransaction Charge(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (ValidateCard(financialGateway, paymentInfo, out errorMessage))
            {
                var transaction = new FinancialTransaction();
                transaction.TransactionCode = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");

                transaction.FinancialPaymentDetail = new FinancialPaymentDetail()
                {
                    ExpirationMonth       = (paymentInfo as ReferencePaymentInfo)?.PaymentExpirationDate?.Month,
                    ExpirationYear        = (paymentInfo as ReferencePaymentInfo)?.PaymentExpirationDate?.Year,
                    CurrencyTypeValueId   = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                    AccountNumberMasked   = paymentInfo.MaskedNumber,
                    CreditCardTypeValueId = CreditCardPaymentInfo.GetCreditCardTypeFromCreditCardNumber(paymentInfo.MaskedNumber ?? string.Empty)?.Id ?? DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.CREDITCARD_TYPE_VISA.AsGuid())
                };

                return(transaction);
            }

            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the credit card information.
        /// </summary>
        /// <returns></returns>
        private CreditCardPaymentInfo GetCCInfo()
        {
            var cc = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate ?? DateTime.MinValue );
            cc.NameOnCard = _ccGatewayComponent != null && _ccGatewayComponent.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
            cc.LastNameOnCard = txtCardLastName.Text;

            if ( cbBillingAddress.Checked )
            {
                cc.BillingStreet1 = acBillingAddress.Street1;
                cc.BillingStreet2 = acBillingAddress.Street2;
                cc.BillingCity = acBillingAddress.City;
                cc.BillingState = acBillingAddress.State;
                cc.BillingPostalCode = acBillingAddress.PostalCode;
                cc.BillingCountry = acBillingAddress.Country;
            }
            else
            {
                cc.BillingStreet1 = acAddress.Street1;
                cc.BillingStreet2 = acAddress.Street2;
                cc.BillingCity = acAddress.City;
                cc.BillingState = acAddress.State;
                cc.BillingPostalCode = acAddress.PostalCode;
                cc.BillingCountry = acAddress.Country;
            }

            return cc;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Processes the payment.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="registration">The registration.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        private bool ProcessPayment( RockContext rockContext, Registration registration, out string errorMessage )
        {
            GatewayComponent gateway = null;
            if ( RegistrationTemplate != null && RegistrationTemplate.FinancialGateway != null )
            {
                gateway = RegistrationTemplate.FinancialGateway.GetGatewayComponent();
            }

            if ( gateway == null )
            {
                errorMessage = "There was a problem creating the payment gateway information";
                return false;
            }

            if ( !RegistrationInstanceState.AccountId.HasValue || RegistrationInstanceState.Account == null )
            {
                errorMessage = "There was a problem with the account configuration for this " + RegistrationTerm.ToLower();
                return false;
            }

            var paymentInfo = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate.Value );
            paymentInfo.NameOnCard = gateway != null && gateway.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
            paymentInfo.LastNameOnCard = txtCardLastName.Text;

            paymentInfo.BillingStreet1 = acBillingAddress.Street1;
            paymentInfo.BillingStreet2 = acBillingAddress.Street2;
            paymentInfo.BillingCity = acBillingAddress.City;
            paymentInfo.BillingState = acBillingAddress.State;
            paymentInfo.BillingPostalCode = acBillingAddress.PostalCode;
            paymentInfo.BillingCountry = acBillingAddress.Country;

            paymentInfo.Amount = RegistrationState.PaymentAmount ?? 0.0m;
            paymentInfo.Email = RegistrationState.ConfirmationEmail;

            paymentInfo.FirstName = RegistrationState.FirstName;
            paymentInfo.LastName = RegistrationState.LastName;

            var transaction = gateway.Charge( RegistrationTemplate.FinancialGateway, paymentInfo, out errorMessage );
            if ( transaction != null )
            {
                var txnChanges = new List<string>();
                txnChanges.Add( "Created Transaction" );

                History.EvaluateChange( txnChanges, "Transaction Code", string.Empty, transaction.TransactionCode );

                transaction.AuthorizedPersonAliasId = registration.PersonAliasId;

                transaction.TransactionDateTime = RockDateTime.Now;
                History.EvaluateChange( txnChanges, "Date/Time", null, transaction.TransactionDateTime );

                transaction.FinancialGatewayId = RegistrationTemplate.FinancialGatewayId;
                History.EvaluateChange( txnChanges, "Gateway", string.Empty, RegistrationTemplate.FinancialGateway.Name );

                var txnType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_EVENT_REGISTRATION ) );
                transaction.TransactionTypeValueId = txnType.Id;
                History.EvaluateChange( txnChanges, "Type", string.Empty, txnType.Value );

                if ( transaction.FinancialPaymentDetail == null )
                {
                    transaction.FinancialPaymentDetail = new FinancialPaymentDetail();
                }

                transaction.FinancialPaymentDetail.NameOnCardEncrypted = Rock.Security.Encryption.EncryptString( paymentInfo.NameOnCard );
                transaction.FinancialPaymentDetail.AccountNumberMasked = paymentInfo.MaskedNumber;
                transaction.FinancialPaymentDetail.ExpirationMonthEncrypted = Rock.Security.Encryption.EncryptString( paymentInfo.ExpirationDate.Month.ToString() );
                transaction.FinancialPaymentDetail.ExpirationYearEncrypted = Rock.Security.Encryption.EncryptString( paymentInfo.ExpirationDate.Year.ToString() );
                transaction.FinancialPaymentDetail.CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id;

                History.EvaluateChange( txnChanges, "Currency Type", string.Empty, paymentInfo.CurrencyTypeValue.Value );

                transaction.FinancialPaymentDetail.CreditCardTypeValueId = paymentInfo.CreditCardTypeValue != null ? paymentInfo.CreditCardTypeValue.Id : (int?)null;
                if ( transaction.FinancialPaymentDetail.CreditCardTypeValueId.HasValue )
                {
                    var ccType = DefinedValueCache.Read( transaction.FinancialPaymentDetail.CreditCardTypeValueId.Value );
                    History.EvaluateChange( txnChanges, "Credit Card Type", string.Empty, ccType.Value );
                }

                Guid sourceGuid = Guid.Empty;
                if ( Guid.TryParse( GetAttributeValue( "Source" ), out sourceGuid ) )
                {
                    var source = DefinedValueCache.Read( sourceGuid );
                    if ( source != null )
                    {
                        transaction.SourceTypeValueId = source.Id;
                        History.EvaluateChange( txnChanges, "Source", string.Empty, source.Value );
                    }
                }

                transaction.Summary = registration.GetSummary( RegistrationInstanceState );

                var transactionDetail = new FinancialTransactionDetail();
                transactionDetail.Amount = RegistrationState.PaymentAmount ?? 0.0m;
                transactionDetail.AccountId = RegistrationInstanceState.AccountId.Value;
                transactionDetail.EntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Registration ) ).Id;
                transactionDetail.EntityId = registration.Id;
                transaction.TransactionDetails.Add( transactionDetail );

                History.EvaluateChange( txnChanges, RegistrationInstanceState.Account.Name, 0.0M.ToString( "C2" ), transactionDetail.Amount.ToString( "C2" ) );

                var batchService = new FinancialBatchService( rockContext );

                // Get the batch
                var batch = batchService.Get(
                    GetAttributeValue( "BatchNamePrefix" ),
                    paymentInfo.CurrencyTypeValue,
                    paymentInfo.CreditCardTypeValue,
                    transaction.TransactionDateTime.Value,
                    RegistrationTemplate.FinancialGateway.GetBatchTimeOffset() );

                var batchChanges = new List<string>();

                if ( batch.Id == 0 )
                {
                    batchChanges.Add( "Generated the batch" );
                    History.EvaluateChange( batchChanges, "Batch Name", string.Empty, batch.Name );
                    History.EvaluateChange( batchChanges, "Status", null, batch.Status );
                    History.EvaluateChange( batchChanges, "Start Date/Time", null, batch.BatchStartDateTime );
                    History.EvaluateChange( batchChanges, "End Date/Time", null, batch.BatchEndDateTime );
                }

                decimal newControlAmount = batch.ControlAmount + transaction.TotalAmount;
                History.EvaluateChange( batchChanges, "Control Amount", batch.ControlAmount.ToString( "C2" ), newControlAmount.ToString( "C2" ) );
                batch.ControlAmount = newControlAmount;

                transaction.BatchId = batch.Id;
                batch.Transactions.Add( transaction );

                rockContext.SaveChanges();

                HistoryService.SaveChanges(
                    rockContext,
                    typeof( FinancialBatch ),
                    Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(),
                    batch.Id,
                    batchChanges
                );

                HistoryService.SaveChanges(
                    rockContext,
                    typeof( FinancialBatch ),
                    Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(),
                    batch.Id,
                    txnChanges,
                    CurrentPerson != null ? CurrentPerson.FullName : string.Empty,
                    typeof( FinancialTransaction ),
                    transaction.Id
                );

                TransactionCode = transaction.TransactionCode;

                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 7
0
        private bool ValidateCard(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage)
        {
            string cardNumber         = string.Empty;
            var    declinedCVV        = this.GetAttributeValue(financialGateway, AttributeKey.DeclinedCVV);
            int    maxExpirationYears = this.GetAttributeValue(financialGateway, AttributeKey.MaxExpirationYears).AsIntegerOrNull() ?? 10;

            CreditCardPaymentInfo ccPayment = paymentInfo as CreditCardPaymentInfo;

            if (ccPayment != null)
            {
                if (declinedCVV.IsNotNullOrWhiteSpace() && ccPayment.Code == declinedCVV)
                {
                    errorMessage = "Declined CVV";
                    return(false);
                }

                cardNumber = ccPayment.Number;

                if (ccPayment.ExpirationDate < RockDateTime.Now.Date)
                {
                    errorMessage = "Card Expired";
                    return(false);
                }

                if (ccPayment.ExpirationDate > RockDateTime.Now.AddYears(maxExpirationYears))
                {
                    errorMessage = "Invalid Card Expiration";
                    return(false);
                }

                if (ccPayment.Number.IsNullOrWhiteSpace())
                {
                    errorMessage = "Card number is required.";
                    return(false);
                }

                if (ccPayment.Code.IsNullOrWhiteSpace())
                {
                    errorMessage = "CVV is required.";
                    return(false);
                }
            }

            SwipePaymentInfo swipePayment = paymentInfo as SwipePaymentInfo;

            if (swipePayment != null)
            {
                cardNumber = swipePayment.Number;
            }

            if (!string.IsNullOrWhiteSpace(cardNumber))
            {
                var declinedNumbers = GetAttributeValue(financialGateway, AttributeKey.DeclinedCardNumbers);
                if (!string.IsNullOrWhiteSpace(declinedNumbers))
                {
                    if (declinedNumbers.SplitDelimitedValues().Any(n => cardNumber.EndsWith(n)))
                    {
                        errorMessage = "Declined Card";
                        return(false);
                    }
                }
            }

            errorMessage = string.Empty;
            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the credit card information.
        /// </summary>
        /// <returns></returns>
        private CreditCardPaymentInfo GetCCInfo()
        {
            var cc = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate.Value );
            cc.NameOnCard = Gateway.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
            cc.LastNameOnCard = txtCardLastName.Text;
            cc.BillingStreet = txtBillingStreet.Text;
            cc.BillingCity = txtBillingCity.Text;
            cc.BillingState = ddlBillingState.SelectedValue;
            cc.BillingZip = txtBillingZip.Text;

            return cc;
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
0
        private CreditCardPaymentInfo GetCCPaymentInfo( GatewayComponent gateway )
        {
            var ccPaymentInfo = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate.Value );

            ccPaymentInfo.NameOnCard = gateway != null && gateway.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
            ccPaymentInfo.LastNameOnCard = txtCardLastName.Text;

            ccPaymentInfo.BillingStreet1 = acBillingAddress.Street1;
            ccPaymentInfo.BillingStreet2 = acBillingAddress.Street2;
            ccPaymentInfo.BillingCity = acBillingAddress.City;
            ccPaymentInfo.BillingState = acBillingAddress.State;
            ccPaymentInfo.BillingPostalCode = acBillingAddress.PostalCode;
            ccPaymentInfo.BillingCountry = acBillingAddress.Country;

            ccPaymentInfo.Amount = RegistrationState.PaymentAmount ?? 0.0m;
            ccPaymentInfo.Email = RegistrationState.ConfirmationEmail;

            ccPaymentInfo.FirstName = RegistrationState.FirstName;
            ccPaymentInfo.LastName = RegistrationState.LastName;

            return ccPaymentInfo;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the credit card information.
        /// </summary>
        /// <returns></returns>
        private CreditCardPaymentInfo GetCCInfo()
        {
            var cc = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate.Value );
            cc.NameOnCard = Gateway.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
            cc.LastNameOnCard = txtCardLastName.Text;
            cc.BillingStreet1 = acBillingAddress.Street1;
            cc.BillingStreet2 = acBillingAddress.Street2;
            cc.BillingCity = acBillingAddress.City;
            cc.BillingState = acBillingAddress.State;
            cc.BillingPostalCode = acBillingAddress.PostalCode;
            cc.BillingCountry = acBillingAddress.Country;

            return cc;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the card information.
        /// </summary>
        /// <param name="paymentInfo">The payment information.</param>
        /// <returns></returns>
        private Card GetCard( CreditCardPaymentInfo cc )
        {
            var card = new Card();
            card.accountNumber = cc.Number.AsNumeric();
            card.expirationMonth = cc.ExpirationDate.Month.ToString( "D2" );
            card.expirationYear = cc.ExpirationDate.Year.ToString( "D4" );
            card.cvNumber = cc.Code.AsNumeric();
            card.cvIndicator = "1";

            if ( cc.CreditCardTypeValue != null )
            {
                switch ( cc.CreditCardTypeValue.Value )
                {
                    case "Visa":
                        card.cardType = "001";
                        break;

                    case "MasterCard":
                        card.cardType = "002";
                        break;

                    case "American Express":
                        card.cardType = "003";
                        break;

                    case "Discover":
                        card.cardType = "004";
                        break;

                    case "Diners":
                        card.cardType = "005";
                        break;

                    case "Carte Blanche":
                        card.cardType = "006";
                        break;

                    case "JCB":
                        card.cardType = "007";
                        break;

                    default:
                        card.cardType = string.Empty;
                        break;
                }
            }

            return card;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Processes the payment.
        /// </summary>
        /// <param name="submitToGateway">if set to <c>true</c> [submit to gateway].</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="registration">The registration.</param>
        /// <param name="personAliasId">The person alias identifier.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        private bool ProcessPayment( bool submitToGateway, RockContext rockContext, Registration registration, int? personAliasId, decimal amount, out string errorMessage )
        {
            FinancialTransaction transaction = null;

            var txnChanges = new List<string>();
            txnChanges.Add( "Created Transaction" );

            var registrationChanges = new List<string>();

            DefinedValueCache dvCurrencyType = null;
            DefinedValueCache dvCredCardType = null;

            if ( submitToGateway )
            {
                GatewayComponent gateway = null;
                if ( RegistrationTemplateState != null && RegistrationTemplateState.FinancialGateway != null )
                {
                    gateway = RegistrationTemplateState.FinancialGateway.GetGatewayComponent();
                }

                if ( gateway == null )
                {
                    errorMessage = "There was a problem creating the payment gateway information";
                    return false;
                }

                if ( registration == null || registration.RegistrationInstance == null || !registration.RegistrationInstance.AccountId.HasValue || registration.RegistrationInstance.Account == null )
                {
                    errorMessage = "There was a problem with the account configuration for this registration.";
                    return false;
                }

                var paymentInfo = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate.Value );
                paymentInfo.NameOnCard = gateway != null && gateway.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
                paymentInfo.LastNameOnCard = txtCardLastName.Text;

                paymentInfo.BillingStreet1 = acBillingAddress.Street1;
                paymentInfo.BillingStreet2 = acBillingAddress.Street2;
                paymentInfo.BillingCity = acBillingAddress.City;
                paymentInfo.BillingState = acBillingAddress.State;
                paymentInfo.BillingPostalCode = acBillingAddress.PostalCode;
                paymentInfo.BillingCountry = acBillingAddress.Country;

                paymentInfo.Amount = amount;
                paymentInfo.Email = registration.ConfirmationEmail;

                paymentInfo.FirstName = registration.FirstName;
                paymentInfo.LastName = registration.LastName;

                paymentInfo.Comment1 = string.Format( "{0} ({1})", registration.RegistrationInstance.Name, registration.RegistrationInstance.Account.GlCode );

                transaction = gateway.Charge( RegistrationTemplateState.FinancialGateway, paymentInfo, out errorMessage );
                if ( transaction != null )
                {
                    transaction.FinancialGatewayId = RegistrationTemplateState.FinancialGatewayId;
                    if ( transaction.FinancialPaymentDetail == null )
                    {
                        transaction.FinancialPaymentDetail = new FinancialPaymentDetail();
                    }
                    transaction.FinancialPaymentDetail.SetFromPaymentInfo( paymentInfo, gateway, rockContext, txnChanges );

                    dvCurrencyType = paymentInfo.CurrencyTypeValue;
                    dvCredCardType = paymentInfo.CreditCardTypeValue;

                    registrationChanges.Add( string.Format( "Processed payment of {0}.", amount.FormatAsCurrency() ) );
                }
            }
            else
            {
                errorMessage = string.Empty;
                transaction = new FinancialTransaction();
                transaction.FinancialPaymentDetail = new FinancialPaymentDetail();
                transaction.FinancialPaymentDetail.CurrencyTypeValueId = ddlCurrencyType.SelectedValueAsInt();
                transaction.FinancialPaymentDetail.CreditCardTypeValueId = ddlCreditCardType.SelectedValueAsInt();
                transaction.TransactionCode = tbTransactionCode.Text;

                registrationChanges.Add( string.Format( "Manually added payment of {0}.", amount.FormatAsCurrency() ) );
            }

            if ( transaction != null )
            {
                transaction.Summary = tbSummary.Text;

                History.EvaluateChange( txnChanges, "Transaction Code", string.Empty, transaction.TransactionCode );

                transaction.AuthorizedPersonAliasId = personAliasId;

                transaction.TransactionDateTime = RockDateTime.Now;
                History.EvaluateChange( txnChanges, "Date/Time", null, transaction.TransactionDateTime );

                if ( transaction.FinancialGatewayId.HasValue )
                {
                    History.EvaluateChange( txnChanges, "Gateway", string.Empty, RegistrationTemplateState.FinancialGateway.Name );
                }

                var txnType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_EVENT_REGISTRATION ) );
                transaction.TransactionTypeValueId = txnType.Id;
                History.EvaluateChange( txnChanges, "Type", string.Empty, txnType.Value );

                Guid sourceGuid = Guid.Empty;
                if ( Guid.TryParse( GetAttributeValue( "Source" ), out sourceGuid ) )
                {
                    var source = DefinedValueCache.Read( sourceGuid );
                    if ( source != null )
                    {
                        transaction.SourceTypeValueId = source.Id;
                        History.EvaluateChange( txnChanges, "Source", string.Empty, source.Value );
                    }
                }

                var transactionDetail = new FinancialTransactionDetail();
                transactionDetail.Amount = amount;
                transactionDetail.AccountId = registration.RegistrationInstance.AccountId.Value;
                transactionDetail.EntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Registration ) ).Id;
                transactionDetail.EntityId = registration.Id;
                transaction.TransactionDetails.Add( transactionDetail );

                History.EvaluateChange( txnChanges, registration.RegistrationInstance.Account.Name, 0.0M.FormatAsCurrency(), transactionDetail.Amount.FormatAsCurrency() );

                var batchService = new FinancialBatchService( rockContext );

                // Get the batch
                var batch = batchService.Get(
                    GetAttributeValue( "BatchNamePrefix" ),
                    dvCurrencyType,
                    dvCredCardType,
                    transaction.TransactionDateTime.Value,
                    RegistrationTemplateState.FinancialGateway.GetBatchTimeOffset() );

                var batchChanges = new List<string>();

                if ( batch.Id == 0 )
                {
                    batchChanges.Add( "Generated the batch" );
                    History.EvaluateChange( batchChanges, "Batch Name", string.Empty, batch.Name );
                    History.EvaluateChange( batchChanges, "Status", null, batch.Status );
                    History.EvaluateChange( batchChanges, "Start Date/Time", null, batch.BatchStartDateTime );
                    History.EvaluateChange( batchChanges, "End Date/Time", null, batch.BatchEndDateTime );
                }

                decimal newControlAmount = batch.ControlAmount + transaction.TotalAmount;
                History.EvaluateChange( batchChanges, "Control Amount", batch.ControlAmount.FormatAsCurrency(), newControlAmount.FormatAsCurrency() );
                batch.ControlAmount = newControlAmount;

                transaction.BatchId = batch.Id;
                batch.Transactions.Add( transaction );

                rockContext.SaveChanges();

                HistoryService.SaveChanges(
                    rockContext,
                    typeof( FinancialBatch ),
                    Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(),
                    batch.Id,
                    batchChanges
                );

                HistoryService.SaveChanges(
                    rockContext,
                    typeof( FinancialBatch ),
                    Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(),
                    batch.Id,
                    txnChanges,
                    CurrentPerson != null ? CurrentPerson.FullName : string.Empty,
                    typeof( FinancialTransaction ),
                    transaction.Id
                );

                HistoryService.SaveChanges(
                    rockContext,
                    typeof( Registration ),
                    Rock.SystemGuid.Category.HISTORY_EVENT_REGISTRATION.AsGuid(),
                    registration.Id,
                    registrationChanges
                );

                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the credit card information.
        /// </summary>
        /// <returns></returns>
        private CreditCardPaymentInfo GetCCInfo()
        {
            var cc = new CreditCardPaymentInfo( txtCreditCard.Text, txtCVV.Text, mypExpiration.SelectedDate.Value );
            cc.NameOnCard = _ccGateway.SplitNameOnCard ? txtCardFirstName.Text : txtCardName.Text;
            cc.LastNameOnCard = txtCardLastName.Text;

            if ( cbBillingAddress.Checked )
            {
                cc.BillingStreet = txtBillingStreet.Text;
                cc.BillingCity = txtBillingCity.Text;
                cc.BillingState = ddlBillingState.SelectedValue;
                cc.BillingZip = txtBillingZip.Text;
            }
            else
            {
                cc.BillingStreet = txtStreet.Text;
                cc.BillingCity = txtCity.Text;
                cc.BillingState = ddlState.SelectedValue;
                cc.BillingZip = txtZip.Text;
            }
            return cc;
        }