Added partial payment option
This commit is contained in:
@@ -14,7 +14,8 @@ function booking_balance_page() {
|
||||
//verify that arg(1) is a uuid
|
||||
if (! preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) {
|
||||
//parameter from url is not what we were expecting
|
||||
drupal_set_message("Error: Invalid session ID supplied. Please use the contact us form to let us know.", 'error', FALSE);
|
||||
drupal_set_message("Error: Invalid session ID supplied to the balance payment page. Please use the contact us form to let us know.", 'error', FALSE);
|
||||
drupal_goto('<front>');
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,8 @@ function booking_confirm_page() {
|
||||
//verify that arg(1) is a uuid
|
||||
if (! preg_match('/^[0-9A-Fa-f\-]+$/', arg(1))) {
|
||||
//parameter from url is not what we were expecting
|
||||
drupal_set_message("Error: Invalid session ID supplied. Please use the contact us form to let us know.", 'error', FALSE);
|
||||
drupal_set_message("Error: Invalid session ID supplied to the registration confirmation page. Please use the contact us form to let us know.", 'error', FALSE);
|
||||
drupal_goto('<front>');
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@@ -164,6 +164,47 @@ function _booking_balance_payment_email($nid)
|
||||
$params['headers']['Bcc'] = "it@coadcorp.com";
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate email to be sent to the registrant thanking them for a partial balance payment
|
||||
*
|
||||
* @param $nid - the registration node
|
||||
*/
|
||||
function _booking_partialbalance_payment_email($nid)
|
||||
{
|
||||
global $event;
|
||||
global $user;
|
||||
$language = user_preferred_language($user);
|
||||
|
||||
//load the node matching this id
|
||||
$node = node_load($nid);
|
||||
$tokens = booking_define_personspecific_tokens($node);
|
||||
|
||||
if ($tokens['payment-required'] <= 0)
|
||||
{
|
||||
watchdog('booking', "Not sending amount owing email, since this person doesn't owe any money: @info", array('@info' => var_export($node, TRUE)));
|
||||
return;
|
||||
}
|
||||
|
||||
//calculate the from email address
|
||||
$from = t('!event Registrations <!email>', array('!event' => $event->booking_eventname,
|
||||
'!email' => variable_get('booking_contact_email', variable_get('site_mail', ini_get('sendmail_from')))
|
||||
));
|
||||
|
||||
//calculate the remaining parameters
|
||||
$to = $node->booking_email;
|
||||
$subject = t('!event Partial Payment Required', array('!event' => $event->booking_eventname));
|
||||
$params['subject'] = $subject;
|
||||
$params['headers']['Bcc'] = "it@coadcorp.com, " . variable_get('booking_notify_email', variable_get('site_mail', ini_get('sendmail_from')));
|
||||
|
||||
//TODO: Married couple version of this
|
||||
$params['body'] = token_replace(variable_get('booking_email_partialpayment_received_text'), $tokens);
|
||||
|
||||
//send the email
|
||||
drupal_mail('booking', 'registration_mail_bal_outstanding', $to, $language, $params, $from);
|
||||
$params['headers']['Bcc'] = "it@coadcorp.com";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to generate email to be sent to the registrant based on custom email template configured in text tokens page
|
||||
*
|
||||
|
@@ -33,6 +33,8 @@ module_load_include('inc', 'booking', 'booking.register');
|
||||
module_load_include('inc', 'booking', 'booking.confirm');
|
||||
// Load the include that contains the registration balance payment page
|
||||
module_load_include('inc', 'booking', 'booking.balance');
|
||||
// Load the include that contains the registration partial balance payment page
|
||||
module_load_include('inc', 'booking', 'booking.partialbalance');
|
||||
// Load the include that contains the registration reports pages
|
||||
module_load_include('inc', 'booking', 'booking.reports');
|
||||
// Load the include for the admin pages
|
||||
@@ -222,6 +224,14 @@ function booking_menu() {
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
$items['partpay/%/%'] = array(
|
||||
'title' => 'Registration Partial Payment',
|
||||
'page callback' => 'booking_partial_balance_page',
|
||||
'page arguments' => array(4), //include the temporary id and the amount
|
||||
'access arguments' => array('access booking form'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
$items['travel/%'] = array(
|
||||
'title' => 'Travel Details Page',
|
||||
'page callback' => 'booking_travel_page',
|
||||
|
91
booking.partialbalance.inc
Normal file
91
booking.partialbalance.inc
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// $Id: booking.confirm.inc,v 0.1 2011/07/12
|
||||
|
||||
/**
|
||||
* Page to allow partial payment of outstanding fees
|
||||
*/
|
||||
function booking_partial_balance_page() {
|
||||
global $event;
|
||||
$output = "";
|
||||
$waiting_list = False;
|
||||
$already_paid = false;
|
||||
$paypal_form = "";
|
||||
$temp_id = arg(1);
|
||||
$partial_amount = arg(2);
|
||||
|
||||
//verify that arg(1) is a uuid
|
||||
if (! preg_match('/^[0-9A-Fa-f\-]+$/', $temp_id)) {
|
||||
//parameter from url is not what we were expecting
|
||||
drupal_set_message("Error: Invalid session ID supplied to the partial payment page. Please use the contact us form to let us know.", 'error', FALSE);
|
||||
drupal_goto('<front>');
|
||||
return "";
|
||||
}
|
||||
|
||||
//verify that arg(2) is a number
|
||||
if (! preg_match('/^[0-9]+$/', $partial_amount)) {
|
||||
drupal_set_message("Error: Invalid payment amount supplied to the partial payment page. Please use the contact us form to let us know.", 'error', FALSE);
|
||||
drupal_goto('<front>');
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
//TODO: if the person says they're married, query to see if they're listed partner has already registered and paid
|
||||
//if they have, then let the new registration person know their partner has already paid, and send them the confirmation email
|
||||
|
||||
//work out the node id from the session id
|
||||
$query = db_select('booking_person', 'p');
|
||||
$query->condition('p.booking_tempid', $temp_id, '=')
|
||||
->fields('p', array('nid'));
|
||||
$person = $query->execute()
|
||||
->fetchObject();
|
||||
|
||||
if ($person)
|
||||
{
|
||||
//load all the fields
|
||||
$node = node_load($person->nid);
|
||||
//calculate the invoice ID
|
||||
$invoiceid = $person->nid . '_bal' . REQUEST_TIME . '_' . $node->booking_lastname . '-' . $node->booking_firstname;
|
||||
//maximum length for invoice id in paypal is 127 characters so truncate if necessary
|
||||
$invoiceid = substr($invoiceid, 0, 126);
|
||||
//there was no matching session id in the database
|
||||
} else {
|
||||
drupal_set_message("Unable to find matching session ID " . $temp_id, 'error', FALSE);
|
||||
drupal_goto('<front>');
|
||||
return "";
|
||||
}
|
||||
|
||||
//populate tokens
|
||||
$tokens = booking_define_personspecific_tokens($node);
|
||||
|
||||
//check they're not trying to pay too much
|
||||
if ($partial_amount > $tokens['paypal-total-amount'])
|
||||
{
|
||||
//just use the normal amount instead
|
||||
$partial_amount = $tokens['paypal-total-amount'];
|
||||
}
|
||||
|
||||
//generate the paypal form
|
||||
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $partial_amount, "Pay $" . $partial_amount);
|
||||
|
||||
//If the amount outstanding is zero, then display information to that effect.
|
||||
if ($tokens['paypal-total-amount'] == 0)
|
||||
{
|
||||
$output = token_replace(variable_get('booking_regn_balance_page_paid'), $tokens);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = token_replace(variable_get('booking_regn_partial_balance_page'), $tokens);
|
||||
//optional additional text for married people
|
||||
if ($node->booking_married == 'Y')
|
||||
$output .= token_replace(variable_get('booking_regn_balance_married_text'), $tokens);
|
||||
}
|
||||
|
||||
//put all the bits together
|
||||
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
|
||||
//$return_array[] = array('form' => $paypal_form);
|
||||
|
||||
//return the form
|
||||
return $return_array;
|
||||
|
||||
}
|
||||
|
@@ -255,6 +255,8 @@ function _booking_process_payment($data) {
|
||||
{
|
||||
watchdog('booking', 'This balance payment of !payment was insufficient for !id to completely pay the total outstanding of !outstanding.',
|
||||
array('!id' => $nid, '!payment' => $data['mc_gross'], '!outstanding' => $amount_owing));
|
||||
//send the person an email thanking them for their partial payment
|
||||
_booking_partialbalance_payment_email($nid);
|
||||
//TODO: create an email specifically for partial-balance payments
|
||||
//_booking_registration_email($nid, $balance_payment);
|
||||
}
|
||||
|
@@ -233,6 +233,12 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
|
||||
//'#format' => 'full_html',
|
||||
//'#default_value' => $booking_regn_balance_married_text['value'],
|
||||
);
|
||||
$form['balance']['booking_regn_partial_balance_page'] = array(
|
||||
'#title' => t('Text to use on the partial balance payment page.'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_regn_partial_balance_page', ''),
|
||||
);
|
||||
|
||||
/*People reporting pages*/
|
||||
$form['people_lists'] = array(
|
||||
@@ -335,6 +341,13 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_regn_complete_text', $booking_email_regn_complete_text),
|
||||
);
|
||||
$form['emails']['booking_email_partialpayment_received_text'] = array(
|
||||
'#title' => t('Email text to send a person thanking them for their partial payment'),
|
||||
'#type' => 'textarea',
|
||||
//'#format' => 'full_html',
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_partialpayment_received_text', ''),
|
||||
);
|
||||
$form['emails']['booking_email_waitinglist_text'] = array(
|
||||
'#title' => t('Email text to indicate a person has registered but is on the waiting list'),
|
||||
'#type' => 'textarea',
|
||||
@@ -355,6 +368,7 @@ $booking_registration_intro_text = variable_get('booking_registration_intro_text
|
||||
'#description' => t(''),
|
||||
'#default_value' => variable_get('booking_email_paymentoutstanding_text', $booking_email_paymentoutstanding_text),
|
||||
);
|
||||
|
||||
$form['emails']['booking_email_paymentoutstanding_married_text'] = array(
|
||||
'#title' => t('Email text to send a married couple reminding them of how much they both owe (only applies when combined pricing enabled)'),
|
||||
'#type' => 'textarea',
|
||||
|
Reference in New Issue
Block a user