/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Charge( PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; var transaction = new FinancialTransaction(); transaction.TransactionCode = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF"); return transaction; }
/// <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; }
/// <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; }
private void SaveTransaction( FinancialGateway financialGateway, GatewayComponent gateway, Person person, PaymentInfo paymentInfo, FinancialTransaction transaction, RockContext rockContext ) { var txnChanges = new List<string>(); txnChanges.Add( "Created Transaction" ); History.EvaluateChange( txnChanges, "Transaction Code", string.Empty, transaction.TransactionCode ); transaction.AuthorizedPersonAliasId = person.PrimaryAliasId; History.EvaluateChange( txnChanges, "Person", string.Empty, person.FullName ); 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 = paymentInfo.Comment1; History.EvaluateChange( txnChanges, "Summary", string.Empty, transaction.Summary ); if ( transaction.FinancialPaymentDetail == null ) { transaction.FinancialPaymentDetail = new FinancialPaymentDetail(); } transaction.FinancialPaymentDetail.SetFromPaymentInfo( paymentInfo, 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 account in SelectedAccounts.Where( a => a.Amount > 0 ) ) { var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = account.Amount; transactionDetail.AccountId = account.Id; transaction.TransactionDetails.Add( transactionDetail ); 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" ), paymentInfo.CurrencyTypeValue, paymentInfo.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.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, person.FullName, typeof( FinancialTransaction ), transaction.Id ); SendReceipt( transaction.Id ); TransactionCode = transaction.TransactionCode; }
private Invoice GetInvoice( PaymentInfo paymentInfo ) { var ppBillingInfo = new BillTo(); ppBillingInfo.FirstName = paymentInfo.FirstName; ppBillingInfo.LastName = paymentInfo.LastName; ppBillingInfo.Email = paymentInfo.Email; ppBillingInfo.PhoneNum = paymentInfo.Phone; ppBillingInfo.Street = paymentInfo.Street1; ppBillingInfo.BillToStreet2 = paymentInfo.Street2; ppBillingInfo.State = paymentInfo.State; ppBillingInfo.Zip = paymentInfo.PostalCode; ppBillingInfo.BillToCountry = paymentInfo.Country; if ( paymentInfo is CreditCardPaymentInfo ) { var cc = paymentInfo as CreditCardPaymentInfo; ppBillingInfo.Street = cc.BillingStreet1; ppBillingInfo.BillToStreet2 = cc.BillingStreet2; ppBillingInfo.City = cc.BillingCity; ppBillingInfo.State = cc.BillingState; ppBillingInfo.Zip = cc.BillingPostalCode; ppBillingInfo.BillToCountry = cc.BillingCountry; } var ppAmount = new Currency( paymentInfo.Amount ); var ppInvoice = new Invoice(); ppInvoice.Amt = ppAmount; ppInvoice.BillTo = ppBillingInfo; return ppInvoice; }
/// <summary> /// Gets the payment information. /// </summary> /// <returns></returns> private PaymentInfo GetPaymentInfo(PersonService personService, FinancialScheduledTransaction scheduledTransaction) { PaymentInfo paymentInfo = null; if ( hfPaymentTab.Value == "ACH" ) { if ( rblSavedAch.Items.Count > 0 && ( rblSavedAch.SelectedValueAsId() ?? 0 ) > 0 ) { paymentInfo = GetReferenceInfo( rblSavedAch.SelectedValueAsId().Value ); } else { paymentInfo = GetACHInfo(); } } else if ( hfPaymentTab.Value == "CreditCard" ) { if ( rblSavedCC.Items.Count > 0 && ( rblSavedCC.SelectedValueAsId() ?? 0 ) > 0 ) { paymentInfo = GetReferenceInfo( rblSavedCC.SelectedValueAsId().Value ); } else { paymentInfo = GetCCInfo(); } } else { paymentInfo = new PaymentInfo(); } if ( paymentInfo != null ) { paymentInfo.Amount = SelectedAccounts.Sum( a => a.Amount ); paymentInfo.FirstName = scheduledTransaction.AuthorizedPerson.FirstName; paymentInfo.LastName = scheduledTransaction.AuthorizedPerson.LastName; paymentInfo.Email = scheduledTransaction.AuthorizedPerson.Email; bool displayPhone = false; if ( bool.TryParse( GetAttributeValue( "DisplayPhone" ), out displayPhone ) && displayPhone ) { var phoneNumber = personService.GetPhoneNumber( scheduledTransaction.AuthorizedPerson, DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ) ) ); paymentInfo.Phone = phoneNumber != null ? phoneNumber.NumberFormatted : string.Empty; } Guid addressTypeGuid = Guid.Empty; if ( !Guid.TryParse( GetAttributeValue( "AddressType" ), out addressTypeGuid ) ) { addressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ); } var address = personService.GetFirstLocation( scheduledTransaction.AuthorizedPerson, DefinedValueCache.Read( addressTypeGuid ).Id ); if ( address != null ) { paymentInfo.Street = address.Street1; paymentInfo.City = address.City; paymentInfo.State = address.State; paymentInfo.Zip = address.Zip; } } return paymentInfo; }
private bool SaveTransaction( GatewayComponent gateway, Registration registration, FinancialTransaction transaction, PaymentInfo paymentInfo, RockContext rockContext ) { if ( transaction != null ) { var txnChanges = new List<string>(); txnChanges.Add( "Created Transaction" ); History.EvaluateChange( txnChanges, "Transaction Code", string.Empty, transaction.TransactionCode ); transaction.AuthorizedPersonAliasId = registration.PersonAliasId; transaction.TransactionDateTime = RockDateTime.Now; History.EvaluateChange( txnChanges, "Date/Time", null, transaction.TransactionDateTime ); transaction.FinancialGatewayId = RegistrationTemplate.FinancialGatewayId; History.EvaluateChange( txnChanges, "Gateway", string.Empty, RegistrationTemplate.FinancialGateway.Name ); var txnType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_EVENT_REGISTRATION ) ); transaction.TransactionTypeValueId = txnType.Id; History.EvaluateChange( txnChanges, "Type", string.Empty, txnType.Value ); if ( transaction.FinancialPaymentDetail == null ) { transaction.FinancialPaymentDetail = new FinancialPaymentDetail(); } DefinedValueCache currencyType = null; DefinedValueCache creditCardType = null; if ( paymentInfo != null ) { transaction.FinancialPaymentDetail.SetFromPaymentInfo( paymentInfo, gateway, rockContext, txnChanges ); currencyType = paymentInfo.CurrencyTypeValue; creditCardType = paymentInfo.CreditCardTypeValue; } Guid sourceGuid = Guid.Empty; if ( Guid.TryParse( GetAttributeValue( "Source" ), out sourceGuid ) ) { var source = DefinedValueCache.Read( sourceGuid ); if ( source != null ) { transaction.SourceTypeValueId = source.Id; History.EvaluateChange( txnChanges, "Source", string.Empty, source.Value ); } } transaction.Summary = registration.GetSummary( RegistrationInstanceState ); var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = RegistrationState.PaymentAmount ?? 0.0m; transactionDetail.AccountId = RegistrationInstanceState.AccountId.Value; transactionDetail.EntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Registration ) ).Id; transactionDetail.EntityId = registration.Id; transaction.TransactionDetails.Add( transactionDetail ); History.EvaluateChange( txnChanges, RegistrationInstanceState.Account.Name, 0.0M.FormatAsCurrency(), transactionDetail.Amount.FormatAsCurrency() ); var batchChanges = new List<string>(); rockContext.WrapTransaction( () => { var batchService = new FinancialBatchService( rockContext ); // determine batch prefix string batchPrefix = string.Empty; if ( !string.IsNullOrWhiteSpace( RegistrationTemplate.BatchNamePrefix ) ) { batchPrefix = RegistrationTemplate.BatchNamePrefix; } else { batchPrefix = GetAttributeValue( "BatchNamePrefix" ); } // Get the batch var batch = batchService.Get( batchPrefix, currencyType, creditCardType, transaction.TransactionDateTime.Value, RegistrationTemplate.FinancialGateway.GetBatchTimeOffset() ); if ( batch.Id == 0 ) { batchChanges.Add( "Generated the batch" ); History.EvaluateChange( batchChanges, "Batch Name", string.Empty, batch.Name ); History.EvaluateChange( batchChanges, "Status", null, batch.Status ); History.EvaluateChange( batchChanges, "Start Date/Time", null, batch.BatchStartDateTime ); History.EvaluateChange( batchChanges, "End Date/Time", null, batch.BatchEndDateTime ); } decimal newControlAmount = batch.ControlAmount + transaction.TotalAmount; History.EvaluateChange( batchChanges, "Control Amount", batch.ControlAmount.FormatAsCurrency(), newControlAmount.FormatAsCurrency() ); batch.ControlAmount = newControlAmount; transaction.BatchId = batch.Id; batch.Transactions.Add( transaction ); rockContext.SaveChanges(); } ); if ( transaction.BatchId.HasValue ) { Task.Run( () => HistoryService.SaveChanges( new RockContext(), typeof( FinancialBatch ), Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(), transaction.BatchId.Value, batchChanges, true, CurrentPersonAliasId ) ); Task.Run( () => HistoryService.SaveChanges( new RockContext(), typeof( FinancialBatch ), Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(), transaction.BatchId.Value, txnChanges, CurrentPerson != null ? CurrentPerson.FullName : string.Empty, typeof( FinancialTransaction ), transaction.Id, true, CurrentPersonAliasId ) ); } List<string> registrationChanges = new List<string>(); registrationChanges.Add( string.Format( "Made {0} payment", transaction.TotalAmount.FormatAsCurrency() ) ); Task.Run( () => HistoryService.SaveChanges( new RockContext(), typeof( Registration ), Rock.SystemGuid.Category.HISTORY_EVENT_REGISTRATION.AsGuid(), registration.Id, registrationChanges, true, CurrentPersonAliasId ) ); TransactionCode = transaction.TransactionCode; return true; } else { return false; } }
/// <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);
/// <summary> /// Gets the total payment item. /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <returns></returns> private Item[] GetItems( PaymentInfo paymentInfo ) { List<Item> itemList = new List<Item>(); Item item = new Item(); item.id = "0"; item.unitPrice = paymentInfo.Amount.ToString(); item.totalAmount = paymentInfo.Amount.ToString(); itemList.Add( item ); return itemList.ToArray(); }
/// <summary> /// Gets the payment information. /// </summary> /// <returns></returns> private PaymentInfo GetPaymentInfo( PersonService personService, FinancialScheduledTransaction scheduledTransaction ) { PaymentInfo paymentInfo = null; if ( hfPaymentTab.Value == "ACH" ) { if ( rblSavedAch.Items.Count > 0 && ( rblSavedAch.SelectedValueAsId() ?? 0 ) > 0 ) { paymentInfo = GetReferenceInfo( rblSavedAch.SelectedValueAsId().Value ); } else { paymentInfo = GetACHInfo(); } } else if ( hfPaymentTab.Value == "CreditCard" ) { if ( rblSavedCC.Items.Count > 0 && ( rblSavedCC.SelectedValueAsId() ?? 0 ) > 0 ) { paymentInfo = GetReferenceInfo( rblSavedCC.SelectedValueAsId().Value ); } else { paymentInfo = GetCCInfo(); } } else { paymentInfo = new PaymentInfo(); } if ( paymentInfo != null ) { paymentInfo.Amount = SelectedAccounts.Sum( a => a.Amount ); var authorizedPerson = scheduledTransaction.AuthorizedPersonAlias.Person; paymentInfo.FirstName = authorizedPerson.FirstName; paymentInfo.LastName = authorizedPerson.LastName; paymentInfo.Email = authorizedPerson.Email; bool displayPhone = GetAttributeValue( "DisplayPhone" ).AsBoolean(); if ( displayPhone ) { var phoneNumber = personService.GetPhoneNumber( authorizedPerson, DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ) ) ); paymentInfo.Phone = phoneNumber != null ? phoneNumber.ToString() : string.Empty; } Guid addressTypeGuid = Guid.Empty; if ( !Guid.TryParse( GetAttributeValue( "AddressType" ), out addressTypeGuid ) ) { addressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ); } var groupLocation = personService.GetFirstLocation( authorizedPerson.Id, DefinedValueCache.Read( addressTypeGuid ).Id ); if ( groupLocation != null && groupLocation.Location != null ) { paymentInfo.Street1 = groupLocation.Location.Street1; paymentInfo.Street2 = groupLocation.Location.Street2; paymentInfo.City = groupLocation.Location.City; paymentInfo.State = groupLocation.Location.State; paymentInfo.PostalCode = groupLocation.Location.PostalCode; paymentInfo.Country = groupLocation.Location.Country; } } return paymentInfo; }
/// <summary> /// Updates the scheduled payment. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public abstract bool UpdateScheduledPayment( FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage );
/// <summary> /// Authorizes the specified payment information. /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public virtual FinancialTransaction Authorize( PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = "Gateway does not support Authorizations"; return null; }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="financialGateway">The financial gateway.</param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Charge(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage) { errorMessage = string.Empty; if (ValidateCard(financialGateway, paymentInfo, out errorMessage)) { var transaction = new FinancialTransaction(); transaction.TransactionCode = "T" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF"); return(transaction); } return(null); }
/// <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 );
/// <summary> /// Updates the scheduled payment. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override bool UpdateScheduledPayment(FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage) { errorMessage = string.Empty; return(true); }
/// <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 = "P" + RockDateTime.Now.ToString("yyyyMMddHHmmssFFF"); scheduledTransaction.LastStatusUpdateDateTime = RockDateTime.Now; return(scheduledTransaction); } return(null); }
/// <summary> /// Updates the scheduled payment. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public abstract bool UpdateScheduledPayment(FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage);
/// <summary> /// Updates the scheduled payment. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override bool UpdateScheduledPayment(FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage) { errorMessage = string.Empty; var referencePaymentInfo = paymentInfo as ReferencePaymentInfo; if (referencePaymentInfo != null) { transaction.TransactionCode = referencePaymentInfo.TransactionCode; } return(true); }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public abstract FinancialTransaction Charge( PaymentInfo paymentInfo, out string errorMessage );
/// <summary> /// Gets the billing details from user submitted payment info. /// </summary> /// <param name="paymentInfo">The payment information.</param> /// <returns></returns> private BillTo GetBillTo( PaymentInfo paymentInfo ) { BillTo billingInfo = new BillTo(); if ( paymentInfo.Phone == null ) { paymentInfo.Phone = string.Empty; } if ( paymentInfo is CreditCardPaymentInfo ) { var cc = paymentInfo as CreditCardPaymentInfo; billingInfo.street1 = cc.BillingStreet1.Left( 50 ); billingInfo.city = cc.BillingCity.Left( 50 ); billingInfo.state = cc.BillingState.Left( 2 ); billingInfo.postalCode = cc.BillingPostalCode.Left( 10 ); } else { billingInfo.street1 = paymentInfo.Street1.Left( 50 ); // up to 50 chars billingInfo.city = paymentInfo.City.Left( 50 ); // up to 50 chars billingInfo.state = paymentInfo.State.Left( 2 ); // only 2 chars var zip = paymentInfo.PostalCode; if ( !string.IsNullOrWhiteSpace( zip ) && zip.Length > 5 ) { Regex.Replace( zip, @"^(.{5})(.{4})$", "$1-$2" ); // up to 9 chars with a separating - } billingInfo.postalCode = zip; } billingInfo.firstName = paymentInfo.FirstName.Left( 50 ); // up to 50 chars billingInfo.lastName = paymentInfo.LastName.Left( 60 ); // up to 60 chars billingInfo.email = paymentInfo.Email; // up to 255 chars billingInfo.phoneNumber = paymentInfo.Phone.Left( 15 ); // up to 15 chars var country = paymentInfo.Country ?? "US"; billingInfo.country = country.Left( 2 ); // only 2 chars var ipAddr = Dns.GetHostEntry( Dns.GetHostName() ).AddressList .FirstOrDefault( ip => ip.AddressFamily == AddressFamily.InterNetwork ); billingInfo.ipAddress = ipAddr.ToString(); // machine IP address return billingInfo; }
/// <summary> /// Updates the scheduled payment. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override bool UpdateScheduledPayment( FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; return true; }
/// <summary> /// Gets the payment information. /// </summary> /// <returns></returns> private RequestMessage GetPaymentInfo( FinancialGateway financialGateway, PaymentInfo paymentInfo ) { RequestMessage request = GetMerchantInfo( financialGateway ); if ( paymentInfo is CreditCardPaymentInfo ) { var cc = paymentInfo as CreditCardPaymentInfo; request.card = GetCard( cc ); } else if ( paymentInfo is ACHPaymentInfo ) { var ach = paymentInfo as ACHPaymentInfo; request.check = GetCheck( ach ); } else if ( paymentInfo is ReferencePaymentInfo ) { var reference = paymentInfo as ReferencePaymentInfo; request.recurringSubscriptionInfo = new RecurringSubscriptionInfo(); request.recurringSubscriptionInfo.subscriptionID = reference.ReferenceNumber; } else { return null; } return request; }
private bool ValidateCard(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage) { string cardNumber = string.Empty; var declinedCVV = this.GetAttributeValue(financialGateway, AttributeKey.DeclinedCVV); int maxExpirationYears = this.GetAttributeValue(financialGateway, AttributeKey.MaxExpirationYears).AsIntegerOrNull() ?? 10; CreditCardPaymentInfo ccPayment = paymentInfo as CreditCardPaymentInfo; if (ccPayment != null) { if (declinedCVV.IsNotNullOrWhiteSpace() && ccPayment.Code == declinedCVV) { errorMessage = "Declined CVV"; return(false); } cardNumber = ccPayment.Number; if (ccPayment.ExpirationDate < RockDateTime.Now.Date) { errorMessage = "Card Expired"; return(false); } if (ccPayment.ExpirationDate > RockDateTime.Now.AddYears(maxExpirationYears)) { errorMessage = "Invalid Card Expiration"; return(false); } if (ccPayment.Number.IsNullOrWhiteSpace()) { errorMessage = "Card number is required."; return(false); } if (ccPayment.Code.IsNullOrWhiteSpace()) { errorMessage = "CVV is required."; return(false); } } SwipePaymentInfo swipePayment = paymentInfo as SwipePaymentInfo; if (swipePayment != null) { cardNumber = swipePayment.Number; } if (!string.IsNullOrWhiteSpace(cardNumber)) { var declinedNumbers = GetAttributeValue(financialGateway, AttributeKey.DeclinedCardNumbers); if (!string.IsNullOrWhiteSpace(declinedNumbers)) { if (declinedNumbers.SplitDelimitedValues().Any(n => cardNumber.EndsWith(n))) { errorMessage = "Declined Card"; return(false); } } } errorMessage = string.Empty; return(true); }
/// <summary> /// Processes the first step of a 3-step charge. /// </summary> /// <param name="registration">The registration.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> private bool ProcessStep1( out string errorMessage ) { ThreeStepGatewayComponent gateway = null; if ( RegistrationTemplate != null && RegistrationTemplate.FinancialGateway != null ) { gateway = RegistrationTemplate.FinancialGateway.GetGatewayComponent() as ThreeStepGatewayComponent; } if ( gateway == null ) { errorMessage = "There was a problem creating the payment gateway information"; return false; } if ( !RegistrationInstanceState.AccountId.HasValue || RegistrationInstanceState.Account == null ) { errorMessage = "There was a problem with the account configuration for this " + RegistrationTerm.ToLower(); return false; } PaymentInfo paymentInfo = null; if ( rblSavedCC.Items.Count > 0 && ( rblSavedCC.SelectedValueAsId() ?? 0 ) > 0 ) { var rockContext = new RockContext(); var savedAccount = new FinancialPersonSavedAccountService( rockContext ).Get( rblSavedCC.SelectedValueAsId().Value ); if ( savedAccount != null ) { paymentInfo = savedAccount.GetReferencePayment(); paymentInfo.Amount = RegistrationState.PaymentAmount ?? 0.0m; } else { errorMessage = "There was a problem retrieving the saved account"; return false; } } else { paymentInfo = new PaymentInfo(); paymentInfo.Amount = RegistrationState.PaymentAmount ?? 0.0m; paymentInfo.Email = RegistrationState.ConfirmationEmail; paymentInfo.FirstName = RegistrationState.FirstName; paymentInfo.LastName = RegistrationState.LastName; } paymentInfo.Description = string.Format( "{0} ({1})", RegistrationInstanceState.Name, RegistrationInstanceState.Account.GlCode ); paymentInfo.IPAddress = GetClientIpAddress(); paymentInfo.AdditionalParameters = gateway.GetStep1Parameters( ResolveRockUrlIncludeRoot( "~/GatewayStep2Return.aspx" ) ); var result = gateway.ChargeStep1( RegistrationTemplate.FinancialGateway, paymentInfo, out errorMessage ); if ( string.IsNullOrWhiteSpace( errorMessage ) && !string.IsNullOrWhiteSpace( result ) ) { hfStep2Url.Value = result; } return string.IsNullOrWhiteSpace( errorMessage ); }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Charge( PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; Response ppResponse = null; var invoice = GetInvoice( paymentInfo ); var tender = GetTender( paymentInfo ); if ( tender != null ) { if ( paymentInfo is ReferencePaymentInfo ) { var reference = paymentInfo as ReferencePaymentInfo; var ppTransaction = new ReferenceTransaction( "Sale", reference.TransactionCode, GetUserInfo(), GetConnection(), invoice, tender, PayflowUtility.RequestId ); ppResponse = ppTransaction.SubmitTransaction(); } else { var ppTransaction = new SaleTransaction( GetUserInfo(), GetConnection(), invoice, tender, PayflowUtility.RequestId ); ppResponse = ppTransaction.SubmitTransaction(); } } else { errorMessage = "Could not create tender from PaymentInfo"; } if ( ppResponse != null ) { TransactionResponse txnResponse = ppResponse.TransactionResponse; if ( txnResponse != null ) { if ( txnResponse.Result == 0 ) // Success { var transaction = new FinancialTransaction(); transaction.TransactionCode = txnResponse.Pnref; return transaction; } 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; }
/// <summary> /// Updates the payment information for saved account. /// </summary> /// <param name="giveParameters">The give parameters.</param> /// <param name="paymentInfo">The payment information.</param> /// <param name="person">The person.</param> /// <param name="rockContext">The rock context.</param> /// <param name="billingLocationId">The billing location identifier.</param> /// <param name="totalAmount">The total amount.</param> private void UpdatePaymentInfoForSavedAccount( GiveParameters giveParameters, PaymentInfo paymentInfo, Person person, RockContext rockContext, int billingLocationId, decimal totalAmount ) { var billingLocation = new LocationService( rockContext ).Get(billingLocationId); paymentInfo.FirstName = giveParameters.FirstName ?? person.FirstName; paymentInfo.LastName = giveParameters.LastName ?? person.LastName; paymentInfo.Email = giveParameters.Email ?? person.Email; paymentInfo.Phone = giveParameters.PhoneNumber ?? string.Empty; paymentInfo.Street1 = giveParameters.Street1 ?? billingLocation.Street1; paymentInfo.Street2 = giveParameters.Street2 ?? billingLocation.Street2; paymentInfo.City = giveParameters.City ?? billingLocation.City; paymentInfo.State = giveParameters.State ?? billingLocation.State; paymentInfo.PostalCode = giveParameters.PostalCode ?? billingLocation.PostalCode; paymentInfo.Country = giveParameters.Country ?? billingLocation.Country; paymentInfo.Amount = totalAmount; }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public abstract FinancialTransaction Charge(PaymentInfo paymentInfo, out string errorMessage);
/// <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> /// Performs the first step of a three-step charge /// </summary> /// <param name="financialGateway">The financial gateway.</param> /// <param name="paymentInfo">The payment information.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public abstract string ChargeStep1( FinancialGateway financialGateway, 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 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; }
/// <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; }
/// <summary> /// Updates 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 bool UpdateScheduledPayment( FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; RecurringModifyTransaction ppTransaction = null; if ( paymentInfo != null ) { ppTransaction = new RecurringModifyTransaction( GetUserInfo(), GetConnection(), GetRecurring( transaction ), GetInvoice( paymentInfo ), GetTender( paymentInfo ), PayflowUtility.RequestId ); } else { ppTransaction = new RecurringModifyTransaction( GetUserInfo(), GetConnection(), GetRecurring( transaction ), PayflowUtility.RequestId ); } 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 ) { return true; } 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 false; }
/// <summary> /// Authorizes/tokenizes the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Authorize( FinancialGateway financialGateway, 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.frequency = "ON-DEMAND"; 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; } // Authorize the transaction ReplyMessage reply = SubmitTransaction( financialGateway, request, out errorMessage ); if ( reply != null && reply.reasonCode.Equals( GATEWAY_RESPONSE_SUCCESS ) ) { var transactionGuid = new Guid( reply.merchantReferenceCode ); var transaction = new FinancialTransaction { Guid = transactionGuid }; transaction.TransactionCode = reply.requestID; return transaction; } else if ( string.IsNullOrEmpty( errorMessage ) ) { errorMessage = string.Format( "Unable to authorize this transaction.{0}", ProcessError( reply ) ); } return null; }
private BaseTender GetTender( PaymentInfo paymentInfo ) { if ( paymentInfo is CreditCardPaymentInfo ) { var cc = paymentInfo as CreditCardPaymentInfo; var ppCreditCard = new CreditCard( cc.Number, cc.ExpirationDate.ToString( "MMyy" ) ); ppCreditCard.Cvv2 = cc.Code; return new CardTender( ppCreditCard ); } if ( paymentInfo is ACHPaymentInfo ) { var ach = paymentInfo as ACHPaymentInfo; var ppBankAccount = new BankAcct( ach.BankAccountNumber, ach.BankRoutingNumber ); ppBankAccount.AcctType = ach.AccountType == BankAccountType.Checking ? "C" : "S"; ppBankAccount.Name = ach.BankName; return new ACHTender( ppBankAccount ); } if ( paymentInfo is SwipePaymentInfo ) { var swipe = paymentInfo as SwipePaymentInfo; var ppSwipeCard = new SwipeCard( swipe.SwipeInfo ); return new CardTender( ppSwipeCard ); } if ( paymentInfo is ReferencePaymentInfo ) { var reference = paymentInfo as ReferencePaymentInfo; if ( reference.CurrencyTypeValue.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ) ) { return new ACHTender( (BankAcct)null ); } else { return new CardTender( (CreditCard)null ); } } return null; }
/// <summary> /// Charges the specified payment info. /// </summary> /// <param name="paymentInfo">The payment info.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public override FinancialTransaction Charge( FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; RequestMessage request = GetPaymentInfo( financialGateway, paymentInfo ); if ( request == null ) { errorMessage = "Payment type not implemented"; return null; } request.purchaseTotals = GetTotals(); request.billTo = GetBillTo( paymentInfo ); request.item = GetItems( paymentInfo ); if ( !paymentInfo.CurrencyTypeValue.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ) ) { request.ecDebitService = new ECDebitService(); request.ecDebitService.commerceIndicator = "internet"; request.ecDebitService.run = "true"; } else { request.ccAuthService = new CCAuthService(); request.ccAuthService.commerceIndicator = "internet"; request.ccAuthService.run = "true"; request.ccCaptureService = new CCCaptureService(); request.ccCaptureService.run = "true"; } // Charge the transaction ReplyMessage reply = SubmitTransaction( financialGateway, request, out errorMessage ); if ( reply != null && reply.reasonCode.Equals( GATEWAY_RESPONSE_SUCCESS ) ) { var transactionGuid = new Guid( reply.merchantReferenceCode ); var transaction = new FinancialTransaction { Guid = transactionGuid }; transaction.TransactionCode = reply.requestID; return transaction; } else if ( string.IsNullOrEmpty( errorMessage ) ) { errorMessage = string.Format( "Unable to process this order.{0}", ProcessError( reply ) ); } return null; }
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; }
/// <summary> /// Updates 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 bool UpdateScheduledPayment( FinancialScheduledTransaction transaction, PaymentInfo paymentInfo, out string errorMessage ) { errorMessage = string.Empty; var financialGateway = transaction.FinancialGateway; RequestMessage request = GetPaymentInfo( financialGateway, paymentInfo ); if ( request == null ) { errorMessage = "Payment type not implemented"; return false; } if ( request.recurringSubscriptionInfo == null ) { request.recurringSubscriptionInfo = new RecurringSubscriptionInfo(); request.recurringSubscriptionInfo.subscriptionID = transaction.TransactionCode; } request.recurringSubscriptionInfo.amount = paymentInfo.Amount.ToString(); request.paySubscriptionUpdateService = new PaySubscriptionUpdateService(); request.paySubscriptionUpdateService.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"; } else { request.subscription.paymentMethod = "credit card"; } // Update the schedule ReplyMessage reply = SubmitTransaction( financialGateway, request, out errorMessage ); if ( reply != null && reply.reasonCode.Equals( GATEWAY_RESPONSE_SUCCESS ) ) { return true; } else if ( string.IsNullOrEmpty( errorMessage ) ) { errorMessage = string.Format( "Unable to update this transaction. {0}", ProcessError( reply ) ); } return false; }
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> /// Authorizes the specified payment information. /// </summary> /// <param name="financialGateway">The financial gateway.</param> /// <param name="paymentInfo">The payment information.</param> /// <param name="errorMessage">The error message.</param> /// <returns></returns> public virtual FinancialTransaction Authorize(FinancialGateway financialGateway, PaymentInfo paymentInfo, out string errorMessage) { errorMessage = "Gateway does not support Authorizations"; return(null); }