Get Expense from Stripe instead of Static Entry

This commit is contained in:
johnnyq
2026-07-22 16:07:39 -04:00
parent 54e2005224
commit 66b38b7f19
6 changed files with 66 additions and 208 deletions

22
functions/payments.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
/*
* Extract the actual Stripe processing fee from a PaymentIntent.
* PI must have been created/retrieved with
* 'expand' => ['latest_charge.balance_transaction'].
* Returns ['fee' => float, 'currency' => 'USD'] or false if unavailable.
*/
function getStripeGatewayFee($payment_intent)
{
$bt = $payment_intent->latest_charge->balance_transaction ?? null;
// Not expanded or not yet created (async payment methods)
if (!$bt || is_string($bt)) {
return false;
}
return [
'fee' => round($bt->fee / 100, 2),
'currency' => strtoupper($bt->currency),
];
}