From 44544889dd26ae77bac1b3602b085c3a3855fe9b Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Mon, 17 Nov 2025 08:48:45 -0800 Subject: [PATCH] Streamlines recharge invoice approval Automatically approves recharge invoices when the customer email matches the user email and the invoice has debit recharge accounts. This speeds up the approval process for self-recharge scenarios. --- .../Controllers/InvoicesController.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Payments.Mvc/Controllers/InvoicesController.cs b/src/Payments.Mvc/Controllers/InvoicesController.cs index 481cec8f..f3598795 100644 --- a/src/Payments.Mvc/Controllers/InvoicesController.cs +++ b/src/Payments.Mvc/Controllers/InvoicesController.cs @@ -452,14 +452,37 @@ public async Task Send(int id, [FromBody] SendInvoiceModel model) await _invoiceService.SendInvoice(invoice, model); - if(invoice.Type == Invoice.InvoiceTypes.Recharge && invoice.Status == Invoice.StatusCodes.PendingApproval) + var user = await _userManager.GetUserAsync(User); + + // check if the user email is the same as the customer email for recharges so it goes directly to the pending approval. + if (invoice.Type == Invoice.InvoiceTypes.Recharge && + string.Equals(user.Email, invoice.CustomerEmail, StringComparison.OrdinalIgnoreCase) && + invoice.Status == Invoice.StatusCodes.Sent && + invoice.RechargeAccounts.Where(a => a.Direction == RechargeAccount.CreditDebit.Debit).Any()) + { + invoice.PaidAt = DateTime.UtcNow; + invoice.Status = Invoice.StatusCodes.PendingApproval; + var approvalAction = new History() + { + Type = HistoryActionTypes.RechargePaidByCustomer.TypeCode, + ActionDateTime = DateTime.UtcNow, + Actor = user.Name, + Data = new RechargePaidByCustomerHistoryActionType().SerializeData(new RechargePaidByCustomerHistoryActionType.DataType + { + RechargeAccounts = invoice.RechargeAccounts.Where(a => a.Direction == RechargeAccount.CreditDebit.Debit).ToArray() + }) + }; + invoice.History.Add(approvalAction); + } + + if (invoice.Type == Invoice.InvoiceTypes.Recharge && invoice.Status == Invoice.StatusCodes.PendingApproval) { //Need to resend these ones too await _invoiceService.SendFinancialApproverEmail(invoice, null); //Will pull them with a private method } // record action - var user = await _userManager.GetUserAsync(User); + var action = new History() { Type = HistoryActionTypes.InvoiceSent.TypeCode,