public static string GetClusterPasswordFromPayloadObject( Microsoft.WindowsAzure.Management.HDInsight.Contracts.May2014.ClusterCreateParameters cluster) { GatewayComponent gateway = cluster.Components.OfType <GatewayComponent>().Single(); return(gateway.RestAuthCredential.Password); }
/// <summary> /// Loads the items. /// </summary> /// <param name="showAll">if set to <c>true</c> [show all].</param> private void LoadItems(bool showAll) { int?selectedItem = this.SelectedValueAsInt(); this.Items.Clear(); this.Items.Add(new ListItem()); using (var rockContext = new RockContext()) { foreach (var gateway in new FinancialGatewayService(rockContext) .Queryable().AsNoTracking() .Where(g => g.EntityTypeId.HasValue) .OrderBy(g => g.Name) .ToList()) { var entityType = EntityTypeCache.Get(gateway.EntityTypeId.Value); GatewayComponent component = GatewayContainer.GetComponent(entityType.Name); if (showAll || (gateway.IsActive && component != null && component.IsActive && component.SupportsRockInitiatedTransactions)) { this.Items.Add(new ListItem(gateway.Name, gateway.Id.ToString())); } } } this.SetValue(selectedItem); }
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.ToString(); tdScheduleId.Visible = ScheduleId.HasValue; 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 = GetSelectedAccounts().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"; pnlConfirmation.Visible = false; pnlSuccess.Visible = true; }
/// <summary> /// Sets from payment information. /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <param name="paymentGateway">The payment gateway.</param> /// <param name="rockContext">The rock context.</param> /// <param name="changes">The changes.</param> public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext, List <string> changes = null) { if (changes != null) { History.EvaluateChange(changes, "Account Number", AccountNumberMasked, paymentInfo.MaskedNumber); History.EvaluateChange(changes, "Currency Type", DefinedValueCache.GetName(CurrencyTypeValueId), paymentInfo.CurrencyTypeValue != null ? paymentInfo.CurrencyTypeValue.Value : string.Empty); History.EvaluateChange(changes, "Credit Card Type", DefinedValueCache.GetName(CreditCardTypeValueId), paymentInfo.CreditCardTypeValue != null ? paymentInfo.CreditCardTypeValue.Value : string.Empty); } AccountNumberMasked = paymentInfo.MaskedNumber; CurrencyTypeValueId = paymentInfo.CurrencyTypeValue != null ? paymentInfo.CurrencyTypeValue.Id : (int?)null; CreditCardTypeValueId = paymentInfo.CreditCardTypeValue != null ? paymentInfo.CreditCardTypeValue.Id : (int?)null; if (paymentInfo is CreditCardPaymentInfo) { var ccPaymentInfo = (CreditCardPaymentInfo)paymentInfo; string nameOnCard = paymentGateway.SplitNameOnCard ? ccPaymentInfo.NameOnCard + " " + ccPaymentInfo.LastNameOnCard : ccPaymentInfo.NameOnCard; var newLocation = new LocationService(rockContext).Get( ccPaymentInfo.BillingStreet1, ccPaymentInfo.BillingStreet2, ccPaymentInfo.BillingCity, ccPaymentInfo.BillingState, ccPaymentInfo.BillingPostalCode, ccPaymentInfo.BillingCountry); if (changes != null) { string oldNameOnCard = Encryption.DecryptString(NameOnCardEncrypted); History.EvaluateChange(changes, "Name on Card", oldNameOnCard, nameOnCard); History.EvaluateChange(changes, "Expiration Month", Encryption.DecryptString(ExpirationMonthEncrypted), ccPaymentInfo.ExpirationDate.Month.ToString()); History.EvaluateChange(changes, "Expiration Year", Encryption.DecryptString(ExpirationYearEncrypted), ccPaymentInfo.ExpirationDate.Year.ToString()); History.EvaluateChange(changes, "Billing Location", BillingLocation != null ? BillingLocation.ToString() : string.Empty, newLocation != null ? newLocation.ToString() : string.Empty); } NameOnCardEncrypted = Encryption.EncryptString(nameOnCard); ExpirationMonthEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Month.ToString()); ExpirationYearEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Year.ToString()); BillingLocationId = newLocation != null ? newLocation.Id : (int?)null; } else if (paymentInfo is SwipePaymentInfo) { var swipePaymentInfo = (SwipePaymentInfo)paymentInfo; if (changes != null) { string oldNameOnCard = Encryption.DecryptString(NameOnCardEncrypted); History.EvaluateChange(changes, "Name on Card", oldNameOnCard, swipePaymentInfo.NameOnCard); History.EvaluateChange(changes, "Expiration Month", Encryption.DecryptString(ExpirationMonthEncrypted), swipePaymentInfo.ExpirationDate.Month.ToString()); History.EvaluateChange(changes, "Expiration Year", Encryption.DecryptString(ExpirationYearEncrypted), swipePaymentInfo.ExpirationDate.Year.ToString()); } NameOnCardEncrypted = Encryption.EncryptString(swipePaymentInfo.NameOnCard); ExpirationMonthEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Month.ToString()); ExpirationYearEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Year.ToString()); } }
protected override void OnInit(EventArgs e) { using (var rockContext = new RockContext()) { _payPalExpressGateway = GetGateway(rockContext, "PayPalExpressGateway"); _payPalExpressGatewayComponent = GetGatewayComponent(rockContext, _payPalExpressGateway); SetTargetPerson(rockContext); } if (PageParameter("token") != String.Empty && PageParameter("PayerID") != string.Empty) { String errorMessage = String.Empty; PaymentInfo paymentInfo = GetPaymentInfo(); if (errorMessage != string.Empty) { ShowMessage(NotificationBoxType.Danger, "PayPal Error", errorMessage); } else { tdNameConfirm.Description = paymentInfo.FullName; tdPhoneConfirm.Description = paymentInfo.Phone; tdEmailConfirm.Description = paymentInfo.Email; tdAddressConfirm.Description = string.Format("{0} {1}, {2} {3}", paymentInfo.Street1, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode); tdTotalConfirm.Description = paymentInfo.Amount.ToString("C"); tdPaymentMethodConfirm.Description = paymentInfo.CurrencyTypeValue.Description; tdAccountNumberConfirm.Description = paymentInfo.MaskedNumber; tdAccountNumberConfirm.Visible = !string.IsNullOrWhiteSpace(paymentInfo.MaskedNumber); tdWhenConfirm.Description = "Today"; rptAccountListConfirmation.DataSource = GetSelectedAccounts().Where(a => a.Amount != 0); rptAccountListConfirmation.DataBind(); } pnlConfirmation.Visible = true; pnlDupWarning.Visible = false; } else { RockTransactionEntry = (RockWeb.Blocks.Finance.TransactionEntry)LoadControl("~/Blocks/Finance/TransactionEntry.ascx"); RockTransactionEntry.Page = RockPage; RockTransactionEntry.SetBlock(PageCache, BlockCache); Controls.Add(RockTransactionEntry); RegisterScript(); } }
/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { try { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; string gatewayGuid = dataMap.GetString("PaymentGateway"); if (!string.IsNullOrWhiteSpace(gatewayGuid)) { GatewayComponent gateway = GatewayContainer.GetComponent(gatewayGuid); if (gateway != null) { int daysBack = dataMap.GetString("DaysBack").AsIntegerOrNull() ?? 1; DateTime today = RockDateTime.Today; TimeSpan days = new TimeSpan(daysBack, 0, 0, 0); DateTime endDateTime = today.Add(gateway.BatchTimeOffset); endDateTime = RockDateTime.Now.CompareTo(endDateTime) < 0 ? endDateTime.AddDays(-1) : today; DateTime startDateTime = endDateTime.Subtract(days); string errorMessage = string.Empty; var payments = gateway.GetPayments(startDateTime, endDateTime, out errorMessage); if (string.IsNullOrWhiteSpace(errorMessage)) { string batchNamePrefix = dataMap.GetString("BatchNamePrefix"); FinancialScheduledTransactionService.ProcessPayments(gateway, batchNamePrefix, payments); } else { throw new Exception(errorMessage); } } } } catch (Exception ex) { ExceptionLogService.LogException(ex, null); } }
public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext, List <string> changes) { this.SetFromPaymentInfo(paymentInfo, paymentGateway, rockContext); }
/// <summary> /// Sets any payment information that the <seealso cref="GatewayComponent">paymentGateway</seealso> didn't set /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <param name="paymentGateway">The payment gateway.</param> /// <param name="rockContext">The rock context.</param> public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext) { /* 2020-08-27 MDP * This method should only update values haven't been set yet. So * 1) Make sure paymentInfo has the data (isn't null or whitespace) * 2) Don't overwrite data in this (FinancialPaymentDetail) that already has the data set. */ if (AccountNumberMasked.IsNullOrWhiteSpace() && paymentInfo.MaskedNumber.IsNotNullOrWhiteSpace()) { AccountNumberMasked = paymentInfo.MaskedNumber; } if (paymentInfo is ReferencePaymentInfo referencePaymentInfo) { if (GatewayPersonIdentifier.IsNullOrWhiteSpace()) { GatewayPersonIdentifier = referencePaymentInfo.GatewayPersonIdentifier; } if (!FinancialPersonSavedAccountId.HasValue) { FinancialPersonSavedAccountId = referencePaymentInfo.FinancialPersonSavedAccountId; } } if (!CurrencyTypeValueId.HasValue && paymentInfo.CurrencyTypeValue != null) { CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; } if (!CreditCardTypeValueId.HasValue && paymentInfo.CreditCardTypeValue != null) { CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id; } if (paymentInfo is CreditCardPaymentInfo) { var ccPaymentInfo = ( CreditCardPaymentInfo )paymentInfo; string nameOnCard = paymentGateway.SplitNameOnCard ? ccPaymentInfo.NameOnCard + " " + ccPaymentInfo.LastNameOnCard : ccPaymentInfo.NameOnCard; var newLocation = new LocationService(rockContext).Get( ccPaymentInfo.BillingStreet1, ccPaymentInfo.BillingStreet2, ccPaymentInfo.BillingCity, ccPaymentInfo.BillingState, ccPaymentInfo.BillingPostalCode, ccPaymentInfo.BillingCountry); if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace()) { NameOnCardEncrypted = Encryption.EncryptString(nameOnCard); } if (!ExpirationMonth.HasValue) { ExpirationMonthEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Month.ToString()); } if (!ExpirationYear.HasValue) { ExpirationYearEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Year.ToString()); } if (!BillingLocationId.HasValue && newLocation != null) { BillingLocationId = newLocation.Id; } } else if (paymentInfo is SwipePaymentInfo) { var swipePaymentInfo = ( SwipePaymentInfo )paymentInfo; if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace()) { NameOnCardEncrypted = Encryption.EncryptString(swipePaymentInfo.NameOnCard); } if (!ExpirationMonth.HasValue) { ExpirationMonthEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Month.ToString()); } if (!ExpirationYear.HasValue) { ExpirationYearEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Year.ToString()); } } else { var newLocation = new LocationService(rockContext).Get( paymentInfo.Street1, paymentInfo.Street2, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode, paymentInfo.Country); if (!BillingLocationId.HasValue && newLocation != null) { BillingLocationId = newLocation.Id; } } }
/// <summary> /// Shows the view. /// </summary> /// <param name="txn">The TXN.</param> private void ShowView(FinancialScheduledTransaction txn) { if (txn != null) { hlStatus.Text = txn.IsActive ? "Active" : "Inactive"; hlStatus.LabelType = txn.IsActive ? LabelType.Success : LabelType.Danger; string rockUrlRoot = ResolveRockUrl("/"); var detailsLeft = new DescriptionList() .Add("Person", (txn.AuthorizedPersonAlias != null && txn.AuthorizedPersonAlias.Person != null) ? txn.AuthorizedPersonAlias.Person.GetAnchorTag(rockUrlRoot) : string.Empty); var detailsRight = new DescriptionList() .Add("Amount", (txn.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M).FormatAsCurrency()) .Add("Frequency", txn.TransactionFrequencyValue != null ? txn.TransactionFrequencyValue.Value : string.Empty) .Add("Start Date", txn.StartDate.ToShortDateString()) .Add("End Date", txn.EndDate.HasValue ? txn.EndDate.Value.ToShortDateString() : string.Empty) .Add("Next Payment Date", txn.NextPaymentDate.HasValue ? txn.NextPaymentDate.Value.ToShortDateString() : string.Empty) .Add("Last Status Refresh", txn.LastStatusUpdateDateTime.HasValue ? txn.LastStatusUpdateDateTime.Value.ToString("g") : string.Empty); detailsLeft.Add("Source", txn.SourceTypeValue != null ? txn.SourceTypeValue.Value : string.Empty); if (txn.FinancialPaymentDetail != null && txn.FinancialPaymentDetail.CurrencyTypeValue != null) { var paymentMethodDetails = new DescriptionList(); var currencyType = txn.FinancialPaymentDetail.CurrencyTypeValue; if (currencyType.Guid.Equals(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid())) { // Credit Card paymentMethodDetails.Add("Type", currencyType.Value + (txn.FinancialPaymentDetail.CreditCardTypeValue != null ? (" - " + txn.FinancialPaymentDetail.CreditCardTypeValue.Value) : string.Empty)); paymentMethodDetails.Add("Name on Card", txn.FinancialPaymentDetail.NameOnCard.Trim()); paymentMethodDetails.Add("Account Number", txn.FinancialPaymentDetail.AccountNumberMasked); paymentMethodDetails.Add("Expires", txn.FinancialPaymentDetail.ExpirationDate); } else { // ACH paymentMethodDetails.Add("Type", currencyType.Value); paymentMethodDetails.Add("Account Number", txn.FinancialPaymentDetail.AccountNumberMasked); } detailsLeft.Add("Payment Method", paymentMethodDetails.GetFormattedList("{0}: {1}").AsDelimited("<br/>")); } GatewayComponent gateway = null; if (txn.FinancialGateway != null) { gateway = txn.FinancialGateway.GetGatewayComponent(); if (gateway != null) { detailsLeft.Add("Payment Gateway", GatewayContainer.GetComponentName(gateway.TypeName)); } } detailsLeft .Add("Transaction Code", txn.TransactionCode) .Add("Schedule Id", txn.GatewayScheduleId); lDetailsLeft.Text = detailsLeft.Html; lDetailsRight.Text = detailsRight.Html; gAccountsView.DataSource = txn.ScheduledTransactionDetails.ToList(); gAccountsView.DataBind(); var noteType = NoteTypeCache.Read(Rock.SystemGuid.NoteType.SCHEDULED_TRANSACTION_NOTE.AsGuid()); if (noteType != null) { var rockContext = new RockContext(); rptrNotes.DataSource = new NoteService(rockContext).Get(noteType.Id, txn.Id) .Where(n => n.CreatedDateTime.HasValue) .OrderBy(n => n.CreatedDateTime) .ToList() .Select(n => new { n.Caption, Text = n.Text.ConvertCrLfToHtmlBr(), Person = (n.CreatedByPersonAlias != null && n.CreatedByPersonAlias.Person != null) ? n.CreatedByPersonAlias.Person.FullName : "", Date = n.CreatedDateTime.HasValue ? n.CreatedDateTime.Value.ToShortDateString() : "", Time = n.CreatedDateTime.HasValue ? n.CreatedDateTime.Value.ToShortTimeString() : "" }) .ToList(); rptrNotes.DataBind(); } lbRefresh.Visible = gateway != null && gateway.GetScheduledPaymentStatusSupported; lbUpdate.Visible = gateway != null && gateway.UpdateScheduledPaymentSupported; lbCancelSchedule.Visible = txn.IsActive; lbReactivateSchedule.Visible = !txn.IsActive && gateway != null && gateway.ReactivateScheduledPaymentSupported; } }
/// <summary> /// Generate ClusterCreateParameters object for 3.X cluster with only Hadoop. /// </summary> /// <param name="inputs">Cluster creation parameter inputs.</param> /// <returns>The corresponding ClusterCreateParameter object.</returns> internal static ClusterCreateParameters Create3XClusterFromMapReduceTemplate(HDInsight.ClusterCreateParametersV2 inputs) { if (inputs == null) { throw new ArgumentNullException("inputs"); } var cluster = new ClusterCreateParameters { DnsName = inputs.Name, Version = inputs.Version }; var headnodeRole = new ClusterRole { FriendlyName = "HeadNodeRole", InstanceCount = 2, VMSizeAsString = inputs.HeadNodeSize, }; var workernodeRole = new ClusterRole { InstanceCount = inputs.ClusterSizeInNodes, FriendlyName = "WorkerNodeRole", VMSizeAsString = inputs.DataNodeSize, }; var zookeeperRole = new ClusterRole { InstanceCount = 3, FriendlyName = "ZKRole", VMSizeAsString = inputs.ZookeeperNodeSize ?? VmSize.Small.ToString(), }; cluster.ClusterRoleCollection.Add(headnodeRole); cluster.ClusterRoleCollection.Add(workernodeRole); cluster.ClusterRoleCollection.Add(zookeeperRole); var gateway = new GatewayComponent { IsEnabled = true, RestAuthCredential = new UsernamePasswordCredential { Username = inputs.UserName, Password = inputs.Password } }; cluster.Components.Add(gateway); cluster.Location = inputs.Location; //Add yarn component YarnComponent yarn = new YarnComponent { ResourceManagerRole = headnodeRole, NodeManagerRole = workernodeRole, }; ConfigYarnComponent(yarn, inputs); MapReduceApplication mapreduceApp = new MapReduceApplication(); ConfigMapReduceApplication(mapreduceApp, inputs); yarn.Applications.Add(mapreduceApp); cluster.Components.Add(yarn); // Adding Hive component HiveComponent hive = new HiveComponent { HeadNodeRole = headnodeRole }; ConfigHiveComponent(hive, inputs); cluster.Components.Add(hive); // Adding config action component if needed if (inputs.ConfigActions != null && inputs.ConfigActions.Count > 0) { CustomActionComponent configAction = new CustomActionComponent { HeadNodeRole = headnodeRole, WorkerNodeRole = workernodeRole }; AddConfigActionComponent(configAction, inputs, headnodeRole, workernodeRole); cluster.Components.Add(configAction); } // Adding Oozie component OozieComponent oozie = new OozieComponent { HeadNodeRole = headnodeRole }; ConfigOozieComponent(oozie, inputs); cluster.Components.Add(oozie); // Adding Hdfs component HdfsComponent hdfs = new HdfsComponent { HeadNodeRole = headnodeRole, WorkerNodeRole = workernodeRole }; ConfigHdfsComponent(hdfs, inputs); cluster.Components.Add(hdfs); // Adding HadoopCore component HadoopCoreComponent hadoopCore = new HadoopCoreComponent(); ConfigHadoopCoreComponent(hadoopCore, inputs); cluster.Components.Add(hadoopCore); // Adding Zookeeper component cluster.Components.Add(new ZookeeperComponent { ZookeeperRole = zookeeperRole }); ConfigVirtualNetwork(cluster, inputs); return(cluster); }
private static void PopulateClusterUriAndHttpCredsFromGateway(ClusterDetails clusterDetails, GatewayComponent gateway) { if (clusterDetails == null) { throw new ArgumentNullException("clusterDetails"); } if (gateway == null) { return; } clusterDetails.ConnectionUrl = gateway.RestUri; if (gateway.IsEnabled) { clusterDetails.HttpUserName = gateway.RestAuthCredential.Username; clusterDetails.HttpPassword = gateway.RestAuthCredential.Password; } else { clusterDetails.HttpUserName = clusterDetails.HttpPassword = string.Empty; } }
/// <summary> /// Handles the Swipe event of the csPayWithCard control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SwipeEventArgs"/> instance containing the event data.</param> protected void csPayWithCard_Swipe(object sender, SwipeEventArgs e) { using (var rockContext = new RockContext()) { try { var swipeInfo = e.PaymentInfo; var person = Customer; if (person == null) { person = new PersonAliasService(rockContext).GetPerson(GetAttributeValue("GuestCustomer").AsGuid()); if (person == null) { nbSwipeErrors.Text = "No guest customer configured. Transaction not processed."; return; } } // // Get the gateway to use. // FinancialGateway financialGateway = null; GatewayComponent gateway = null; Guid? gatewayGuid = GetAttributeValue("CreditCardGateway").AsGuidOrNull(); if (gatewayGuid.HasValue) { financialGateway = new FinancialGatewayService(rockContext).Get(gatewayGuid.Value); if (financialGateway != null) { financialGateway.LoadAttributes(rockContext); } gateway = financialGateway.GetGatewayComponent(); } if (gateway == null) { nbSwipeErrors.Text = "Invalid gateway provided. Please provide a gateway. Transaction not processed."; return; } swipeInfo.Amount = Cart.Total; // // Process the transaction. // string errorMessage = string.Empty; var transaction = gateway.Charge(financialGateway, swipeInfo, out errorMessage); if (transaction == null) { nbSwipeErrors.Text = String.Format("An error occurred while process this transaction. Message: {0}", errorMessage); return; } // // Set some common information about the transaction. // transaction.AuthorizedPersonAliasId = person.PrimaryAliasId; transaction.TransactionDateTime = RockDateTime.Now; transaction.FinancialGatewayId = financialGateway.Id; transaction.TransactionTypeValueId = DefinedValueCache.Get(GetAttributeValue("TransactionType")).Id; transaction.SourceTypeValueId = DefinedValueCache.Get(GetAttributeValue("Source")).Id; transaction.Summary = swipeInfo.Comment1; // // Ensure we have payment details. // if (transaction.FinancialPaymentDetail == null) { transaction.FinancialPaymentDetail = new FinancialPaymentDetail(); } transaction.FinancialPaymentDetail.SetFromPaymentInfo(swipeInfo, gateway, rockContext); // // Setup the transaction details to credit the correct account. // GetTransactionDetails(rockContext).ForEach(d => transaction.TransactionDetails.Add(d)); var batchService = new FinancialBatchService(rockContext); // // Get the batch // var batch = batchService.Get( GetAttributeValue("BatchNamePrefix"), swipeInfo.CurrencyTypeValue, swipeInfo.CreditCardTypeValue, transaction.TransactionDateTime.Value, financialGateway.GetBatchTimeOffset()); var batchChanges = new History.HistoryChangeList(); if (batch.Id == 0) { batchChanges.AddChange(History.HistoryVerb.Add, History.HistoryChangeType.Record, "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); } // // Update the control amount. // decimal newControlAmount = batch.ControlAmount + transaction.TotalAmount; History.EvaluateChange(batchChanges, "Control Amount", batch.ControlAmount.FormatAsCurrency(), newControlAmount.FormatAsCurrency()); batch.ControlAmount = newControlAmount; // // Add the transaction to the batch. // transaction.BatchId = batch.Id; batch.Transactions.Add(transaction); // // Generate the receipt. // int receiptId; using (var rockContext2 = new RockContext()) { var receipt = GenerateReceipt(rockContext2); receiptId = receipt.Id; } // // Update each transaction detail to reference the receipt. // foreach (var transactionDetail in transaction.TransactionDetails) { transactionDetail.EntityTypeId = EntityTypeCache.Get(typeof(InteractionComponent)).Id; transactionDetail.EntityId = receiptId; } rockContext.WrapTransaction(() => { rockContext.SaveChanges(); HistoryService.SaveChanges( rockContext, typeof(FinancialBatch), Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(), batch.Id, batchChanges ); }); ShowReceiptPanel(); } catch (Exception ex) { nbSwipeErrors.Text = String.Format("An error occurred while process this transaction. Message: {0}", ex.Message); } } }
/// <summary> /// Processes the payments. /// </summary> /// <param name="gateway">The gateway.</param> /// <param name="batchNamePrefix">The batch name prefix.</param> /// <param name="payments">The payments.</param> /// <param name="batchUrlFormat">The batch URL format.</param> /// <returns></returns> public static string ProcessPayments(GatewayComponent gateway, string batchNamePrefix, List <Payment> payments, string batchUrlFormat = "") { int totalPayments = 0; int totalAlreadyDownloaded = 0; int totalNoScheduledTransaction = 0; int totalAdded = 0; var batches = new List <FinancialBatch>(); var batchSummary = new Dictionary <Guid, List <Payment> >(); var rockContext = new RockContext(); var accountService = new FinancialAccountService(rockContext); var txnService = new FinancialTransactionService(rockContext); var batchService = new FinancialBatchService(rockContext); var scheduledTxnService = new FinancialScheduledTransactionService(rockContext); var contributionTxnTypeId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()).Id; var defaultAccount = accountService.Queryable() .Where(a => a.IsActive && !a.ParentAccountId.HasValue && (!a.StartDate.HasValue || a.StartDate.Value <= RockDateTime.Now) && (!a.EndDate.HasValue || a.EndDate.Value >= RockDateTime.Now) ) .OrderBy(a => a.Order) .FirstOrDefault(); foreach (var payment in payments.Where(p => p.Amount > 0.0M)) { totalPayments++; // Only consider transactions that have not already been added if (txnService.GetByTransactionCode(payment.TransactionCode) == null) { var scheduledTransaction = scheduledTxnService.GetByScheduleId(payment.GatewayScheduleId); if (scheduledTransaction != null) { scheduledTransaction.IsActive = payment.ScheduleActive; var transaction = new FinancialTransaction(); transaction.TransactionCode = payment.TransactionCode; transaction.TransactionDateTime = payment.TransactionDateTime; transaction.ScheduledTransactionId = scheduledTransaction.Id; transaction.AuthorizedPersonAliasId = scheduledTransaction.AuthorizedPersonAliasId; transaction.GatewayEntityTypeId = gateway.TypeId; transaction.TransactionTypeValueId = contributionTxnTypeId; var currencyTypeValue = payment.CurrencyTypeValue; if (currencyTypeValue == null && scheduledTransaction.CurrencyTypeValueId.HasValue) { currencyTypeValue = DefinedValueCache.Read(scheduledTransaction.CurrencyTypeValueId.Value); } if (currencyTypeValue != null) { transaction.CurrencyTypeValueId = currencyTypeValue.Id; } var creditCardTypevalue = payment.CreditCardTypeValue; if (creditCardTypevalue == null && scheduledTransaction.CreditCardTypeValueId.HasValue) { creditCardTypevalue = DefinedValueCache.Read(scheduledTransaction.CreditCardTypeValueId.Value); } if (creditCardTypevalue != null) { transaction.CreditCardTypeValueId = creditCardTypevalue.Id; } //transaction.SourceTypeValueId = DefinedValueCache.Read( sourceGuid ).Id; // Try to allocate the amount of the transaction based on the current scheduled transaction accounts decimal remainingAmount = payment.Amount; foreach (var detail in scheduledTransaction.ScheduledTransactionDetails.Where(d => d.Amount != 0.0M)) { var transactionDetail = new FinancialTransactionDetail(); transactionDetail.AccountId = detail.AccountId; if (detail.Amount <= remainingAmount) { // If the configured amount for this account is less than or equal to the remaining // amount, allocate the configured amount transactionDetail.Amount = detail.Amount; remainingAmount -= detail.Amount; } else { // If the configured amount is greater than the remaining amount, only allocate // the remaining amount transaction.Summary = "Note: Downloaded transaction amount was less than the configured allocation amounts for the Scheduled Transaction."; detail.Amount = remainingAmount; detail.Summary = "Note: The downloaded amount was not enough to apply the configured amount to this account."; remainingAmount = 0.0M; } transaction.TransactionDetails.Add(transactionDetail); if (remainingAmount <= 0.0M) { // If there's no amount left, break out of details break; } } // If there's still amount left after allocating based on current config, add the remainder // to the account that was configured for the most amount if (remainingAmount > 0.0M) { transaction.Summary = "Note: Downloaded transaction amount was greater than the configured allocation amounts for the Scheduled Transaction."; var transactionDetail = transaction.TransactionDetails .OrderByDescending(d => d.Amount) .First(); if (transactionDetail == null && defaultAccount != null) { transactionDetail = new FinancialTransactionDetail(); transactionDetail.AccountId = defaultAccount.Id; } if (transactionDetail != null) { transactionDetail.Amount += remainingAmount; transactionDetail.Summary = "Note: Extra amount was applied to this account."; } } // Get the batch var batch = batchService.Get( batchNamePrefix, currencyTypeValue, creditCardTypevalue, transaction.TransactionDateTime.Value, gateway.BatchTimeOffset, batches); batch.ControlAmount += transaction.TotalAmount; batch.Transactions.Add(transaction); // Add summary if (!batchSummary.ContainsKey(batch.Guid)) { batchSummary.Add(batch.Guid, new List <Payment>()); } batchSummary[batch.Guid].Add(payment); totalAdded++; } else { totalNoScheduledTransaction++; } } else { totalAlreadyDownloaded++; } } rockContext.SaveChanges(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("<li>{0} {1} downloaded.</li>", totalPayments.ToString("N0"), (totalPayments == 1 ? "payment" : "payments")); if (totalAlreadyDownloaded > 0) { sb.AppendFormat("<li>{0} {1} previously downloaded and {2} already been added.</li>", totalAlreadyDownloaded.ToString("N0"), (totalAlreadyDownloaded == 1 ? "payment was" : "payments were"), (totalAlreadyDownloaded == 1 ? "has" : "have")); } if (totalNoScheduledTransaction > 0) { sb.AppendFormat("<li>{0} {1} could not be matched to an existing scheduled payment profile.</li>", totalNoScheduledTransaction.ToString("N0"), (totalNoScheduledTransaction == 1 ? "payment" : "payments")); } sb.AppendFormat("<li>{0} {1} successfully added.</li>", totalAdded.ToString("N0"), (totalAdded == 1 ? "payment was" : "payments were")); foreach (var batchItem in batchSummary) { int items = batchItem.Value.Count; if (items > 0) { var batch = batches .Where(b => b.Guid.Equals(batchItem.Key)) .FirstOrDefault(); string batchName = string.Format("'{0} ({1})'", batch.Name, batch.BatchStartDateTime.Value.ToString("d")); if (!string.IsNullOrWhiteSpace(batchUrlFormat)) { batchName = string.Format("<a href='{0}'>{1}</a>", string.Format(batchUrlFormat, batch.Id), batchName); } decimal sum = batchItem.Value.Select(p => p.Amount).Sum(); string summaryformat = items == 1 ? "<li>{0} transaction of {1} was added to the {2} batch.</li>" : "<li>{0} transactions totaling {1} were added to the {2} batch</li>"; sb.AppendFormat(summaryformat, items.ToString("N0"), sum.ToString("C2"), batchName); } } return(sb.ToString()); }
/// <summary> /// Generate ClusterCreateParameters object for 2.X cluster with only Hadoop. /// </summary> /// <param name="inputs">Cluster creation parameter inputs.</param> /// <returns>The corresponding ClusterCreateParameter object.</returns> internal static ClusterCreateParameters Create2XClusterForMapReduceTemplate(HDInsight.ClusterCreateParametersV2 inputs) { if (inputs == null) { throw new ArgumentNullException("inputs"); } var cluster = new ClusterCreateParameters { DnsName = inputs.Name, Version = inputs.Version }; var remoteDesktopSettings = (string.IsNullOrEmpty(inputs.RdpUsername)) ? new RemoteDesktopSettings() { IsEnabled = false } : new RemoteDesktopSettings() { IsEnabled = true, AuthenticationCredential = new UsernamePasswordCredential() { Username = inputs.RdpUsername, Password = inputs.RdpPassword }, RemoteAccessExpiry = (DateTime)inputs.RdpAccessExpiry }; var headnodeRole = new ClusterRole { FriendlyName = "HeadNodeRole", InstanceCount = 2, VMSizeAsString = inputs.HeadNodeSize, RemoteDesktopSettings = remoteDesktopSettings }; var workernodeRole = new ClusterRole { InstanceCount = inputs.ClusterSizeInNodes, FriendlyName = "WorkerNodeRole", VMSizeAsString = inputs.DataNodeSize, RemoteDesktopSettings = remoteDesktopSettings }; var zookeeperRole = new ClusterRole { InstanceCount = 3, FriendlyName = "ZKRole", VMSizeAsString = VmSize.Small.ToString(), RemoteDesktopSettings = remoteDesktopSettings }; cluster.ClusterRoleCollection.Add(headnodeRole); cluster.ClusterRoleCollection.Add(workernodeRole); cluster.ClusterRoleCollection.Add(zookeeperRole); var gateway = new GatewayComponent { IsEnabled = true, RestAuthCredential = new UsernamePasswordCredential { Username = inputs.UserName, Password = inputs.Password } }; cluster.Components.Add(gateway); cluster.Location = inputs.Location; // Adding MapReduce component MapReduceComponent mapReduce = new MapReduceComponent { HeadNodeRole = headnodeRole, WorkerNodeRole = workernodeRole }; ConfigMapReduceComponent(mapReduce, inputs); cluster.Components.Add(mapReduce); // Adding Hive component HiveComponent hive = new HiveComponent { HeadNodeRole = headnodeRole }; ConfigHiveComponent(hive, inputs); cluster.Components.Add(hive); // Adding config action component if needed if (inputs.ConfigActions != null && inputs.ConfigActions.Count > 0) { CustomActionComponent configAction = new CustomActionComponent { HeadNodeRole = headnodeRole, WorkerNodeRole = workernodeRole }; AddConfigActionComponent(configAction, inputs, headnodeRole, workernodeRole, zookeeperRole); cluster.Components.Add(configAction); } // Adding Oozie component OozieComponent oozie = new OozieComponent { HeadNodeRole = headnodeRole }; ConfigOozieComponent(oozie, inputs); cluster.Components.Add(oozie); // Adding Hdfs component HdfsComponent hdfs = new HdfsComponent { HeadNodeRole = headnodeRole, WorkerNodeRole = workernodeRole }; ConfigHdfsComponent(hdfs, inputs); cluster.Components.Add(hdfs); // Adding HadoopCore component HadoopCoreComponent hadoopCore = new HadoopCoreComponent(); ConfigHadoopCoreComponent(hadoopCore, inputs); cluster.Components.Add(hadoopCore); ConfigVirtualNetwork(cluster, inputs); return(cluster); }
/// <summary> /// Sets from payment information. /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <param name="paymentGateway">The payment gateway.</param> /// <param name="rockContext">The rock context.</param> public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext) { if (AccountNumberMasked.IsNullOrWhiteSpace() && paymentInfo.MaskedNumber.IsNotNullOrWhiteSpace()) { AccountNumberMasked = paymentInfo.MaskedNumber; } if (!CurrencyTypeValueId.HasValue && paymentInfo.CurrencyTypeValue != null) { CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; } if (!CreditCardTypeValueId.HasValue && paymentInfo.CreditCardTypeValue != null) { CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id; } if (paymentInfo is CreditCardPaymentInfo) { var ccPaymentInfo = (CreditCardPaymentInfo)paymentInfo; string nameOnCard = paymentGateway.SplitNameOnCard ? ccPaymentInfo.NameOnCard + " " + ccPaymentInfo.LastNameOnCard : ccPaymentInfo.NameOnCard; var newLocation = new LocationService(rockContext).Get( ccPaymentInfo.BillingStreet1, ccPaymentInfo.BillingStreet2, ccPaymentInfo.BillingCity, ccPaymentInfo.BillingState, ccPaymentInfo.BillingPostalCode, ccPaymentInfo.BillingCountry); if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace()) { NameOnCardEncrypted = Encryption.EncryptString(nameOnCard); } if (!ExpirationMonth.HasValue) { ExpirationMonthEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Month.ToString()); } if (!ExpirationYear.HasValue) { ExpirationYearEncrypted = Encryption.EncryptString(ccPaymentInfo.ExpirationDate.Year.ToString()); } if (!BillingLocationId.HasValue && newLocation != null) { BillingLocationId = newLocation.Id; } } else if (paymentInfo is SwipePaymentInfo) { var swipePaymentInfo = (SwipePaymentInfo)paymentInfo; if (NameOnCard.IsNullOrWhiteSpace() && NameOnCard.IsNotNullOrWhiteSpace()) { NameOnCardEncrypted = Encryption.EncryptString(swipePaymentInfo.NameOnCard); } if (!ExpirationMonth.HasValue) { ExpirationMonthEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Month.ToString()); } if (!ExpirationYear.HasValue) { ExpirationYearEncrypted = Encryption.EncryptString(swipePaymentInfo.ExpirationDate.Year.ToString()); } } else { var newLocation = new LocationService(rockContext).Get( paymentInfo.Street1, paymentInfo.Street2, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode, paymentInfo.Country); if (!BillingLocationId.HasValue && newLocation != null) { BillingLocationId = newLocation.Id; } } }
/// <summary> /// Sets any payment information that the <seealso cref="GatewayComponent">paymentGateway</seealso> didn't set /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <param name="paymentGateway">The payment gateway.</param> /// <param name="rockContext">The rock context.</param> public void SetFromPaymentInfo(PaymentInfo paymentInfo, GatewayComponent paymentGateway, RockContext rockContext) { /* 2020-08-27 MDP * This method should only update values haven't been set yet. So * 1) Make sure paymentInfo has the data (isn't null or whitespace) * 2) Don't overwrite data in this (FinancialPaymentDetail) that already has the data set. */ if (AccountNumberMasked.IsNullOrWhiteSpace() && paymentInfo.MaskedNumber.IsNotNullOrWhiteSpace()) { AccountNumberMasked = paymentInfo.MaskedNumber; } if (paymentInfo is ReferencePaymentInfo referencePaymentInfo) { if (GatewayPersonIdentifier.IsNullOrWhiteSpace()) { GatewayPersonIdentifier = referencePaymentInfo.GatewayPersonIdentifier; } if (!FinancialPersonSavedAccountId.HasValue) { FinancialPersonSavedAccountId = referencePaymentInfo.FinancialPersonSavedAccountId; } } if (!CurrencyTypeValueId.HasValue && paymentInfo.CurrencyTypeValue != null) { CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; } if (!CreditCardTypeValueId.HasValue && paymentInfo.CreditCardTypeValue != null) { CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id; } if (paymentInfo is CreditCardPaymentInfo) { var ccPaymentInfo = ( CreditCardPaymentInfo )paymentInfo; string nameOnCard = paymentGateway.SplitNameOnCard ? ccPaymentInfo.NameOnCard + " " + ccPaymentInfo.LastNameOnCard : ccPaymentInfo.NameOnCard; // since the Address info could coming from an external system (the Gateway), don't do Location validation when creating a new location var newLocation = new LocationService(rockContext).Get( ccPaymentInfo.BillingStreet1, ccPaymentInfo.BillingStreet2, ccPaymentInfo.BillingCity, ccPaymentInfo.BillingState, ccPaymentInfo.BillingPostalCode, ccPaymentInfo.BillingCountry, new GetLocationArgs { ValidateLocation = false, CreateNewLocation = true }); if (NameOnCard.IsNullOrWhiteSpace() && nameOnCard.IsNotNullOrWhiteSpace()) { NameOnCard = nameOnCard; } if (!ExpirationMonth.HasValue) { ExpirationMonth = ccPaymentInfo.ExpirationDate.Month; } if (!ExpirationYear.HasValue) { ExpirationYear = ccPaymentInfo.ExpirationDate.Year; } if (!BillingLocationId.HasValue && newLocation != null) { BillingLocationId = newLocation.Id; } } else if (paymentInfo is SwipePaymentInfo) { var swipePaymentInfo = ( SwipePaymentInfo )paymentInfo; if (NameOnCard.IsNullOrWhiteSpace() && swipePaymentInfo.NameOnCard.IsNotNullOrWhiteSpace()) { NameOnCard = swipePaymentInfo.NameOnCard; } if (!ExpirationMonth.HasValue) { ExpirationMonth = swipePaymentInfo.ExpirationDate.Month; } if (!ExpirationYear.HasValue) { ExpirationYear = swipePaymentInfo.ExpirationDate.Year; } } else { // since the Address info could coming from an external system (the Gateway), don't do Location validation when creating a new location var newLocation = new LocationService(rockContext).Get( paymentInfo.Street1, paymentInfo.Street2, paymentInfo.City, paymentInfo.State, paymentInfo.PostalCode, paymentInfo.Country, new GetLocationArgs { ValidateLocation = false, CreateNewLocation = true }); if (!BillingLocationId.HasValue && newLocation != null) { BillingLocationId = newLocation.Id; } } }
private void SaveTransaction(FinancialGateway financialGateway, GatewayComponent gateway, Person person, PaymentInfo paymentInfo, FinancialTransaction transaction, RockContext rockContext) { transaction.AuthorizedPersonAliasId = person.PrimaryAliasId; if (RockTransactionEntry != null) { RockCheckBox cbGiveAnonymouslyControl = (( RockCheckBox )(RockTransactionEntry.FindControl("cbGiveAnonymously"))); if (cbGiveAnonymouslyControl != null) { transaction.ShowAsAnonymous = cbGiveAnonymouslyControl.Checked; } } transaction.TransactionDateTime = RockDateTime.Now; transaction.FinancialGatewayId = financialGateway.Id; var txnType = DefinedValueCache.Get(this.GetAttributeValue("TransactionType").AsGuidOrNull() ?? Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid()); transaction.TransactionTypeValueId = txnType.Id; transaction.Summary = paymentInfo.Comment1; if (transaction.FinancialPaymentDetail == null) { transaction.FinancialPaymentDetail = new FinancialPaymentDetail(); } transaction.FinancialPaymentDetail.SetFromPaymentInfo(paymentInfo, gateway, rockContext); Guid sourceGuid = Guid.Empty; if (Guid.TryParse(GetAttributeValue("Source"), out sourceGuid)) { var source = DefinedValueCache.Get(sourceGuid); if (source != null) { transaction.SourceTypeValueId = source.Id; } } var transactionEntity = this.GetTransactionEntity(); foreach (var account in GetSelectedAccounts().Where(a => a.Amount > 0)) { var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = account.Amount; transactionDetail.AccountId = account.Id; if (transactionEntity != null) { transactionDetail.EntityTypeId = transactionEntity.TypeId; transactionDetail.EntityId = transactionEntity.Id; } transaction.TransactionDetails.Add(transactionDetail); } var batchService = new FinancialBatchService(rockContext); // Get the batch var batch = batchService.Get( GetAttributeValue("BatchNamePrefix"), paymentInfo.CurrencyTypeValue, paymentInfo.CreditCardTypeValue, transaction.TransactionDateTime.Value, financialGateway.GetBatchTimeOffset()); var batchChanges = new History.HistoryChangeList(); if (batch.Id == 0) { batchChanges.AddCustom("Add", "Record", "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; transaction.LoadAttributes(rockContext); var allowedTransactionAttributes = GetAttributeValue("AllowedTransactionAttributesFromURL").Split(',').AsGuidList().Select(x => AttributeCache.Get(x).Key); foreach (KeyValuePair <string, AttributeValueCache> attr in transaction.AttributeValues) { if (PageParameters().ContainsKey("Attribute_" + attr.Key) && allowedTransactionAttributes.Contains(attr.Key)) { attr.Value.Value = Server.UrlDecode(PageParameter("Attribute_" + attr.Key)); } } batch.Transactions.Add(transaction); rockContext.SaveChanges(); transaction.SaveAttributeValues(); HistoryService.SaveChanges( rockContext, typeof(FinancialBatch), Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(), batch.Id, batchChanges ); SendReceipt(transaction.Id); TransactionCode = transaction.TransactionCode; }
/// <summary> /// Process the data read from the card reader and generate the transaction. /// </summary> /// <param name="swipeData">The data read from the card.</param> private void ProcessSwipe(string swipeData) { try { using (var rockContext = new RockContext()) { // create swipe object SwipePaymentInfo swipeInfo = new SwipePaymentInfo(swipeData); swipeInfo.Amount = tbAmount.Text.AsDecimal(); // add comment to the transation swipeInfo.Comment1 = PageParameter("Memo"); // get gateway FinancialGateway financialGateway = null; GatewayComponent gateway = null; Guid? gatewayGuid = GetAttributeValue("CreditCardGateway").AsGuidOrNull(); if (gatewayGuid.HasValue) { financialGateway = new FinancialGatewayService(rockContext).Get(gatewayGuid.Value); if (financialGateway != null) { financialGateway.LoadAttributes(rockContext); } gateway = financialGateway.GetGatewayComponent(); } if (gateway == null) { lSwipeErrors.Text = "<div class='alert alert-danger'>Invalid gateway provided. Please provide a gateway. Transaction not processed.</div>"; return; } // // Process the transaction. // string errorMessage = string.Empty; var transaction = gateway.Charge(financialGateway, swipeInfo, out errorMessage); if (transaction == null) { lSwipeErrors.Text = String.Format("<div class='alert alert-danger'>An error occurred while process this transaction. Message: {0}</div>", errorMessage); return; } _transactionCode = transaction.TransactionCode; // // Set some common information about the transaction. // transaction.AuthorizedPersonAliasId = new PersonService(rockContext).Get(SelectedPersonGuid).PrimaryAliasId; transaction.TransactionDateTime = RockDateTime.Now; transaction.FinancialGatewayId = financialGateway.Id; transaction.TransactionTypeValueId = DefinedValueCache.Read(GetAttributeValue("TransactionType")).Id; transaction.SourceTypeValueId = DefinedValueCache.Read(GetAttributeValue("Source")).Id; transaction.Summary = swipeInfo.Comment1; // // Ensure we have payment details. // if (transaction.FinancialPaymentDetail == null) { transaction.FinancialPaymentDetail = new FinancialPaymentDetail(); } transaction.FinancialPaymentDetail.SetFromPaymentInfo(swipeInfo, gateway, rockContext); var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = swipeInfo.Amount; transactionDetail.AccountId = new FinancialAccountService(rockContext).Get(GetAttributeValue("Account").AsGuid()).Id; transaction.TransactionDetails.Add(transactionDetail); var batchService = new FinancialBatchService(rockContext); // Get the batch var batch = batchService.Get( GetAttributeValue("BatchNamePrefix"), swipeInfo.CurrencyTypeValue, swipeInfo.CreditCardTypeValue, transaction.TransactionDateTime.Value, 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.WrapTransaction(() => { rockContext.SaveChanges(); HistoryService.SaveChanges( rockContext, typeof(FinancialBatch), Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(), batch.Id, batchChanges ); }); ShowReceiptPanel(); } } catch (Exception ex) { lSwipeErrors.Text = String.Format("<div class='alert alert-danger'>An error occurred while process this transaction. Message: {0}</div>", ex.Message); } }
// // Swipe Panel Events // private void ProcessSwipe(string swipeData) { try { using (var rockContext = new RockContext()) { // create swipe object SwipePaymentInfo swipeInfo = new SwipePaymentInfo(swipeData); swipeInfo.Amount = this.Amounts.Sum(a => a.Value); // if not anonymous then add contact info to the gateway transaction if (this.AnonymousGiverPersonAliasId != this.SelectedGivingUnit.PersonAliasId) { var giver = new PersonAliasService(rockContext).Queryable("Person, Person.PhoneNumbers").Where(p => p.Id == this.SelectedGivingUnit.PersonAliasId).FirstOrDefault(); swipeInfo.FirstName = giver.Person.NickName; swipeInfo.LastName = giver.Person.LastName; if (giver.Person.PhoneNumbers != null) { Guid homePhoneValueGuid = new Guid(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME); var homephone = giver.Person.PhoneNumbers.Where(p => p.NumberTypeValue.Guid == homePhoneValueGuid).FirstOrDefault(); if (homephone != null) { swipeInfo.Phone = homephone.NumberFormatted; } } var homeLocation = giver.Person.GetHomeLocation(); if (homeLocation != null) { swipeInfo.Street1 = homeLocation.Street1; if (!string.IsNullOrWhiteSpace(homeLocation.Street2)) { swipeInfo.Street2 = homeLocation.Street2; } swipeInfo.City = homeLocation.City; swipeInfo.State = homeLocation.State; swipeInfo.PostalCode = homeLocation.PostalCode; } } // add comment to the transation swipeInfo.Comment1 = GetAttributeValue("PaymentComment"); // get gateway FinancialGateway financialGateway = null; GatewayComponent gateway = null; Guid? gatewayGuid = GetAttributeValue("CreditCardGateway").AsGuidOrNull(); if (gatewayGuid.HasValue) { financialGateway = new FinancialGatewayService(rockContext).Get(gatewayGuid.Value); if (financialGateway != null) { financialGateway.LoadAttributes(rockContext); } gateway = financialGateway.GetGatewayComponent(); } if (gateway != null) { string errorMessage = string.Empty; var transaction = gateway.Charge(financialGateway, swipeInfo, out errorMessage); if (transaction != null) { var txnChanges = new List <string>(); txnChanges.Add("Created Transaction (from kiosk)"); _transactionCode = transaction.TransactionCode; History.EvaluateChange(txnChanges, "Transaction Code", string.Empty, transaction.TransactionCode); var personName = new PersonAliasService(rockContext) .Queryable().AsNoTracking() .Where(a => a.Id == this.SelectedGivingUnit.PersonAliasId) .Select(a => a.Person.NickName + " " + a.Person.LastName) .FirstOrDefault(); transaction.AuthorizedPersonAliasId = this.SelectedGivingUnit.PersonAliasId; History.EvaluateChange(txnChanges, "Person", string.Empty, personName); transaction.TransactionDateTime = RockDateTime.Now; History.EvaluateChange(txnChanges, "Date/Time", null, transaction.TransactionDateTime); transaction.FinancialGatewayId = financialGateway.Id; History.EvaluateChange(txnChanges, "Gateway", string.Empty, financialGateway.Name); var txnType = DefinedValueCache.Read(new Guid(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION)); transaction.TransactionTypeValueId = txnType.Id; History.EvaluateChange(txnChanges, "Type", string.Empty, txnType.Value); transaction.Summary = swipeInfo.Comment1; History.EvaluateChange(txnChanges, "Transaction Code", string.Empty, transaction.Summary); if (transaction.FinancialPaymentDetail == null) { transaction.FinancialPaymentDetail = new FinancialPaymentDetail(); } transaction.FinancialPaymentDetail.SetFromPaymentInfo(swipeInfo, gateway, rockContext, txnChanges); 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); } } foreach (var accountAmount in this.Amounts.Where(a => a.Value > 0)) { var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = accountAmount.Value; transactionDetail.AccountId = accountAmount.Key; transaction.TransactionDetails.Add(transactionDetail); var account = new FinancialAccountService(rockContext).Get(accountAmount.Key); if (account != null) { History.EvaluateChange(txnChanges, account.Name, 0.0M.FormatAsCurrency(), transactionDetail.Amount.FormatAsCurrency()); } } var batchService = new FinancialBatchService(rockContext); // Get the batch var batch = batchService.Get( GetAttributeValue("BatchNamePrefix"), swipeInfo.CurrencyTypeValue, swipeInfo.CreditCardTypeValue, transaction.TransactionDateTime.Value, 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.WrapTransaction(() => { 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, personName, typeof(FinancialTransaction), transaction.Id ); }); // send receipt in one is configured and not giving anonymously if (!string.IsNullOrWhiteSpace(GetAttributeValue("ReceiptEmail")) && (this.AnonymousGiverPersonAliasId != this.SelectedGivingUnit.PersonAliasId)) { _receiptSent = true; SendReceipt(); } HidePanels(); ShowReceiptPanel(); } else { lSwipeErrors.Text = String.Format("<div class='alert alert-danger'>An error occurred while process this transaction. Message: {0}</div>", errorMessage); } } else { lSwipeErrors.Text = "<div class='alert alert-danger'>Invalid gateway provided. Please provide a gateway. Transaction not processed.</div>"; } } } catch (Exception ex) { lSwipeErrors.Text = String.Format("<div class='alert alert-danger'>An error occurred while process this transaction. Message: {0}</div>", ex.Message); } }
/// <summary> /// Shows the view. /// </summary> /// <param name="financialScheduledTransaction">The TXN.</param> private void ShowView(FinancialScheduledTransaction financialScheduledTransaction) { if (financialScheduledTransaction == null) { return; } hlStatus.Text = financialScheduledTransaction.IsActive ? "Active" : "Inactive"; hlStatus.LabelType = financialScheduledTransaction.IsActive ? LabelType.Success : LabelType.Danger; string rockUrlRoot = ResolveRockUrl("/"); Person person = null; if (financialScheduledTransaction.AuthorizedPersonAlias != null) { person = financialScheduledTransaction.AuthorizedPersonAlias.Person; } var detailsLeft = new DescriptionList().Add("Person", person); var detailsRight = new DescriptionList() .Add("Amount", (financialScheduledTransaction.ScheduledTransactionDetails.Sum(d => ( decimal? )d.Amount) ?? 0.0M).FormatAsCurrency()) .Add("Frequency", financialScheduledTransaction.TransactionFrequencyValue != null ? financialScheduledTransaction.TransactionFrequencyValue.Value : string.Empty) .Add("Start Date", financialScheduledTransaction.StartDate.ToShortDateString()) .Add("End Date", financialScheduledTransaction.EndDate.HasValue ? financialScheduledTransaction.EndDate.Value.ToShortDateString() : string.Empty) .Add("Next Payment Date", financialScheduledTransaction.NextPaymentDate.HasValue ? financialScheduledTransaction.NextPaymentDate.Value.ToShortDateString() : string.Empty) .Add("Last Status Refresh", financialScheduledTransaction.LastStatusUpdateDateTime.HasValue ? financialScheduledTransaction.LastStatusUpdateDateTime.Value.ToString("g") : string.Empty); detailsLeft.Add("Source", financialScheduledTransaction.SourceTypeValue != null ? financialScheduledTransaction.SourceTypeValue.Value : string.Empty); if (financialScheduledTransaction.FinancialPaymentDetail != null && financialScheduledTransaction.FinancialPaymentDetail.CurrencyTypeValue != null) { var paymentMethodDetails = new DescriptionList(); var currencyType = financialScheduledTransaction.FinancialPaymentDetail.CurrencyTypeValue; if (currencyType.Guid.Equals(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid())) { // Credit Card paymentMethodDetails.Add("Type", currencyType.Value + (financialScheduledTransaction.FinancialPaymentDetail.CreditCardTypeValue != null ? (" - " + financialScheduledTransaction.FinancialPaymentDetail.CreditCardTypeValue.Value) : string.Empty)); paymentMethodDetails.Add("Name on Card", financialScheduledTransaction.FinancialPaymentDetail.NameOnCard.Trim()); paymentMethodDetails.Add("Account Number", financialScheduledTransaction.FinancialPaymentDetail.AccountNumberMasked); paymentMethodDetails.Add("Expires", financialScheduledTransaction.FinancialPaymentDetail.ExpirationDate); } else { // ACH paymentMethodDetails.Add("Type", currencyType.Value); paymentMethodDetails.Add("Account Number", financialScheduledTransaction.FinancialPaymentDetail.AccountNumberMasked); } detailsLeft.Add("Payment Method", paymentMethodDetails.GetFormattedList("{0}: {1}").AsDelimited("<br/>")); } GatewayComponent gateway = null; if (financialScheduledTransaction.FinancialGateway != null) { gateway = financialScheduledTransaction.FinancialGateway.GetGatewayComponent(); if (gateway != null) { detailsLeft.Add("Payment Gateway", GatewayContainer.GetComponentName(gateway.TypeName)); } } detailsLeft .Add("Transaction Code", financialScheduledTransaction.TransactionCode) .Add("Schedule Id", financialScheduledTransaction.GatewayScheduleId); lSummary.Visible = financialScheduledTransaction.Summary.IsNotNullOrWhiteSpace(); lSummary.Text = financialScheduledTransaction.Summary.ConvertCrLfToHtmlBr(); lDetailsLeft.Text = detailsLeft.Html; lDetailsRight.Text = detailsRight.Html; gAccountsView.DataSource = financialScheduledTransaction.ScheduledTransactionDetails.ToList(); gAccountsView.DataBind(); btnRefresh.Visible = gateway != null && gateway.GetScheduledPaymentStatusSupported; btnUpdate.Visible = gateway != null && gateway.UpdateScheduledPaymentSupported; btnCancelSchedule.Visible = financialScheduledTransaction.IsActive; btnReactivateSchedule.Visible = !financialScheduledTransaction.IsActive && gateway != null && gateway.ReactivateScheduledPaymentSupported; }