Files
booking/booking.balance.inc
2013-09-30 12:01:07 +10:00

235 lines
8.8 KiB
PHP

<?php
// $Id: booking.confirm.inc,v 0.1 2011/07/12
/**
* Confirmation page for event registration
*/
function booking_balance_page() {
global $event;
$output = "";
$waiting_list = False;
$already_paid = false;
$paypal_form = "";
//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);
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
//fetch details about the person
$query = db_select('booking_person', 'p');
$query->join('booking_price', 'pr', 'p.booking_payment_id = pr.pid');
$query->condition('p.booking_tempid', arg(1), '=')
->fields('p')
->fields('pr', array('booking_price', 'booking_price_descrip'));
$person = $query->execute()
->fetchObject();
if ($person) {
//maximum length for invoice id is 127 characters
$invoiceid = $person->nid . '_bal' . REQUEST_TIME . '_' . $person->booking_lastname . '-' . $person->booking_firstname;
$invoiceid = substr($invoiceid, 0, 126);
} else {
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
return "";
}
$tokens = booking_define_personspecific_tokens($person);
$tokens['paypal-total-form'] = _booking_paypal_form($person, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
//Calculate the amount outstanding
//watchdog('booking', 'Booking Balance form calculating amount owing');
//$amount_owing = _booking_amount_owing($person->nid);
//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_balance_page'), $tokens);
}
//optional additional text for married people
if ($person->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;
}
/**
* Confirmation page for event registration
*/
/*
function old_booking_balance_page() {
global $event;
$output = "";
$waiting_list = False;
$already_paid = false;
$amount_owing = 0;
$return_array = array();
$output = "";
//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);
return "";
}
//fetch details about the person
$person = db_query("SELECT person.nid, person.booking_event_id, person.booking_lastname, person.booking_firstname, price.booking_buttonid, price.booking_price, price.booking_price_descrip, " .
" person.booking_married, person.booking_partner_name, booking_partner_id, person.booking_amount_paid, person.booking_status " .
"FROM {booking_person} person, {booking_price} price " .
"WHERE booking_tempid = :tempid " .
"AND person.booking_payment_id = price.pid",
array(':tempid' => arg(1)))
->fetchObject();
if ($person) {
//maximum length for invoice id is 127 characters
$invoiceid = $person->nid . '_bal' . REQUEST_TIME . '_' . $person->booking_lastname . '-' . $person->booking_firstname;
$invoiceid = substr($invoiceid, 0, 126);
} else {
drupal_set_message("Unable to find matching session ID " . arg(1), 'error', FALSE);
return "";
}
//set a flag for married couple
$married = $person->booking_partner_id > 0 ? TRUE : FALSE;
if ($married)
$output .= t("<p><br />Hi Mr and Mrs !lastname. Welcome to the payment page for !event, God willing.</p>",
array('!firstname' => $person->booking_firstname, '!lastname' => $person->booking_lastname, '!event' => $event->booking_eventname));
else
$output .= t("<p><br />Hi !firstname !lastname. Welcome to the payment page for !event, God willing.</p>",
array('!firstname' => $person->booking_firstname, '!lastname' => $person->booking_lastname, '!event' => $event->booking_eventname));
//figure out if we're in the right time period for discounted registration rates
$early = db_query("SELECT booking_earlybird_close FROM {booking_event} where eid = :eid", array(
':eid' => $event->eid))
->fetchObject();
if ($early->booking_earlybird_close > time())
$earlybird_flag = TRUE;
else
$earlybird_flag = FALSE;
//Calculate the amount outstanding
$amount_owing = _booking_amount_owing($person->nid);
//If the amount outstanding is zero, then display information to that effect.
if ($amount_owing == 0)
{
$output .= t("<p>Our records indicate that you have already fully paid, so there is no need for you to take any further action.</p>");
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
return $return_array;
}
else
{
if ($earlybird_flag)
{
$output .= t("<p>Our records indicate that you have a balance owing of <strong>$!owing</strong> (including Paypal transaction fees) in order to secure your spot at !event.</p>",
array('!owing' => number_format($amount_owing, 2, '.', ''), '!event' => $event->booking_eventname));
}
else
{
//this payment has missed the early bird rate
$output .= t("<p>Our records indicate that you currently have <strong>$!amount</strong> outstanding (including Paypal transaction fees) to complete your payment for !event," .
" since you have missed the earlybird-rate cutoff date.</p>",
array('!amount' => number_format($amount_owing, 2, '.', ''), '!event' => $event->booking_eventname,
'!earlybird-cutoff' => format_date($early->booking_earlybird_close, 'custom', 'd/m/Y') ));
}
//$output .= t("<p>Our records indicate that you have a balance owing of $!owing in order to secure your spot at !event. ",
// array('!owing' => number_format($amount_owing, 2, '.', ''), '!event' => $event->booking_eventname));
if ($person->booking_status == 2)
{
$output .= t("<p>However, you are currently on the waiting list, and are not required to pay the balance until your place at !event is confirmed.</p>",
array('!event' => $event->booking_eventname));
}
$output .= t("<p>Please use the button below to submit your final payment securely via Paypal.</p>");
$output .= t("<p>Once we have received your payment, you will be sent an automatic confirmation email thanking you for paying your outstanding fees. " .
"If you are paying via Paypal's eCheque feature, please be aware that payments take 3-5 working days to clear, and you will not receive the confirmation email until that has occurred.</p>");
}
//put all the bits together
$return_array[] = array('paragraph' => array('#type' => 'markup', '#markup' => $output));
$return_array[] = array('form' => drupal_get_form('balance_form', arg(1), $person, $invoiceid, $amount_owing));
//return the form
return $return_array;
}
function balance_form($node, &$form_state, $tempid, $person, $invoiceid, $amount_owing) {
global $event;
//paypal specific settings
$vars = array(
'module' => 'Booking System',
'type' => $event->booking_eventname,
//'custom' => $data,
'item_name' => $event->booking_eventname . ' ' . $person->booking_price_descrip . ' balance',
'invoice' => $invoiceid,
'no_shipping' => TRUE,
'no_note' => TRUE,
'currency_code' => 'AUD',
'return' => url('bookingfinal', array('absolute' => TRUE)),
'cancel_return' => url('balance/' . $tempid, 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));
foreach($vars as $name => $value) {
// is this field a forms api element, or just a value?
// if(is_array($value)) {
// $form[$name] = $value;
// $form[$name]['#name'] = $name;
// }
//else {
$form[$name] = array(
'#type' => 'hidden',
'#value' => $value,
);
//}
}
$form['submit'] = array(
'#type' => 'button',
'#value' => t('Continue to Paypal'),
);
watchdog('booking', 'Booking Balance payment: @info', array ('@info' => var_export($form, TRUE)));
return $form;
}
*/