public override bool ProcessPayment(Payment payment, ref string message) { if (payment?.Parent?.Parent == null) { message = "Failed to process your payment."; return(false); } var currentOrder = payment.Parent.Parent; var customer = _customerService.Service.GetContactById(currentOrder.CustomerId.ToString()); if (customer == null) { message = "Failed to process your payment."; return(false); } var isQuoteOrder = currentOrder.IsQuoteCart(); if (isQuoteOrder) { if (customer.Role != B2BUserRoles.Approver) { message = "Failed to process your payment."; return(false); } } else if (customer.Role != B2BUserRoles.Purchaser) { message = "Failed to process your payment."; return(false); } var purchaserCustomer = !isQuoteOrder ? customer : _ordersService.Service.GetPurchaserCustomer(currentOrder); if (AreBudgetsOnHold(purchaserCustomer)) { message = "Budget on hold."; return(false); } var budget = _budgetService.Service.GetCustomerCurrentBudget(purchaserCustomer.Organization.OrganizationId, purchaserCustomer.ContactId); if (budget == null || budget.RemainingBudget < payment.Amount) { message = "Insufficient budget."; return(false); } if (payment.TransactionType == TransactionType.Capture.ToString()) { UpdateUserBudgets(purchaserCustomer, payment.Amount); payment.Status = PaymentStatus.Processed.ToString(); payment.AcceptChanges(); } return(true); }