mirror of
https://github.com/itflow-org/itflow
synced 2026-07-23 08:50:42 +00:00
Cleanup Expense Code in post blocks and remove single use function since stripe payments get reconciled during nightly cron
This commit is contained in:
@@ -818,8 +818,6 @@ while ($row = mysqli_fetch_assoc($sql_recurring_payments)) {
|
||||
$provider_name = escapeSql($saved_payment['payment_provider_name']);
|
||||
$provider_private_key = $saved_payment['payment_provider_private_key'];
|
||||
$account_id = intval($saved_payment['payment_provider_account']);
|
||||
$expense_category_id = intval($saved_payment['payment_provider_expense_category']);
|
||||
$expense_vendor_id = intval($saved_payment['payment_provider_expense_vendor']);
|
||||
$saved_payment_description = escapeSql($saved_payment['saved_payment_description']);
|
||||
$stripe_payment_method_id = $saved_payment['saved_payment_provider_method'];
|
||||
|
||||
@@ -851,7 +849,6 @@ while ($row = mysqli_fetch_assoc($sql_recurring_payments)) {
|
||||
'off_session' => true,
|
||||
'confirm' => true,
|
||||
'description' => $pi_description,
|
||||
'expand' => ['latest_charge.balance_transaction'],
|
||||
'metadata' => [
|
||||
'itflow_client_id' => $client_id,
|
||||
'itflow_client_name' => $client_name,
|
||||
@@ -884,18 +881,6 @@ while ($row = mysqli_fetch_assoc($sql_recurring_payments)) {
|
||||
mysqli_query($mysqli, "INSERT INTO payments SET payment_date = '$pi_date', payment_amount = $pi_amount_paid, payment_currency_code = '$pi_currency', payment_account_id = $account_id, 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 (autopay)', history_invoice_id = $invoice_id");
|
||||
|
||||
// EXPENSE: Actual Stripe gateway fee as an expense (if configured)
|
||||
if ($expense_vendor_id > 0 && $expense_category_id > 0) {
|
||||
$stripe_fee = getStripeGatewayFee($payment_intent);
|
||||
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 = $account_id, expense_vendor_id = $expense_vendor_id, expense_client_id = $client_id, expense_category_id = $expense_category_id, expense_description = 'Stripe fee for Invoice $invoice_prefix$invoice_number payment of $balance_to_pay', expense_reference = 'Stripe - $pi_id'");
|
||||
} else {
|
||||
logApp("Stripe", "warning", "Balance transaction unavailable for $pi_id - fee expense not recorded for invoice ID $invoice_id");
|
||||
}
|
||||
}
|
||||
|
||||
// RECEIPT EMAIL
|
||||
if (!empty($config_smtp_provider)) {
|
||||
$subject = "Payment Received - Invoice $invoice_prefix$invoice_number";
|
||||
@@ -1006,10 +991,11 @@ if ($stripe_provider) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$stripe_fee = getStripeGatewayFee($payment_intent);
|
||||
if ($stripe_fee) {
|
||||
$gateway_fee = floatval($stripe_fee['fee']);
|
||||
$gateway_fee_currency = escapeSql($stripe_fee['currency']);
|
||||
// Actual fee from the balance transaction (null until Stripe attaches it - retried next run)
|
||||
$balance_transaction = $payment_intent->latest_charge->balance_transaction ?? null;
|
||||
if ($balance_transaction && !is_string($balance_transaction)) {
|
||||
$gateway_fee = round($balance_transaction->fee / 100, 2);
|
||||
$gateway_fee_currency = escapeSql(strtoupper($balance_transaction->currency));
|
||||
mysqli_query($mysqli, "INSERT INTO expenses SET expense_date = '$payment_date', expense_amount = $gateway_fee, expense_currency_code = '$gateway_fee_currency', expense_account_id = $expense_account_id, expense_vendor_id = $expense_vendor_id, expense_client_id = $client_id, expense_category_id = $expense_category_id, expense_description = 'Stripe fee for Invoice $invoice_prefix$invoice_number payment of $payment_amount', expense_reference = '$payment_reference'");
|
||||
logApp("Stripe", "info", "Fee reconciliation - recorded Stripe fee of $gateway_fee for $pi_id");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user