/// <summary> /// Shows the details. /// </summary> private void ShowDetails() { var rockContext = new RockContext(); var scheduledTransaction = this.GetFinancialScheduledTransaction(rockContext); if (scheduledTransaction == null) { // Note: Also verified in OnInit ShowConfigurationMessage(NotificationBoxType.Warning, "Warning", "Scheduled Transaction not found."); return; } var financialScheduledTransactionService = new FinancialScheduledTransactionService(rockContext); string errorMessages; if (!financialScheduledTransactionService.GetStatus(scheduledTransaction, out errorMessages)) { ShowConfigurationMessage(NotificationBoxType.Danger, "Error", errorMessages); return; } hfScheduledTransactionGuid.Value = scheduledTransaction.Guid.ToString(); List <int> selectableAccountIds = new FinancialAccountService(rockContext).GetByGuids(this.GetAttributeValues(AttributeKey.AccountsToDisplay).AsGuidList()).Select(a => a.Id).ToList(); CampusAccountAmountPicker.AccountIdAmount[] accountAmounts = scheduledTransaction.ScheduledTransactionDetails.Select(a => new CampusAccountAmountPicker.AccountIdAmount(a.AccountId, a.Amount)).ToArray(); // if the scheduledTransaction already has Multiple Account, enabled multi account mode. Otherwise, only enabled multi account based on the block setting. var hasMultipleAccounts = accountAmounts.Length > 1; bool enableMultiAccount = hasMultipleAccounts || this.GetAttributeValue(AttributeKey.EnableMultiAccount).AsBoolean(); if (enableMultiAccount) { caapPromptForAccountAmounts.AmountEntryMode = CampusAccountAmountPicker.AccountAmountEntryMode.MultipleAccounts; } else { caapPromptForAccountAmounts.AmountEntryMode = CampusAccountAmountPicker.AccountAmountEntryMode.SingleAccount; } caapPromptForAccountAmounts.AskForCampusIfKnown = this.GetAttributeValue(AttributeKey.AskForCampusIfKnown).AsBoolean(); caapPromptForAccountAmounts.SelectableAccountIds = selectableAccountIds.ToArray(); if (!caapPromptForAccountAmounts.SelectableAccountIds.Any()) { ShowConfigurationMessage(NotificationBoxType.Warning, "Configuration", "At least one Financial Account must be selected in the configuration for this block."); pnlPromptForChanges.Visible = false; return; } if (this.FinancialGateway == null) { ShowConfigurationMessage(NotificationBoxType.Warning, "Configuration", "Unable to determine the financial gateway for this scheduled transaction."); pnlPromptForChanges.Visible = false; return; } if (this.FinancialGatewayComponent == null || !(this.FinancialGatewayComponent is IHostedGatewayComponent)) { ShowConfigurationMessage(NotificationBoxType.Danger, "Configuration", "This page is not configured to allow edits for the payment gateway associated with the selected transaction."); pnlPromptForChanges.Visible = false; return; } caapPromptForAccountAmounts.AccountAmounts = accountAmounts; var targetPerson = scheduledTransaction.AuthorizedPersonAlias.Person; SetAccountPickerCampus(targetPerson); int oneTimeFrequencyId = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME.AsGuid()) ?? 0; ddlFrequency.Items.Clear(); var supportedFrequencies = this.FinancialGatewayComponent.SupportedPaymentSchedules; foreach (var supportedFrequency in supportedFrequencies) { // If this isn't a one-time scheduled transaction, don't allow changing scheduled transaction to a one-time, if (scheduledTransaction.TransactionFrequencyValueId == oneTimeFrequencyId || supportedFrequency.Id != oneTimeFrequencyId) { ddlFrequency.Items.Add(new ListItem(supportedFrequency.Value, supportedFrequency.Id.ToString())); } } ddlFrequency.SetValue(scheduledTransaction.TransactionFrequencyValueId); /* 2020-02-26 MDP: Payment prompt behavior.. * - No Saved Accounts * - Show text with existing payment method with a 'Change' link. * - If 'Change' is clicked, existing payment info prompt will disappear and hosted payment will be displayed * - Has Saved Accounts * - Show RadioButtons with first item with the existing payment as the option, followed by saved accounts * - Then under the RadioButtons show a 'Add Method'. * - If 'Add Method' is clicked, RadioButtons will disappear and hosted payment will be displayed */ string paymentName; if (scheduledTransaction.FinancialPaymentDetail.FinancialPersonSavedAccountId.HasValue) { paymentName = scheduledTransaction.FinancialPaymentDetail.FinancialPersonSavedAccount.Name; } else { paymentName = scheduledTransaction.FinancialPaymentDetail.CurrencyTypeValue?.Value; } string existingPaymentInfoDisplayText; if (scheduledTransaction.FinancialPaymentDetail.ExpirationDate.IsNotNullOrWhiteSpace()) { existingPaymentInfoDisplayText = $"Existing Payment Method - {paymentName} ({scheduledTransaction.FinancialPaymentDetail.AccountNumberMasked} Expires: {scheduledTransaction.FinancialPaymentDetail.ExpirationDate})"; } else { existingPaymentInfoDisplayText = $"Existing Payment Method - {paymentName} ({scheduledTransaction.FinancialPaymentDetail.AccountNumberMasked})"; } lUseExistingPaymentMethodNoSavedAccounts.Text = existingPaymentInfoDisplayText; var personSavedAccountList = GetSavedAccounts(); pnlHostedPaymentControl.Visible = false; if (personSavedAccountList.Any()) { pnlUseExistingPaymentWithSavedAccounts.Visible = true; pnlUseExistingPaymentNoSavedAccounts.Visible = false; BindPersonSavedAccounts(personSavedAccountList); rblExistingPaymentOrPersonSavedAccount.Items.Insert(0, new ListItem(existingPaymentInfoDisplayText, "0")); // default to using existing payment method rblExistingPaymentOrPersonSavedAccount.SetValue(0); } else { // no saved account, so just prompt for payment info (or using existing payment info) pnlUseExistingPaymentNoSavedAccounts.Visible = true; pnlUseExistingPaymentWithSavedAccounts.Visible = false; } dtpStartDate.SelectedDate = scheduledTransaction.NextPaymentDate; // NOTE: Depending on the Gateway, the earliest date could be more than 1-2+ days in the future var earliestScheduledStartDate = FinancialGatewayComponent.GetEarliestScheduledStartDate(FinancialGateway); if (dtpStartDate.SelectedDate.HasValue && dtpStartDate.SelectedDate.Value < earliestScheduledStartDate) { dtpStartDate.SelectedDate = earliestScheduledStartDate; } var person = scheduledTransaction.AuthorizedPersonAlias.Person; Location billingLocation = null; // default to the billing location of the scheduled transaction, or the mailing location if unable to get a billing location from the scheduled transaction. if (scheduledTransaction.FinancialPaymentDetail != null) { billingLocation = scheduledTransaction.FinancialPaymentDetail.BillingLocation; } if (billingLocation == null) { billingLocation = person.GetMailingLocation(); } acBillingAddress.SetValues(billingLocation); }
/// <summary> /// Shows the details. /// </summary> private void ShowDetails() { var rockContext = new RockContext(); var scheduledTransaction = this.GetFinancialScheduledTransaction(rockContext); if (scheduledTransaction == null) { // Note: Also verified in OnInit ShowConfigurationMessage(NotificationBoxType.Warning, "Warning", "Scheduled Transaction not found."); return; } hfScheduledTransactionId.Value = scheduledTransaction.Id.ToString(); List <int> selectableAccountIds = new FinancialAccountService(rockContext).GetByGuids(this.GetAttributeValues(AttributeKey.AccountsToDisplay).AsGuidList()).Select(a => a.Id).ToList(); CampusAccountAmountPicker.AccountIdAmount[] accountAmounts = scheduledTransaction.ScheduledTransactionDetails.Select(a => new CampusAccountAmountPicker.AccountIdAmount(a.AccountId, a.Amount)).ToArray(); // if the scheduledTransaction already has Multiple Account, enabled multi account mode. Otherwise, only enabled multi account based on the block setting. var hasMultipleAccounts = accountAmounts.Length > 1; bool enableMultiAccount = hasMultipleAccounts || this.GetAttributeValue(AttributeKey.EnableMultiAccount).AsBoolean(); if (enableMultiAccount) { caapPromptForAccountAmounts.AmountEntryMode = CampusAccountAmountPicker.AccountAmountEntryMode.MultipleAccounts; } else { caapPromptForAccountAmounts.AmountEntryMode = CampusAccountAmountPicker.AccountAmountEntryMode.SingleAccount; } caapPromptForAccountAmounts.AskForCampusIfKnown = this.GetAttributeValue(AttributeKey.AskForCampusIfKnown).AsBoolean(); caapPromptForAccountAmounts.SelectableAccountIds = selectableAccountIds.ToArray(); if (!caapPromptForAccountAmounts.SelectableAccountIds.Any()) { ShowConfigurationMessage(NotificationBoxType.Warning, "Configuration", "At least one Financial Account must be selected in the configuration for this block."); pnlPromptForChanges.Visible = false; return; } caapPromptForAccountAmounts.AccountAmounts = accountAmounts; var targetPerson = scheduledTransaction.AuthorizedPersonAlias.Person; SetAccountPickerCampus(targetPerson); int oneTimeFrequencyId = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_ONE_TIME.AsGuid()) ?? 0; ddlFrequency.Items.Clear(); var supportedFrequencies = this.FinancialGatewayComponent.SupportedPaymentSchedules; foreach (var supportedFrequency in supportedFrequencies.Where(a => a.Id != oneTimeFrequencyId)) { ddlFrequency.Items.Add(new ListItem(supportedFrequency.Value, supportedFrequency.Id.ToString())); } ddlFrequency.SetValue(scheduledTransaction.TransactionFrequencyValueId); BindPersonSavedAccounts(); dtpStartDate.SelectedDate = scheduledTransaction.NextPaymentDate; // NOTE: Depending on the Gateway, the earliest date could be more than 1-2+ days in the future var earliestScheduledStartDate = FinancialGatewayComponent.GetEarliestScheduledStartDate(FinancialGateway); if (dtpStartDate.SelectedDate.HasValue && dtpStartDate.SelectedDate.Value < earliestScheduledStartDate) { dtpStartDate.SelectedDate = earliestScheduledStartDate; } var person = scheduledTransaction.AuthorizedPersonAlias.Person; Location billingLocation = null; // default to the billing location of the scheduled transaction, or the mailing location if unable to get a billing location from the scheduled transaction. if (scheduledTransaction.FinancialPaymentDetail != null) { billingLocation = scheduledTransaction.FinancialPaymentDetail.BillingLocation; } if (billingLocation == null) { billingLocation = person.GetMailingLocation(); } acBillingAddress.SetValues(billingLocation); }