Last active
January 25, 2024 13:42
-
-
Save jwv/4480539 to your computer and use it in GitHub Desktop.
PHP: Paypal Fees
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.