Let’s say a credit card processor charges a variable rate plus a fixed fee on any credit card transactions. For example, Stripe’s current merchant fee in the US is 2.9% + $0.30. This means that, for a $100 amount charged, the seller is getting only $100 − ($100 × 2.9% + $0.30) = $96.80 after the fee is deducted. In some contexts, sellers will want to make up for the difference by passing the fee on to the customer.

What if the seller wants to add a surcharge to recoup the amount of the processing fee? They can’t just tack on 2.9% + $0.30 to the subtotal, because that surcharge *itself* will incur the processing fee, and the seller will still lose money.

So the formula instead is:

\begin{aligned} p_v &=\text{the variable portion of the processing fee (e.g., 0.029)} \\ p_f &=\text{the fixed portion of the processing fee (e.g., 0.30)} \\ x &=\text{the subtotal} \\ f &=\text{the surcharge needed to recoup the processing fee} \\ \end{aligned} \\ f=\frac{x+p_f}{1-p_v}-x

This follows from a simple derivation. The amount on which the processing fees will be charged is x+f. This means the processing fees are

(x+f)p_v+p_f

What the seller earns after processing fees, then, is the total minus the above fee:

(x+f)-((x+f)p_v+p_f) \\ =(1-p_v)(x+f)-p_f

Our goal is for the expression above (what the seller earns after processing fees are deducted) to end up equal to the subtotal. Now solve for f that makes that true:

\begin{equation*} \begin{aligned} x &= (1-p_v)(x+f) - p_f \\ x+p_f &= (1-p_v)(x+f) \\ \frac{x+p_f}{1-p_v} &= x+f \\ f &=\frac{x+p_f}{1-p_v}-x \\ \end{aligned} \end{equation*}