From 0c907cc710ca81ebea4b90c49a3c0094c9ad4105 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Thu, 19 Mar 2015 13:16:28 +1100 Subject: [PATCH] Move paypal fee calculations to new function --- booking.helper.inc | 30 +++++++++++++++++++++++++++--- booking.tokens.inc | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/booking.helper.inc b/booking.helper.inc index c7c36b6..5c38ed6 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -805,10 +805,28 @@ function _booking_datepaid_ts($nid) 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 */ -function _booking_deposit_amount($include_fees = TRUE) +function _booking_deposit_amount($person, $include_fees = TRUE) { global $event; @@ -822,10 +840,13 @@ function _booking_deposit_amount($include_fees = TRUE) //if we're using paypal, add the transaction fee 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 $amount_owing = $deposit->booking_price + 0.3; //and the 2.4 percent transaction fee $amount_owing = $amount_owing / (1 - 0.026); + */ } 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 (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 $amount_owing = $total_due - $amount_paid + 0.3; //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); //watchdog('booking', "This is an international registration."); } + */ } else $amount_owing = $total_due - $amount_paid; @@ -1061,12 +1085,12 @@ function _booking_process_refund($person) { //calculate the refund due //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 (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); } } diff --git a/booking.tokens.inc b/booking.tokens.inc index 49eab4d..a6833b8 100644 --- a/booking.tokens.inc +++ b/booking.tokens.inc @@ -734,7 +734,7 @@ function booking_define_personspecific_tokens($node) $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->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); if (variable_get('booking_enable_travelform', 0) == 1) {