Archive for Tag "paypal"

Paypal Fee Script

// calculate paypal fees
// http://snipplr.com/view.php?codeview&id=44373

<?php

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 array('grand_total'=>$grand_total, 'paypal_fee'=>$paypal_fee, 'sub_total'=>$sub_total);
}