Skip to content

Instantly share code, notes, and snippets.

@jwv
Last active January 25, 2024 13:42
Show Gist options
  • Save jwv/4480539 to your computer and use it in GitHub Desktop.
Save jwv/4480539 to your computer and use it in GitHub Desktop.
PHP: Paypal Fees
function paypalFees($sub_total, $round_fee) {
// Set Fee Rate Variables
$fee_percent = '3.4'; // Paypal's percentage rate per transaction (3.4% in UK)
$fee_cash = '0.20'; // Paypal's set cash amount per transaction (£0.20 in UK)
// Calculate Fees
$paypal_fee = ((($sub_total / 100) * $fee_percent) + $fee_cash);
if ($round_fee == true) {
$paypal_fee = ceil($paypal_fee);
}
// Calculate Grand Total
$grand_total = ($sub_total + $paypal_fee);
// Tidy Up Numbers
$sub_total = number_format($sub_total, 2, '.', ',');
$paypal_fee = number_format($paypal_fee, 2, '.', ',');
$grand_total = number_format($grand_total, 2, '.', ',');
// Return Array
return [
'grand_total'=>$grand_total,
'paypal_fee'=>$paypal_fee,
'sub_total'=>$sub_total,
];
}
@extraa75213603
Copy link

Are you using PayPal but concerned about transaction fees? No need to worry! We have the solution: the Paypal Fee Calculator . It's here to assist you in calculating transaction fees worldwide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment