add code to handle stripe fees

This commit is contained in:
Nathan Coad
2016-07-22 11:21:27 +10:00
parent 75e7f08111
commit b132ed9682
4 changed files with 121 additions and 98 deletions

View File

@@ -790,27 +790,27 @@ function _booking_generate_statistics($booking_list)
}
//figure out if we're in the right time period for discounted registration rates
function _booking_is_earlybird()
{
function _booking_is_earlybird() {
global $event;
if ($event->booking_earlybird_close > time())
if ($event->booking_earlybird_close > time()) {
return TRUE;
else
{
}
else {
return FALSE;
}
}
function _booking_datepaid_ts($nid)
{
function _booking_datepaid_ts($nid) {
$query = db_query("SELECT * FROM {booking_payment} where booking_person_nid = :nid", array(':nid' => $nid))
->fetchObject();
if ($query)
if ($query) {
return $query->booking_payment_date;
else
}
else {
return 0;
}
}
/**
@@ -839,6 +839,29 @@ function _booking_add_paypal_fees($amount, $country)
return $result;
}
/**
* Helper function to calculate stripe transaction fees
*/
function _booking_add_stripe_fees($amount, $country) {
//add the 30 cent fixed cost
$result = '0.00';
$result = (float) ($amount + (float) variable_get('booking_stripe_transaction_fee_fixedcost', '0.3'));
//and the 2.6 percent transaction fee for australian transaction with no currency conversion
if ($country == variable_get('booking_default_country', 'Australia')) {
$percentage = (float) variable_get('booking_stripe_transaction_fee_percentage', '1.75');
} else {
$percentage = (float) variable_get('booking_stripe_transaction_fee_percentage_intl', '2.9');
}
//apply the percentage
$percentage = (float) $percentage / 100;
$result = $result / (1 - $percentage);
//return result
return $result;
}
/**
* Helper function to return the amount for a booking deposit, if there is one
*/
@@ -852,12 +875,19 @@ function _booking_deposit_amount($person, $include_fees = TRUE)
->fetchObject();
if ($deposit) {
//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);
//if we're using paypal or stripe, add the transaction fee
$payment_processor_type = variable_get('booking_payment_processor', 0);
if ($include_fees == TRUE) {
if ($payment_processor_type == 0) {
$amount_owing = _booking_add_paypal_fees($deposit->booking_price, $person->booking_country);
}
elseif ($payment_processor_type == 1) {
$amount_owing = _booking_add_stripe_fees($deposit->booking_price, $person->booking_country);
}
}
//otherwise we're using manual payment processing so don't add any fees
else {
$amount_owing = $deposit->booking_price;
$amount_owing = $deposit->booking_price;
}
//return the calculated amount rounded to two decimal places
return number_format($amount_owing, 2, '.', '');
@@ -1039,13 +1069,18 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_fees = TRUE)
//watchdog('booking', "This person doesn't owe any money: @info", array('@info' => var_export($person, TRUE)));
return 0;
}
//@todo - use booking_payment_processor instead. 0 is paypal, 1 is stripe, 2 is manual
//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($total_due - $amount_paid, $person->booking_country);
//if we're using paypal or stripe, add the transaction fee
$payment_processor_type = variable_get('booking_payment_processor', 0);
if ($include_fees == TRUE) {
if ($payment_processor_type == 0) {
$amount_owing = _booking_add_paypal_fees($total_due - $amount_paid, $person->booking_country);
}
elseif ($payment_processor_type == 1) {
$amount_owing = _booking_add_stripe_fees($total_due - $amount_paid, $person->booking_country);
}
}
//otherwise we're using manual payment processing so don't add any fees
else {
$amount_owing = $total_due - $amount_paid;
}
@@ -1211,8 +1246,7 @@ function _booking_process_refund($person)
$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)
{
if (variable_get('booking_enable_combined_pricing', 0) == 1 && $person->booking_partner_id > 0) {
$refund = $refund - _booking_deposit_amount($person, FALSE);
}
@@ -1270,64 +1304,6 @@ function _booking_process_refund($person)
return $refund;
}
/**
* Helper function to generate paypal form for payments
*/
function _booking_paypal_form($person, $invoiceid, $amount_owing, $button_text) {
$form = drupal_get_form('_booking_paypal_form_builder', $person, $invoiceid, $amount_owing, $button_text);
return drupal_render($form);
}
/**
* Helper function to generate form elements for paypal form
*/
function _booking_paypal_form_builder($node, &$form_state, $person, $invoiceid, $amount_owing, $button_text) {
global $event;
//get our current path so we can send the user back here if they cancel
$path = isset($_GET['q']) ? $_GET['q'] : '<front>';
//paypal specific settings
$vars = array(
'module' => 'Booking System',
'type' => $event->booking_eventname,
//'custom' => $data,
'item_name' => $event->booking_eventname . ' ' . $person->booking_price_descrip,
'invoice' => $invoiceid,
'no_shipping' => TRUE,
'no_note' => TRUE,
'currency_code' => 'AUD',
'return' => url('bookingfinal', array('absolute' => TRUE)),
'cancel_return' => url($path, array('absolute' => TRUE)),
'rm' => '2',
'amount' => $amount_owing,
'last_name' => $person->booking_lastname,
'first_name' => $person->booking_firstname,
'cmd' => '_xclick',
'notify_url' => url(BOOKING_PAYPAL_IPN_PATH, array('absolute' => TRUE)),
'business' => variable_get('booking_paypal_account', '')
);
$form['#action'] = url(variable_get('booking_paypal_sandbox', 0) ? BOOKING_PAYPAL_SUBMIT_URL_SANDBOX : BOOKING_PAYPAL_SUBMIT_URL, array('absolute' => TRUE));
//turn the array into a form
foreach($vars as $name => $value) {
$form[$name] = array(
'#type' => 'hidden',
'#value' => $value,
);
}
$form['submit'] = array(
'#type' => 'button',
'#value' => t($button_text),
);
//watchdog('booking', 'Booking Balance payment: @info', array ('@info' => var_export($form, TRUE)));
return $form;
}
/**
* Helper function to provide a list of columns in the booking_person table
* This will be used to select which fields to import/export to/from a CSV
@@ -1346,7 +1322,6 @@ function _booking_get_person_fields() {
return $list_of_columns;
}
/**
* Helper function to format registrations details for summary in the confirmation email
*/