Move Expense block for Stripe after intent

This commit is contained in:
johnnyq
2026-07-22 16:16:40 -04:00
parent 66b38b7f19
commit f4b1b6585b
2 changed files with 14 additions and 14 deletions

View File

@@ -19,4 +19,4 @@ function getStripeGatewayFee($payment_intent)
'fee' => round($bt->fee / 100, 2),
'currency' => strtoupper($bt->currency),
];
}
}

View File

@@ -223,18 +223,6 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
$amount_paid_previously = floatval(mysqli_fetch_assoc($sql_amount_paid_previously)['amount_paid']);
$balance_to_pay = $invoice_amount - $amount_paid_previously;
// Stripe expense (actual fee from balance transaction)
if ($stripe_expense_vendor > 0 && $stripe_expense_category > 0) {
$stripe_fee = getStripeGatewayFee($pi_obj);
if ($stripe_fee) {
$gateway_fee = floatval($stripe_fee['fee']);
$gateway_fee_currency = escapeSql($stripe_fee['currency']);
mysqli_query($mysqli, "INSERT INTO expenses SET expense_date = '$pi_date', expense_amount = $gateway_fee, expense_currency_code = '$gateway_fee_currency', expense_account_id = $stripe_account, expense_vendor_id = $stripe_expense_vendor, expense_client_id = $client_id, expense_category_id = $stripe_expense_category, expense_description = 'Stripe fee for Invoice $invoice_prefix$invoice_number payment of $balance_to_pay', expense_reference = 'Stripe - $pi_id'");
} else {
error_log("Stripe payment warning - balance transaction unavailable for $pi_id, fee expense not recorded");
}
}
if (intval($balance_to_pay) !== intval($pi_amount_paid)) {
error_log("Stripe payment error - Invoice balance does not match amount paid for $pi_id");
exit(WORDING_PAYMENT_FAILED);
@@ -243,10 +231,22 @@ if (isset($_GET['invoice_id'], $_GET['url_key']) && !isset($_GET['payment_intent
// Update Invoice Status
mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $invoice_id");
// Add Payment to History
// Add Payment to History
mysqli_query($mysqli, "INSERT INTO payments SET payment_date = '$pi_date', payment_amount = $pi_amount_paid, payment_currency_code = '$pi_currency', payment_account_id = $stripe_account, payment_method = 'Stripe', payment_reference = 'Stripe - $pi_id', payment_invoice_id = $invoice_id");
mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Paid', history_description = 'Online Payment added (client) - $ip - $os - $browser', history_invoice_id = $invoice_id");
// Stripe expense (actual fee from balance transaction)
if ($stripe_expense_vendor > 0 && $stripe_expense_category > 0) {
$stripe_fee = getStripeGatewayFee($pi_obj);
if ($stripe_fee) {
$gateway_fee = floatval($stripe_fee['fee']);
$gateway_fee_currency = escapeSql($stripe_fee['currency']);
mysqli_query($mysqli, "INSERT INTO expenses SET expense_date = '$pi_date', expense_amount = $gateway_fee, expense_currency_code = '$gateway_fee_currency', expense_account_id = $stripe_account, expense_vendor_id = $stripe_expense_vendor, expense_client_id = $client_id, expense_category_id = $stripe_expense_category, expense_description = 'Stripe fee for Invoice $invoice_prefix$invoice_number payment of $balance_to_pay', expense_reference = 'Stripe - $pi_id'");
} else {
error_log("Stripe payment warning - balance transaction unavailable for $pi_id, fee expense not recorded");
}
}
// Notify
appNotify("Invoice Paid", "Invoice $invoice_prefix$invoice_number has been paid by $client_name - $ip - $os - $browser", "/agent/invoice.php?invoice_id=$invoice_id", $pi_client_id);