Move paypal fee calculations to new function

This commit is contained in:
2015-03-19 13:16:28 +11:00
parent dbae57532d
commit 0c907cc710
2 changed files with 28 additions and 4 deletions

View File

@@ -805,10 +805,28 @@ function _booking_datepaid_ts($nid)
return 0; return 0;
} }
/**
* Helper function to calculate paypal fees
*/
function _booking_add_paypal_fees($amount, $country)
{
//add the 30 cent fixed cost
$result = $amount + 0.3;
//and the 2.6 percent transaction fee
if ($country === "Australia") {
$result = $result / (1 - 0.026);
} else {
watchdog('booking', "This is an international registration.");
$result = $result / (1 - 0.036);
}
return $result;
}
/** /**
* Helper function to return the amount for a booking deposit, if there is one * Helper function to return the amount for a booking deposit, if there is one
*/ */
function _booking_deposit_amount($include_fees = TRUE) function _booking_deposit_amount($person, $include_fees = TRUE)
{ {
global $event; global $event;
@@ -822,10 +840,13 @@ function _booking_deposit_amount($include_fees = TRUE)
//if we're using paypal, add the transaction fee //if we're using paypal, add the transaction fee
if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE) if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE)
{ {
$amount_owing = _booking_add_paypal_fees($deposit->booking_price, $person->booking_country);
/*
//add the 30 cent fixed cost //add the 30 cent fixed cost
$amount_owing = $deposit->booking_price + 0.3; $amount_owing = $deposit->booking_price + 0.3;
//and the 2.4 percent transaction fee //and the 2.4 percent transaction fee
$amount_owing = $amount_owing / (1 - 0.026); $amount_owing = $amount_owing / (1 - 0.026);
*/
} }
else else
{ {
@@ -1026,6 +1047,8 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_paypal_fees =
//if we're using paypal, add the transaction fee //if we're using paypal, add the transaction fee
if (variable_get('booking_use_paypal', 0) == 1 && $include_paypal_fees == TRUE) if (variable_get('booking_use_paypal', 0) == 1 && $include_paypal_fees == TRUE)
{ {
$amount_owing = _booking_add_paypal_fees($total_due - $amount_paid, $person->booking_country);
/*
//add the 30 cent fixed cost //add the 30 cent fixed cost
$amount_owing = $total_due - $amount_paid + 0.3; $amount_owing = $total_due - $amount_paid + 0.3;
//and the 2.4 percent transaction fee //and the 2.4 percent transaction fee
@@ -1038,6 +1061,7 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_paypal_fees =
$amount_owing = $amount_owing / (1 - 0.036); $amount_owing = $amount_owing / (1 - 0.036);
//watchdog('booking', "This is an international registration."); //watchdog('booking', "This is an international registration.");
} }
*/
} }
else else
$amount_owing = $total_due - $amount_paid; $amount_owing = $total_due - $amount_paid;
@@ -1061,12 +1085,12 @@ function _booking_process_refund($person)
{ {
//calculate the refund due //calculate the refund due
//don't include paypal fees in the deposit amount //don't include paypal fees in the deposit amount
$refund = $paid - _booking_deposit_amount(FALSE); $refund = $paid - _booking_deposit_amount($person, FALSE);
//if there is a spouse, subtract their deposit too //if there is a spouse, subtract their deposit too
if (variable_get('booking_enable_combined_pricing', 0) == 1 && $person->booking_partner_id > 0) if (variable_get('booking_enable_combined_pricing', 0) == 1 && $person->booking_partner_id > 0)
{ {
$refund = $refund - _booking_deposit_amount(FALSE); $refund = $refund - _booking_deposit_amount($person, FALSE);
} }
} }

View File

@@ -734,7 +734,7 @@ function booking_define_personspecific_tokens($node)
$tokens['confirm-payment-link'] = url('confirm/' . $tempid, array('absolute' => TRUE)); $tokens['confirm-payment-link'] = url('confirm/' . $tempid, array('absolute' => TRUE));
$tokens['paypal-total-amount'] = _booking_amount_owing($node, $amount_paid); $tokens['paypal-total-amount'] = _booking_amount_owing($node, $amount_paid);
//$tokens['paypal-total-amount'] = _booking_amount_owing($node->nid, $amount_paid); //$tokens['paypal-total-amount'] = _booking_amount_owing($node->nid, $amount_paid);
$tokens['paypal-deposit-amount'] = _booking_deposit_amount(); $tokens['paypal-deposit-amount'] = _booking_deposit_amount($node, TRUE);
$tokens['regn-summary'] = _booking_details_email_summary($node); $tokens['regn-summary'] = _booking_details_email_summary($node);
if (variable_get('booking_enable_travelform', 0) == 1) { if (variable_get('booking_enable_travelform', 0) == 1) {