diff --git a/functions/payments.php b/functions/payments.php index 55d5ed5f..d7bde49c 100644 --- a/functions/payments.php +++ b/functions/payments.php @@ -19,4 +19,4 @@ function getStripeGatewayFee($payment_intent) 'fee' => round($bt->fee / 100, 2), 'currency' => strtoupper($bt->currency), ]; -} \ No newline at end of file +} diff --git a/guest/guest_pay_invoice_stripe.php b/guest/guest_pay_invoice_stripe.php index 2feb8599..317fb7a6 100644 --- a/guest/guest_pay_invoice_stripe.php +++ b/guest/guest_pay_invoice_stripe.php @@ -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);