Skip to content

Commit 28cde8a

Browse files
committed
Moved booking_key creation to be a step later than before
1 parent b4bdb91 commit 28cde8a

8 files changed

Lines changed: 159 additions & 127 deletions

File tree

inc/config-example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
$result_type = 'simplexml';
1919

2020
// Set the response URL, only required if being used by a Tour Operator
21-
// Point this to ".....step2.php?tour_id={tour_id}"
21+
// Point this to ".....step3.php?tour_id={tour_id}"
2222
// Explanation here: http://www.tourcms.com/support/api/mp/booking_getkey.php
23-
$response_url = "http://www.example.com/very-basic-booking-engine/step2.php?tour={tour_id}";
23+
$response_url = "http://www.example.com/very-basic-booking-engine/step3.php?tour={tour_id}";
2424

2525
// Create a new Instance of the TourCMS API class
2626
$tourcms = new TourCMS($marketplace_account_id, $api_private_key, $result_type);

inc/top.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5-
<title>List of Tours/Hotels</title>
5+
<title><?php print $title; ?></title>
66
<link rel="stylesheet" href="inc/style.css" />
77
</head>
88
<body>

step0.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
55
Lists Tours/Hotels available in the API
66
*/
7-
7+
$title = "List of Tours/Hotels";
88
include_once("inc/top.php");
99
?>
10-
<h1>List of Tours/Hotels</h1>
10+
<h1><?php print $title; ?></h1>
1111
<p>Not strictly part of the booking process, included here for navigation purposes, all Tours/Hotels <a href="http://www.tourcms.com/support/api/mp/useful.php" target="_blank">made available for the API</a> should be listed below:</p>
1212

1313

step1.php

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,94 @@
1-
<?php
1+
<?php
22
/*
33
step1.php
44
5+
Calls the "Show Tour" API method
6+
Displays passenger number and date selection form
7+
based on the data returned
58
6-
7-
This page should be invisible to the user
8-
they will be redirected from here to TourCMS
9-
then subsequently on to step2.php
109
*/
10+
$title = "Numbers of people and dates";
11+
include_once("inc/top.php");
1112

1213
// Include the config file
1314
include('inc/config.php');
14-
15-
// Create a new SimpleXMLElement to hold the response url
16-
$url_data = new SimpleXMLElement('<url />');
1715

18-
// Add the response url, TourCMS will redirect to this, appending the key
19-
$url_data->addChild('response_url', str_replace("{tour_id}", (int)$_GET['tour'], $response_url));
16+
// Tour ID based on previous selection should be in the querystring
17+
isset($_GET['tour']) ? $tour = (int)$_GET['tour'] : exit();
2018

21-
// Send the response URL to TourCMS
22-
$result = $tourcms->get_booking_redirect_url($url_data, $channel_id);
19+
// Query the TourCMS API, get back all the info on this Tour/Hotel
20+
$result = $tourcms->show_tour($tour, $channel_id);
2321

24-
// TourCMS should have returned a URL back to us, get that
25-
$redirect_url = $result->url->redirect_url;
22+
// Jump straight to the bit of XML related to making a new booking panel
23+
// includes rate and date info
24+
$booking_criteria = $result->tour->new_booking;
25+
?>
26+
<h1><?php print $title; ?></h1>
27+
<p>Below you should be able to select the number of people for each rate that is loaded against this Tour/Hotel (Adults, Children, Premium etc) plus a start date entry. In the case of hotel products there will also be a box for the duration.</p>
28+
<form action="step2.php" method="post">
2629

27-
// Redirect the customer to the URL obtained from TourCMS
28-
header("Location: " . $redirect_url);
29-
exit();
30+
<?php
31+
$rates = array();
3032

31-
?><pre><?php print_r($result); ?></pre>
33+
// Process the available rates for this Tour/Hotel
34+
foreach ($booking_criteria->people_selection->rate as $rate) {
35+
$rates[] = (string)$rate->rate_id;
36+
// Process the labels
37+
// Label_1 might be blank, for
38+
(string)$rate->label_1 != "" ? $label = $rate->label_1 : $label = "Number of People";
39+
(string)$rate->label_2 != "" ? $label .= "(" . $rate->label_2 . ")" : null;
40+
?>
41+
<label><?php print $label; ?>
42+
<select name="<?php print $rate->rate_id; ?>">
43+
<?php
44+
$count = (int)$rate->minimum;
45+
$max = (int)$rate->maximum;
46+
47+
while($count <= $max) {
48+
?>
49+
<option><?php print $count; ?></option>
50+
<?php
51+
$count ++;
52+
}
53+
?>
54+
</select>
55+
</label>
56+
<?php
57+
}
58+
59+
// Set some sensible default time
60+
$default_date = strtotime("+2 weeks Saturday");
61+
?>
62+
<label>Date:<input type="text" name="date" value="<?php print date("Y-m-d", $default_date); ?>" /></label>
63+
<?php
64+
$date_type = $booking_criteria->date_selection->date_type;
65+
if($date_type == "DATE_NIGHTS" || $date_type == "DATE_DAYS"):
66+
$min_hdur = 7;
67+
$max_hdur = 21;
68+
$def_hdur = (int)$result->tour->duration;
69+
?>
70+
<select name="hdur">
71+
<?php
72+
for($i=$min_hdur; $i<=$max_hdur; $i++):
73+
?>
74+
<option value="<?php print $i; ?>"<?php
75+
$i==$def_hdur ? print ' selected="selected"' : null;
76+
?>><?php print $i; ?></option>
77+
<?php
78+
endfor;
79+
?>
80+
</select>
81+
<?
82+
endif;
83+
?>
84+
85+
<input type="hidden" name="rates" value="<?php print implode(",", $rates); ?>" />
86+
<input type="hidden" name="tour" value="<?php print $tour; ?>" />
87+
88+
<input type="submit" name="submit" value="Go" />
89+
</form>
90+
91+
<?php
92+
include_once("inc/debug.php");
93+
include_once("inc/bottom.php");
94+
?>

step2.php

Lines changed: 46 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,57 @@
1-
<?php
1+
<?php
22
/*
33
step2.php
44
5-
Calls the "Show Tour" API method
6-
Displays passenger number and date selection form
7-
based on the data returned
8-
5+
This page should be invisible to the user
6+
they will be redirected from here to TourCMS
7+
then subsequently on to step3.php
98
*/
109

11-
include_once("inc/top.php");
12-
1310
// Include the config file
1411
include('inc/config.php');
1512

16-
// We need a booking key if we are calling the API as a Tour Operator
17-
// Marketplace Partner accounts won't have one and don't need one
18-
isset($_GET['booking_key']) ? $booking_key = $_GET['booking_key'] : $booking_key = "";
19-
20-
// Tour ID based on previous selection should be in the querystring
21-
isset($_GET['tour']) ? $tour = (int)$_GET['tour'] : exit();
22-
23-
// Query the TourCMS API, get back all the info on this Tour/Hotel
24-
$result = $tourcms->show_tour($tour, $channel_id);
25-
26-
// Jump straight to the bit of XML related to making a new booking panel
27-
// includes rate and date info
28-
$booking_criteria = $result->tour->new_booking;
29-
?>
30-
<h1>Numbers of people and dates</h1>
31-
<form action="step3.php" method="post">
3213

33-
<?php
34-
$rates = array();
35-
36-
// Process the available rates for this Tour/Hotel
37-
foreach ($booking_criteria->people_selection->rate as $rate) {
38-
$rates[] = (string)$rate->rate_id;
39-
// Process the labels
40-
// Label_1 might be blank, for
41-
(string)$rate->label_1 != "" ? $label = $rate->label_1 : $label = "Number of People";
42-
(string)$rate->label_2 != "" ? $label .= "(" . $rate->label_2 . ")" : null;
43-
?>
44-
<label><?php print $label; ?>
45-
<select name="<?php print $rate->rate_id; ?>">
46-
<?php
47-
$count = (int)$rate->minimum;
48-
$max = (int)$rate->maximum;
49-
50-
while($count <= $max) {
51-
?>
52-
<option><?php print $count; ?></option>
53-
<?php
54-
$count ++;
55-
}
56-
?>
57-
</select>
58-
</label>
59-
<?php
14+
// Process the form
15+
$qs = "";
16+
// Date
17+
isset($_POST['date']) ? $date = $_POST['date'] : $date = "";
18+
$qs .= "&date=" . $date;
19+
// Duration
20+
isset($_POST['hdur']) ? $hdur = $_POST['hdur'] : $hdur = "";
21+
$qs .= "&hdur=" . $hdur;
22+
// Rates & number of people
23+
isset($_POST['rates']) ? $rate_string = $_POST['rates'] : exit();
24+
$qs .= "&rates=" . $rate_string;
25+
$rates = explode(",", $rate_string);
26+
$total_people = 0;
27+
foreach ($rates as $rate) {
28+
if(isset($_POST[$rate])) {
29+
$rate_count = (int)$_POST[$rate];
30+
31+
if($rate_count > 0) {
32+
$qs .= "&" . $rate . "=" . $rate_count;
33+
$total_people += $rate_count;
34+
}
6035
}
36+
}
37+
$qs .= "&total_people=" . $total_people;
38+
39+
// Create a new SimpleXMLElement to hold the response url
40+
$url_data = new SimpleXMLElement('<url />');
41+
42+
// Add the response url, TourCMS will redirect to this, appending the key
43+
$response_url = str_replace("{tour_id}", (int)$_POST['tour'], $response_url) . $qs;
44+
$url_data->addChild('response_url', htmlentities($response_url));
45+
//$url_data->addChild('response_url', "http://tourcmsdev.macbook/scratch/api/bookings/step3.php?qs=" . urlencode("tour=" . (int)$_POST['tour'] . $qs));
46+
47+
// Send the response URL to TourCMS
48+
$result = $tourcms->get_booking_redirect_url($url_data, $channel_id);
49+
50+
// TourCMS should have returned a URL back to us, get that
51+
$redirect_url = $result->url->redirect_url;
52+
53+
// Redirect the customer to the URL obtained from TourCMS
54+
header("Location: " . $redirect_url);
55+
exit();
6156

62-
// Set some sensible default time
63-
$default_date = strtotime("+2 weeks Saturday");
64-
?>
65-
<label>Date:<input type="text" name="date" value="<?php print date("Y-m-d", $default_date); ?>" /></label>
66-
<?php
67-
$date_type = $booking_criteria->date_selection->date_type;
68-
if($date_type == "DATE_NIGHTS" || $date_type == "DATE_DAYS"):
69-
$min_hdur = 7;
70-
$max_hdur = 21;
71-
$def_hdur = (int)$result->tour->duration;
72-
?>
73-
<select name="hdur">
74-
<?php
75-
for($i=$min_hdur; $i<=$max_hdur; $i++):
76-
?>
77-
<option value="<?php print $i; ?>"<?php
78-
$i==$def_hdur ? print ' selected="selected"' : null;
79-
?>><?php print $i; ?></option>
80-
<?php
81-
endfor;
82-
?>
83-
</select>
84-
<?
85-
endif;
86-
?>
87-
88-
<input type="hidden" name="rates" value="<?php print implode(",", $rates); ?>" />
89-
<input type="hidden" name="tour" value="<?php print $tour; ?>" />
90-
<input type="hidden" name="booking_key" value="<?php print $booking_key; ?>" />
91-
92-
<input type="submit" name="submit" value="Go" />
93-
</form>
94-
95-
<?php
96-
include_once("inc/debug.php");
97-
include_once("inc/bottom.php");
98-
?>
57+
?><pre><?php htmlspecialchars(print($url_data->asXML())); ?></pre><pre><?php print_r($result); ?></pre><pre><?php print $redirect_url; ?></pre>

step3.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Boxes for customer details displayed
99
1010
*/
11-
11+
$title = "Availability confirmed, enter passenger details";
1212
include_once("inc/top.php");
1313

1414
// Include the config file
@@ -18,27 +18,28 @@
1818
$qs = "";
1919

2020
if($marketplace_account_id == 0)
21-
isset($_POST['booking_key']) ? $booking_key = $_POST['booking_key'] : exit();
21+
isset($_GET['booking_key']) ? $booking_key = $_GET['booking_key'] : exit();
2222

23-
isset($_POST['date']) ? $date = $_POST['date'] : exit();
23+
isset($_GET['date']) ? $date = $_GET['date'] : exit();
24+
2425

2526
$qs .= "date=" . $date;
2627

27-
isset($_POST['hdur']) ? $hdur = $_POST['hdur'] : $hdur = null;
28+
isset($_GET['hdur']) ? $hdur = $_GET['hdur'] : $hdur = null;
2829

2930
isset($hdur) ? $qs .= "&hdur=" . $hdur : null;
3031

31-
isset($_POST['rates']) ? $rate_string = $_POST['rates'] : exit();
32+
isset($_GET['rates']) ? $rate_string = $_GET['rates'] : exit();
3233

33-
isset($_POST['tour']) ? $tour = (int)$_POST['tour'] : exit();
34+
isset($_GET['tour']) ? $tour = (int)$_GET['tour'] : exit();
3435

3536
$rates = explode(",", $rate_string);
3637

3738
$total_people = 0;
3839

3940
foreach ($rates as $rate) {
40-
if(isset($_POST[$rate])) {
41-
$rate_count = (int)$_POST[$rate];
41+
if(isset($_GET[$rate])) {
42+
$rate_count = (int)$_GET[$rate];
4243

4344
if($rate_count > 0) {
4445
$qs .= "&" . $rate . "=" . $rate_count;
@@ -53,7 +54,10 @@
5354
isset($result->available_components->component) ? $num_components = count($result->available_components->component) : $num_components = 0;
5455

5556
?>
56-
<h1>Availability confirmed, enter passenger details</h1>
57+
<h1><?php print $title; ?></h1>
58+
<?php
59+
if($num_components>0) : ?>
60+
<p>We have checked availability based on the rate and date selection, the available components should be displayed below alongside boxes for customer detail entry.</p>
5761
<form method="post" action="step4.php" />
5862
<?php
5963
if($marketplace_account_id == 0) :
@@ -67,21 +71,24 @@
6771
<fieldset>
6872
<table>
6973
<?php
70-
71-
if($num_components > 0) {
74+
$counter = 1;
75+
7276
foreach ($result->available_components->component as $component) {
7377
?>
7478
<tr>
75-
<td><input type="radio" name="component_key" value="<?php print $component->component_key; ?>" /></td>
79+
<td><input type="radio" name="component_key" value="<?php print $component->component_key; ?>"<?php
80+
($counter==1) ? print "checked" : null;
81+
?> /></td>
7682
<td><?php print $component->date_code; ?></td>
7783
<td><?php print $component->start_date; ?></td>
7884
<td><?php print ($component->end_date != $component->start_date ? $component->end_date : null ); ?></td>
7985
<td><?php print $component->note . $component->special_offer_note; ?></td>
8086
<td><?php print $component->total_price_display; ?></td>
8187
</tr>
8288
<?php
89+
$counter ++;
8390
}
84-
}
91+
8592
?>
8693
</table>
8794
</fieldset>
@@ -110,7 +117,10 @@
110117
?>
111118
<input type="submit" name="submit" value="Go" />
112119
</form>
113-
120+
<?php
121+
else:
122+
print "Sorry no availability, please go back and try a different date / number of passengers";
123+
endif; ?>
114124

115125
<?php
116126
include_once("inc/debug.php");

0 commit comments

Comments
 (0)