I hope this helps at all, if not, ignore!
According to Stripe's pricing documentation, fees also vary by:
Card type (debit vs credit)
International vs domestic transactions
Processing method (online vs in-person)
Your specific Stripe agreement
Dispute and chargeback fees
From reviewing the Stripe API documentation, the actual fee information isn't directly in the charge object. You need to access the Balance Transaction:
Charge Object (Stripe Charges API):
- Contains
balance_transaction
field with transaction ID
Balance Transaction Object (Stripe Balance Transactions API):
fee
- actual fee in cents
fee_details
- array breaking down fee components
net
- amount after all fees
Maybe this would do it:
`// Get the charge (ITFlow probably already does this)
$charge = \Stripe\Charge::retrieve($charge_id);
// Get the balance transaction (this is the missing piece)
$balance_txn = \Stripe\BalanceTransaction::retrieve($charge->balance_transaction);
// Store actual values instead of calculated ones
$gross_amount = $charge->amount / 100;
$actual_fee = $balance_txn->fee / 100;
$net_amount = $balance_txn->net / 100;
`
The fixed percentage from settings would need to be replaced with the balance transaction API call.
According to Stripe's webhook documentation, listening for charge.succeeded
events and then pulling the balance transaction data ensures you get the final, accurate fee data.
Based on Stripe's documentation on refunds and disputes:
Refunds create separate balance transactions with negative fees
Disputes generate additional balance transactions
Each needs to be tracked separately