/// <summary> /// Calculates the total amount. /// </summary> /// <param name="giveParameters">The give parameters.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private decimal? CalculateTotalAmount( GiveParameters giveParameters, RockContext rockContext ) { var totalAmount = 0m; if ( giveParameters.AmountDetails == null || giveParameters.AmountDetails.Length == 0 ) { GenerateResponse( HttpStatusCode.BadRequest, "AmountDetails are required" ); return null; } foreach ( var accountAmount in giveParameters.AmountDetails ) { if ( accountAmount.Amount < 1m ) { GenerateResponse( HttpStatusCode.BadRequest, "AmountDetails/Amount is required and must be greater than or equal to 1" ); return null; } if ( accountAmount.TargetAccountId == 0 ) { GenerateResponse( HttpStatusCode.BadRequest, "AmountDetails/TargetAccountId is required" ); return null; } if ( new FinancialAccountService( rockContext ).Get( accountAmount.TargetAccountId ) == null ) { GenerateResponse( HttpStatusCode.BadRequest, "AmountDetails/TargetAccountId must be an existing account's id" ); return null; } totalAmount += accountAmount.Amount; } if ( totalAmount < 1 ) { GenerateResponse( HttpStatusCode.BadRequest, "Total gift must be at least $1" ); return null; } return totalAmount; }
/// <summary> /// Gets the existing saved account. /// </summary> /// <param name="giveParameters">The give parameters.</param> /// <param name="person">The person.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private FinancialPersonSavedAccount GetExistingSavedAccount( GiveParameters giveParameters, Person person, RockContext rockContext ) { if ( !giveParameters.SourceAccountId.HasValue ) { return null; } var savedAccount = new FinancialPersonSavedAccountService( rockContext ).Get( giveParameters.SourceAccountId.Value ); if ( savedAccount == null ) { GenerateResponse( HttpStatusCode.BadRequest, "The SourceAccountId passed is invalid" ); return null; } if ( !savedAccount.PersonAliasId.HasValue ) { GenerateResponse( HttpStatusCode.BadRequest, "The SourceAccount doesn't belong to anyone" ); return null; } if ( person.Aliases.All( a => a.Id != savedAccount.PersonAliasId.Value ) ) { GenerateResponse( HttpStatusCode.BadRequest, "The SourceAccount doesn't belong to the passed PersonId" ); return null; } return savedAccount; }
/// <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; }