Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chron's avatar
Level 6

Paypal fees calculation

I just noticed that paypal has a fee. I’m using EUR as a currency, so it is not that accurate when I manually convert the amount to USD just to add the paypal fees then convert it back to EUR.

Is there a way to automatically include it in the calculation before going to the actual paypal page?

The additional paypal fee is 2.9% + $0.3 per transactions.

I tried this function, but it's not that accurate.

function memfees($amount)
{
    $amount += .30;
    return $amount / (1 - .029);
}
0 likes
7 replies
jlrdw's avatar

Doesn't the exchange amount differ daily or weekly you may need a lookup table. Find a service that has current exchange rates that you can use. As far as the conversion should be just some basic math.

Chron's avatar
Level 6

Yes, I tried that. But the paypal's calculation is always cents off.

Eg.

//50 EUR = 55.54 USD

function paypalFees(amt) {
  let percentage = amt * .029;
  amt -= percentage + .30;
  return amt;
}

paypalFees(50);

// 53.62934 USD

// 48.28 EUR

while paypal's calculation was only 48.20 EUR

jlrdw's avatar

it stands to reason you will need to find out what PayPal is basing their calculation on. I take it you are passing on that charge to the customer.

We did things slightly different we absorbed the charges and at each month we would have a income table and expense table.

jlrdw's avatar

Have you dug into the API, I would imagine there is something in their api as how to handle this during a transaction. I'd say at least look it over.

Chron's avatar
Level 6

It seems like the exchange rate is the one that makes the amount change.

From Paypal's Help Center

Here’s how we set our exchange rate: We receive a wholesale rate quote from our bank twice a day and add a percentage to determine the retail foreign exchange rate to apply to transactions that involve a currency conversion. Our currency exchange rates are competitive with conversion rates used by banks and by currency exchanges. When you transfer from your PayPal account to your local bank account, we automatically convert the money into the local currency when the transfer is initiated.

I think the only solution now is converting the amount base on the rate of paypal then do the calculations. But that's not possible afaik. ConvertCurrency API belongs to Paypal's Adaptive Payments, but I'm using ExpressCheckout.

martinbean's avatar

@chron Yes, payment providers charge you fees to send and receive payments. That’s kinda how they make their money.

I wouldn’t rely on trying to calculate a fee in code, because if PayPal updates their fee structure then your code is immediately out of date and calculating incorrect values.

So either price your product/service to account for payment processing fees, or make the customer pay the fee, but don’t rely on being able to calculate the fee before setting the amount to be charged.

Chron's avatar
Level 6

Hmm. I'm sorry if I misunderstood you. So should I increase the price of the product? But when the fees have increased, the seller would receive less money, so it's just the same as calculating the fee before charging the buyer.

Please or to participate in this conversation.