Files
booking/booking.balance.inc
2016-07-22 16:09:23 +10:00

76 lines
2.8 KiB
PHP

<?php
/**
* Balance payment page for event registration
*/
function booking_balance_page() {
global $event;
$payment_processor_type = variable_get('booking_payment_processor', 0);
$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 token supplied to the balance 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', arg(1), '=')
->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);
} else {
drupal_set_message("Error: Invalid token supplied to the balance payment page. Please use the contact us form to let us know.", 'error', FALSE);
drupal_goto('<front>');
return "";
}
//populate tokens and paypal form
$tokens = booking_define_personspecific_tokens($node);
//if paypal is enabled
if ($payment_processor_type == 0) {
$tokens['paypal-total-form'] = _booking_paypal_form($node, $invoiceid, $tokens['paypal-total-amount'], "Pay Balance");
}
//if stripe is enabled
elseif ($payment_processor_type == 1) {
$tokens['stripe-total-form'] = _booking_stripe_form($node, $invoiceid, $tokens['payment-required'], "Pay Balance");
}
//watchdog('booking_debug', "<pre>Balance page tokens:\n@info</pre>", array('@info' => print_r( $tokens, true)));
//If the amount outstanding is zero, then display information to that effect.
if ($tokens['payment-required'] == 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 ($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 page
return $return_array;
}