Information related to a scheduled payment frequency
Esempio n. 1
0
        /// <summary>
        /// Adds the scheduled payment.
        /// </summary>
        /// <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( PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage )
        {
            errorMessage = string.Empty;

            var scheduledTransaction = new FinancialScheduledTransaction();
            scheduledTransaction.TransactionCode = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            scheduledTransaction.GatewayScheduleId = "P" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            return scheduledTransaction;
        }
Esempio n. 2
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;

            var scheduledTransaction = new FinancialScheduledTransaction();
            scheduledTransaction.IsActive = true;
            scheduledTransaction.StartDate = schedule.StartDate;
            scheduledTransaction.NextPaymentDate = schedule.StartDate;
            scheduledTransaction.TransactionCode = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            scheduledTransaction.GatewayScheduleId = "P" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            scheduledTransaction.LastStatusUpdateDateTime = RockDateTime.Now;
            return scheduledTransaction;
        }
Esempio n. 3
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);
        }
Esempio n. 4
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;

            var scheduledTransaction = new FinancialScheduledTransaction();

            scheduledTransaction.IsActive                 = true;
            scheduledTransaction.StartDate                = schedule.StartDate;
            scheduledTransaction.NextPaymentDate          = schedule.StartDate;
            scheduledTransaction.TransactionCode          = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            scheduledTransaction.GatewayScheduleId        = "P" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF");
            scheduledTransaction.LastStatusUpdateDateTime = RockDateTime.Now;
            return(scheduledTransaction);
        }
Esempio n. 5
0
        private RecurringInfo GetRecurring( PaymentSchedule schedule )
        {
            var ppRecurringInfo = new RecurringInfo();

            ppRecurringInfo.ProfileName = schedule.PersonId.ToString();
            ppRecurringInfo.Start = schedule.StartDate.ToString( "MMddyyyy" );
            SetPayPeriod( ppRecurringInfo, schedule.TransactionFrequencyValue );

            return ppRecurringInfo;
        }
Esempio n. 6
0
        /// <summary>
        /// Adds the scheduled payment.
        /// </summary>
        /// <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( PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage )
        {
            errorMessage = string.Empty;

            var recurring = GetRecurring( schedule );

            if ( paymentInfo is CreditCardPaymentInfo )
            {
                recurring.OptionalTrx = "A";
            }

            var ppTransaction = new RecurringAddTransaction( GetUserInfo(), GetConnection(), GetInvoice( paymentInfo ), GetTender( paymentInfo ),
                recurring, PayflowUtility.RequestId );

            if ( paymentInfo is ReferencePaymentInfo )
            {
                var reference = paymentInfo as ReferencePaymentInfo;
                ppTransaction.OrigId = reference.TransactionCode;
            }
            var ppResponse = ppTransaction.SubmitTransaction();

            if ( ppResponse != null )
            {
                TransactionResponse txnResponse = ppResponse.TransactionResponse;
                if ( txnResponse != null )
                {
                    if ( txnResponse.Result == 0 ) // Success
                    {
                        RecurringResponse recurringResponse = ppResponse.RecurringResponse;

                        if ( recurringResponse != null )
                        {
                            var scheduledTransaction = new FinancialScheduledTransaction();
                            scheduledTransaction.TransactionCode = recurringResponse.TrxPNRef;
                            scheduledTransaction.GatewayScheduleId = recurringResponse.ProfileId;

                            GetScheduledPaymentStatus( scheduledTransaction, out errorMessage );
                            return scheduledTransaction;

                        }
                        else
                        {
                            errorMessage = "Invalid recurring response from the financial gateway";
                        }
                    }
                    else
                    {
                        errorMessage = string.Format( "[{0}] {1}", txnResponse.Result, txnResponse.RespMsg );
                    }
                }
                else
                {
                    errorMessage = "Invalid transaction response from the financial gateway";
                }
            }
            else
            {
                errorMessage = "Invalid response from the financial gateway.";
            }

            return null;
        }
Esempio n. 7
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 abstract FinancialScheduledTransaction AddScheduledPayment(FinancialGateway financialGateway, PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage);
Esempio n. 8
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 = "The Payment Gateway only supports adding scheduled payment using a three-step process.";
     return null;
 }
Esempio n. 9
0
        private void SaveScheduledTransaction( FinancialGateway financialGateway, GatewayComponent gateway, Person person, PaymentInfo paymentInfo, PaymentSchedule schedule, FinancialScheduledTransaction scheduledTransaction, RockContext rockContext )
        {
            scheduledTransaction.TransactionFrequencyValueId = schedule.TransactionFrequencyValue.Id;
            scheduledTransaction.StartDate = schedule.StartDate;
            scheduledTransaction.AuthorizedPersonAliasId = person.PrimaryAliasId.Value;
            scheduledTransaction.FinancialGatewayId = financialGateway.Id;

            if ( scheduledTransaction.FinancialPaymentDetail == null )
            {
                scheduledTransaction.FinancialPaymentDetail = new FinancialPaymentDetail();
            }
            scheduledTransaction.FinancialPaymentDetail.SetFromPaymentInfo( paymentInfo, gateway, rockContext );

            Guid sourceGuid = Guid.Empty;
            if ( Guid.TryParse( GetAttributeValue( "Source" ), out sourceGuid ) )
            {
                var source = DefinedValueCache.Read( sourceGuid );
                if ( source != null )
                {
                    scheduledTransaction.SourceTypeValueId = source.Id;
                }
            }

            var changeSummary = new StringBuilder();
            changeSummary.AppendFormat( "{0} starting {1}", schedule.TransactionFrequencyValue.Value, schedule.StartDate.ToShortDateString() );
            changeSummary.AppendLine();
            changeSummary.Append( paymentInfo.CurrencyTypeValue.Value );
            if ( paymentInfo.CreditCardTypeValue != null )
            {
                changeSummary.AppendFormat( " - {0}", paymentInfo.CreditCardTypeValue.Value );
            }
            changeSummary.AppendFormat( " {0}", paymentInfo.MaskedNumber );
            changeSummary.AppendLine();

            foreach ( var account in SelectedAccounts.Where( a => a.Amount > 0 ) )
            {
                var transactionDetail = new FinancialScheduledTransactionDetail();
                transactionDetail.Amount = account.Amount;
                transactionDetail.AccountId = account.Id;
                scheduledTransaction.ScheduledTransactionDetails.Add( transactionDetail );
                changeSummary.AppendFormat( "{0}: {1}", account.Name, account.Amount.FormatAsCurrency() );
                changeSummary.AppendLine();
            }

            if ( !string.IsNullOrWhiteSpace( paymentInfo.Comment1 ) )
            {
                changeSummary.Append( paymentInfo.Comment1 );
                changeSummary.AppendLine();
            }

            var transactionService = new FinancialScheduledTransactionService( rockContext );
            transactionService.Add( scheduledTransaction );
            rockContext.SaveChanges();

            // If this is a transfer, now we can delete the old transaction
            if ( _scheduledTransactionToBeTransferred != null )
            {
                DeleteOldTransaction( _scheduledTransactionToBeTransferred.Id );
            }

            // Add a note about the change
            var noteType = NoteTypeCache.Read( Rock.SystemGuid.NoteType.SCHEDULED_TRANSACTION_NOTE.AsGuid() );
            if ( noteType != null )
            {
                var noteService = new NoteService( rockContext );
                var note = new Note();
                note.NoteTypeId = noteType.Id;
                note.EntityId = scheduledTransaction.Id;
                note.Caption = "Created Transaction";
                note.Text = changeSummary.ToString();
                noteService.Add( note );
            }
            rockContext.SaveChanges();

            ScheduleId = scheduledTransaction.GatewayScheduleId;
            TransactionCode = scheduledTransaction.TransactionCode;
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the payment frequency.
        /// </summary>
        /// <param name="schedule">The schedule.</param>
        /// <returns></returns>
        private string GetFrequency( PaymentSchedule schedule )
        {
            string frequency = string.Empty;

            var selectedFrequencyGuid = schedule.TransactionFrequencyValue.Guid.ToString().ToUpper();
            switch ( selectedFrequencyGuid )
            {
                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME:
                    frequency = "ON-DEMAND";
                    break;

                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_WEEKLY:
                    frequency = "WEEKLY";
                    break;

                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_BIWEEKLY:
                    frequency = "BI-WEEKLY";
                    break;

                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_TWICEMONTHLY:
                    frequency = "SEMI-MONTHLY";
                    break;

                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_MONTHLY:
                    frequency = "MONTHLY";
                    break;

                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_YEARLY:
                    frequency = "ANNUALLY";
                    break;
            }

            return frequency;
        }
Esempio n. 11
0
        /// <summary>
        /// Adds the scheduled payment.
        /// </summary>
        /// <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;
            RequestMessage request = GetPaymentInfo( financialGateway, paymentInfo );

            if ( request == null )
            {
                errorMessage = "Payment type not implemented";
                return null;
            }

            if ( request.recurringSubscriptionInfo == null )
            {
                request.recurringSubscriptionInfo = new RecurringSubscriptionInfo();
            }

            request.recurringSubscriptionInfo.startDate = GetStartDate( schedule );
            request.recurringSubscriptionInfo.frequency = GetFrequency( schedule );
            request.recurringSubscriptionInfo.amount = paymentInfo.Amount.ToString();
            request.paySubscriptionCreateService = new PaySubscriptionCreateService();
            request.paySubscriptionCreateService.run = "true";
            request.purchaseTotals = GetTotals();
            request.billTo = GetBillTo( paymentInfo );
            request.item = GetItems( paymentInfo );

            request.subscription = new Subscription();
            if ( !paymentInfo.CurrencyTypeValue.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ) )
            {
                request.subscription.paymentMethod = "check";
            }

            if ( paymentInfo is ReferencePaymentInfo )
            {
                request.paySubscriptionCreateService.paymentRequestID = ( (ReferencePaymentInfo)paymentInfo ).TransactionCode;
            }

            // Schedule the payment
            ReplyMessage reply = SubmitTransaction( financialGateway, request, out errorMessage );
            if ( reply != null && reply.reasonCode.Equals( GATEWAY_RESPONSE_SUCCESS ) )
            {
                var transactionGuid = new Guid( reply.merchantReferenceCode );
                var scheduledTransaction = new FinancialScheduledTransaction { Guid = transactionGuid };
                scheduledTransaction.TransactionCode = reply.paySubscriptionCreateReply.subscriptionID;
                scheduledTransaction.GatewayScheduleId = reply.paySubscriptionCreateReply.subscriptionID;
                scheduledTransaction.FinancialGateway = financialGateway;
                scheduledTransaction.FinancialGatewayId = financialGateway.Id;
                GetScheduledPaymentStatus( scheduledTransaction, out errorMessage );
                return scheduledTransaction;
            }
            else if ( string.IsNullOrEmpty( errorMessage ) )
            {
                errorMessage = string.Format( "Your order was not approved.{0}", ProcessError( reply ) );
            }

            return null;
        }
Esempio n. 12
0
 /// <summary>
 /// Performs the first step of adding a new payment schedule
 /// </summary>
 /// <param name="financialGateway">The financial gateway.</param>
 /// <param name="schedule">The schedule.</param>
 /// <param name="paymentInfo">The payment information.</param>
 /// <param name="errorMessage">The error message.</param>
 /// <returns></returns>
 public abstract string AddScheduledPaymentStep1( FinancialGateway financialGateway, PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage );
 /// <summary>
 /// Adds the scheduled payment.
 /// </summary>
 /// <param name="schedule">The schedule.</param>
 /// <param name="paymentInfo">The payment info.</param>
 /// <param name="errorMessage">The error message.</param>
 /// <returns></returns>
 public abstract FinancialScheduledTransaction AddScheduledPayment( PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage );
Esempio n. 14
0
        /// <summary>
        /// Creates a scheduled transaction plan XML element
        /// </summary>
        /// <param name="schedule">The schedule.</param>
        /// <param name="paymentInfo">The payment information.</param>
        /// <returns></returns>
        private XElement GetPlan( PaymentSchedule schedule, PaymentInfo paymentInfo )
        {
            var selectedFrequencyGuid = schedule.TransactionFrequencyValue.Guid.ToString().ToUpper();

            if ( selectedFrequencyGuid == Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME )
            {
                // Make sure number of payments is set to 1 for one-time future payments
                schedule.NumberOfPayments = 1;
            }

            XElement planElement = new XElement( "plan",
                new XElement( "payments", schedule.NumberOfPayments.HasValue ? schedule.NumberOfPayments.Value.ToString() : "0" ),
                new XElement( "amount", paymentInfo.Amount.ToString() ) );

            switch ( selectedFrequencyGuid )
            {
                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME:
                    planElement.Add( new XElement( "month-frequency", "12" ) );
                    planElement.Add( new XElement( "day-of-month", schedule.StartDate.Day.ToString() ) );
                    break;
                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_WEEKLY:
                    planElement.Add( new XElement( "day-frequency", "7" ) );
                    break;
                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_BIWEEKLY:
                    planElement.Add( new XElement( "day-frequency", "14" ) );
                    break;
                case Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_MONTHLY:
                    planElement.Add( new XElement( "month-frequency", "1" ) );
                    planElement.Add( new XElement( "day-of-month", schedule.StartDate.Day.ToString() ) );
                    break;
            }

            return planElement;
        }
Esempio n. 15
0
        /// <summary>
        /// Performs the first step of adding a new payment schedule
        /// </summary>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="schedule">The schedule.</param>
        /// <param name="paymentInfo">The payment information.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">paymentInfo</exception>
        public override string AddScheduledPaymentStep1( FinancialGateway financialGateway, PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage )
        {
            errorMessage = string.Empty;

            try
            {
                if ( paymentInfo == null )
                {
                    throw new ArgumentNullException( "paymentInfo" );
                }

                var rootElement = GetRoot( financialGateway, "add-subscription" );

                rootElement.Add(
                    new XElement( "start-date", schedule.StartDate.ToString( "yyyyMMdd" ) ),
                    new XElement( "order-description", paymentInfo.Description ),
                    new XElement( "currency", "USD" ),
                    new XElement( "tax-amount", "0.00" ) );

                bool isReferencePayment = ( paymentInfo is ReferencePaymentInfo );
                if ( isReferencePayment )
                {
                    var reference = paymentInfo as ReferencePaymentInfo;
                    rootElement.Add( new XElement( "customer-vault-id", reference.ReferenceNumber ) );
                }

                if ( paymentInfo.AdditionalParameters != null )
                {
                    foreach ( var keyValue in paymentInfo.AdditionalParameters )
                    {
                        XElement xElement = new XElement( keyValue.Key, keyValue.Value );
                        rootElement.Add( xElement );
                    }
                }

                rootElement.Add( GetPlan( schedule, paymentInfo ) );

                rootElement.Add( GetBilling( paymentInfo ) );

                XDocument xdoc = new XDocument( new XDeclaration( "1.0", "UTF-8", "yes" ), rootElement );
                var result = PostToGateway( financialGateway, xdoc );

                if ( result == null )
                {
                    errorMessage = "Invalid Response from NMI!";
                    return null;
                }

                if ( result.GetValueOrNull( "result" ) != "1" )
                {
                    errorMessage = result.GetValueOrNull( "result-text" );
                    return null;
                }

                return result.GetValueOrNull( "form-url" );
            }

            catch ( WebException webException )
            {
                string message = GetResponseMessage( webException.Response.GetResponseStream() );
                errorMessage = webException.Message + " - " + message;
                return null;
            }

            catch ( Exception ex )
            {
                errorMessage = ex.Message;
                return null;
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Performs the first step of adding a new payment schedule
 /// </summary>
 /// <param name="financialGateway">The financial gateway.</param>
 /// <param name="schedule">The schedule.</param>
 /// <param name="paymentInfo">The payment information.</param>
 /// <param name="errorMessage">The error message.</param>
 /// <returns></returns>
 public abstract string AddScheduledPaymentStep1(FinancialGateway financialGateway, PaymentSchedule schedule, PaymentInfo paymentInfo, out string errorMessage);
Esempio n. 17
0
        /// <summary>
        /// Gets the payment schedule.
        /// </summary>
        /// <returns></returns>
        private PaymentSchedule GetSchedule()
        {
            // Figure out if this is a one-time transaction or a future scheduled transaction
            if ( GetAttributeValue( "AllowScheduled" ).AsBoolean() )
            {
                // If a one-time gift was selected for today's date, then treat as a onetime immediate transaction (not scheduled)
                int oneTimeFrequencyId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME ).Id;
                if ( btnFrequency.SelectedValue == oneTimeFrequencyId.ToString() && dtpStartDate.SelectedDate <= RockDateTime.Today )
                {
                    // one-time immediate payment
                    return null;
                }

                var schedule = new PaymentSchedule();
                schedule.TransactionFrequencyValue = DefinedValueCache.Read( btnFrequency.SelectedValueAsId().Value );
                if ( dtpStartDate.SelectedDate.HasValue && dtpStartDate.SelectedDate > RockDateTime.Today )
                {
                    schedule.StartDate = dtpStartDate.SelectedDate.Value;
                }
                else
                {
                    schedule.StartDate = DateTime.MinValue;
                }

                return schedule;
            }

            return null;
        }
Esempio n. 18
0
        /// <summary>
        /// Gets the payment start date.
        /// </summary>
        /// <param name="schedule">The schedule.</param>
        /// <returns></returns>
        private string GetStartDate( PaymentSchedule schedule )
        {
            string startDate = string.Empty;

            if ( !schedule.TransactionFrequencyValue.Guid.ToString().Equals( Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_TWICEMONTHLY, StringComparison.InvariantCultureIgnoreCase ) )
            {
                startDate = schedule.StartDate.ToString( "yyyyMMdd" );
            }
            else
            {
                // determine the next valid day on a twice monthly schedule;
                // today's date is not a valid option (enforced in UI)
                var dateOffset = schedule.StartDate.AddDays( -1 );
                if ( dateOffset.Day >= 15 )
                {
                    dateOffset = new DateTime( dateOffset.Year, dateOffset.Month, 1 ).AddMonths( 1 );
                }
                else
                {
                    dateOffset = new DateTime( dateOffset.Year, dateOffset.Month, 15 );
                }

                startDate = dateOffset.ToString( "yyyyMMdd" );
            }

            return startDate;
        }
Esempio n. 19
0
        private void ShowSuccess( GatewayComponent gatewayComponent, Person person, PaymentInfo paymentInfo, PaymentSchedule schedule, FinancialPaymentDetail paymentDetail, RockContext rockContext )
        {
            tdTransactionCodeReceipt.Description = TransactionCode;
            tdTransactionCodeReceipt.Visible = !string.IsNullOrWhiteSpace( TransactionCode );

            tdScheduleId.Description = ScheduleId;
            tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId );

            tdNameReceipt.Description = paymentInfo.FullName;
            tdPhoneReceipt.Description = paymentInfo.Phone;
            tdEmailReceipt.Description = paymentInfo.Email;
            tdAddressReceipt.Description = string.Format( "{0} {1}, {2} {3}", paymentInfo.Street1, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode );

            rptAccountListReceipt.DataSource = SelectedAccounts.Where( a => a.Amount != 0 );
            rptAccountListReceipt.DataBind();

            tdTotalReceipt.Description = paymentInfo.Amount.ToString( "C" );

            tdPaymentMethodReceipt.Description = paymentInfo.CurrencyTypeValue.Description;

            string acctNumber = paymentInfo.MaskedNumber;
            if ( string.IsNullOrWhiteSpace( acctNumber ) && paymentDetail != null && !string.IsNullOrWhiteSpace( paymentDetail.AccountNumberMasked ) )
            {
                acctNumber = paymentDetail.AccountNumberMasked;
            }
            tdAccountNumberReceipt.Description = acctNumber;
            tdAccountNumberReceipt.Visible = !string.IsNullOrWhiteSpace( acctNumber );

            tdWhenReceipt.Description = schedule != null ? schedule.ToString() : "Today";

            // If there was a transaction code returned and this was not already created from a previous saved account,
            // show the option to save the account.
            if ( !( paymentInfo is ReferencePaymentInfo ) && !string.IsNullOrWhiteSpace( TransactionCode ) && gatewayComponent.SupportsSavedAccount( paymentInfo.CurrencyTypeValue ) )
            {
                cbSaveAccount.Visible = true;
                pnlSaveAccount.Visible = true;
                txtSaveAccount.Visible = true;

                // If current person does not have a login, have them create a username and password
                phCreateLogin.Visible = !new UserLoginService( rockContext ).GetByPersonId( person.Id ).Any();
            }
            else
            {
                pnlSaveAccount.Visible = false;
            }
        }
        /// <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";
                return(scheduledTransaction);
            }

            return(null);
        }