92 lines
3.0 KiB
PHP
92 lines
3.0 KiB
PHP
<?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;
|
|
|
|
}
|
|
|