add code to handle stripe fees
This commit is contained in:
@@ -128,8 +128,8 @@ function booking_admin() {
|
|||||||
);
|
);
|
||||||
$form['paypal']['booking_use_paypal'] = array(
|
$form['paypal']['booking_use_paypal'] = array(
|
||||||
'#type' => 'radios',
|
'#type' => 'radios',
|
||||||
'#title' => t('Use Paypal?'),
|
'#title' => t('Use Paypal? (DEPRECATED)'),
|
||||||
'#description' => t('Select whether to use paypal for automatic payment handling, or process payments manually.'),
|
'#description' => t('Select whether to use paypal for automatic payment handling, or process payments manually. This option is now deprecated. Use the payment processor option below instead.'),
|
||||||
'#options' => array(
|
'#options' => array(
|
||||||
0 => t('No'),
|
0 => t('No'),
|
||||||
t('Yes')
|
t('Yes')
|
||||||
|
@@ -790,28 +790,28 @@ function _booking_generate_statistics($booking_list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//figure out if we're in the right time period for discounted registration rates
|
//figure out if we're in the right time period for discounted registration rates
|
||||||
function _booking_is_earlybird()
|
function _booking_is_earlybird() {
|
||||||
{
|
|
||||||
global $event;
|
global $event;
|
||||||
|
|
||||||
if ($event->booking_earlybird_close > time())
|
if ($event->booking_earlybird_close > time()) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
else
|
}
|
||||||
{
|
else {
|
||||||
return FALSE;
|
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))
|
$query = db_query("SELECT * FROM {booking_payment} where booking_person_nid = :nid", array(':nid' => $nid))
|
||||||
->fetchObject();
|
->fetchObject();
|
||||||
|
|
||||||
if ($query)
|
if ($query) {
|
||||||
return $query->booking_payment_date;
|
return $query->booking_payment_date;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to calculate paypal fees
|
* Helper function to calculate paypal fees
|
||||||
@@ -839,6 +839,29 @@ function _booking_add_paypal_fees($amount, $country)
|
|||||||
return $result;
|
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
|
* Helper function to return the amount for a booking deposit, if there is one
|
||||||
*/
|
*/
|
||||||
@@ -852,10 +875,17 @@ function _booking_deposit_amount($person, $include_fees = TRUE)
|
|||||||
->fetchObject();
|
->fetchObject();
|
||||||
|
|
||||||
if ($deposit) {
|
if ($deposit) {
|
||||||
//if we're using paypal, add the transaction fee
|
//if we're using paypal or stripe, add the transaction fee
|
||||||
if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE) {
|
$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);
|
$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 {
|
else {
|
||||||
$amount_owing = $deposit->booking_price;
|
$amount_owing = $deposit->booking_price;
|
||||||
}
|
}
|
||||||
@@ -1040,12 +1070,17 @@ function _booking_amount_owing($person, $amount_paid = 0, $include_fees = TRUE)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@todo - use booking_payment_processor instead. 0 is paypal, 1 is stripe, 2 is manual
|
//if we're using paypal or stripe, add the transaction fee
|
||||||
|
$payment_processor_type = variable_get('booking_payment_processor', 0);
|
||||||
//if we're using paypal, add the transaction fee
|
if ($include_fees == TRUE) {
|
||||||
if (variable_get('booking_use_paypal', 0) == 1 && $include_fees == TRUE) {
|
if ($payment_processor_type == 0) {
|
||||||
$amount_owing = _booking_add_paypal_fees($total_due - $amount_paid, $person->booking_country);
|
$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 {
|
else {
|
||||||
$amount_owing = $total_due - $amount_paid;
|
$amount_owing = $total_due - $amount_paid;
|
||||||
}
|
}
|
||||||
@@ -1211,8 +1246,7 @@ function _booking_process_refund($person)
|
|||||||
$refund = $paid - _booking_deposit_amount($person, 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($person, FALSE);
|
$refund = $refund - _booking_deposit_amount($person, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1270,64 +1304,6 @@ function _booking_process_refund($person)
|
|||||||
return $refund;
|
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
|
* 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
|
* 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;
|
return $list_of_columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to format registrations details for summary in the confirmation email
|
* Helper function to format registrations details for summary in the confirmation email
|
||||||
*/
|
*/
|
||||||
|
@@ -217,3 +217,60 @@ function booking_payment_completed_page() {
|
|||||||
|
|
||||||
return $return_array;
|
return $return_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
@@ -7,8 +7,8 @@ jQuery(document).ready(function($) {
|
|||||||
locale: 'auto',
|
locale: 'auto',
|
||||||
token: function(token) {
|
token: function(token) {
|
||||||
try {
|
try {
|
||||||
//var $token_id = $(':input[name="token_id"]', $stripeForm);
|
// Use the token to create the charge with a server-side script.
|
||||||
//var $token_email = $(':input[name="token_email"]', $stripeForm);
|
// You can access the token ID with `token.id`
|
||||||
$(':input[name="token_id"]', $stripeForm).val(token.id);
|
$(':input[name="token_id"]', $stripeForm).val(token.id);
|
||||||
$(':input[name="token_email"]', $stripeForm).val(token.email);
|
$(':input[name="token_email"]', $stripeForm).val(token.email);
|
||||||
$stripeForm.get(0).submit();
|
$stripeForm.get(0).submit();
|
||||||
@@ -17,22 +17,13 @@ jQuery(document).ready(function($) {
|
|||||||
console.log([err]);
|
console.log([err]);
|
||||||
alert(err.message);
|
alert(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the token to create the charge with a server-side script.
|
|
||||||
// You can access the token ID with `token.id`
|
|
||||||
//if (currentForm === undefined)
|
|
||||||
// return;
|
|
||||||
//currentForm.find('input[name="token_id"]').val(token.id);
|
|
||||||
//currentForm.find('input[name="token_email"]').val(token.email);
|
|
||||||
//currentForm.submit();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//var currentForm = undefined;
|
|
||||||
|
|
||||||
$('.form-submit').click(function (e) {
|
$('.form-submit').click(function (e) {
|
||||||
currentForm = $(this).closest('form');
|
//currentForm = $(this).closest('form');
|
||||||
if (currentForm === undefined)
|
//if (currentForm === undefined)
|
||||||
return;
|
// return;
|
||||||
var settings = Drupal.settings.booking_stripe;
|
var settings = Drupal.settings.booking_stripe;
|
||||||
var $stripeForm = $("#" + settings.form_selector);
|
var $stripeForm = $("#" + settings.form_selector);
|
||||||
//$description = $(':input[name="description"]', $stripeForm).val();
|
//$description = $(':input[name="description"]', $stripeForm).val();
|
||||||
|
Reference in New Issue
Block a user