forked from Rezgo/rezgo-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
book_ajax.php
72 lines (53 loc) · 2.69 KB
/
book_ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// This script handles the booking requests made via ajax by book.php
require('rezgo/include/page_header.php');
// start a new instance of RezgoSite
$site = new RezgoSite(secure);
if ($_POST['rezgoAction'] == 'get_paypal_token') {
// send a partial commit (a=get_paypal_token) to get a paypal token for the modal window
// include the return url (this url), so the paypal API can use it in the modal window
if($_POST['mode'] == 'mobile') {
$result = $site->sendBooking(null, 'a=get_paypal_token&paypal_return_url=https://'.$_SERVER['HTTP_HOST'].REZGO_DIR.'/paypal');
} else {
$result = $site->sendBookingOrder(null, '<additional>get_paypal_token</additional><paypal_return_url>https://'.$_SERVER['HTTP_HOST'].REZGO_DIR.'/paypal</paypal_return_url>');
}
$response = ($site->exists($result->paypal_token)) ? $result->paypal_token : 0;
} elseif($_POST['rezgoAction'] == 'book') {
$result = $site->sendBookingOrder();
if ( $result->status == 1 ) {
// start a session so we can save the analytics code
session_start();
$response = 'TXID|*|' . $site->encode($result->trans_num);
// Set a session variable for the analytics to carry to the receipt's first view
$_SESSION['REZGO_CONVERSION_ANALYTICS'] = $result->analytics_convert;
// Add a blank script tag so that this session is detected on the receipt
$_SESSION['REZGO_CONVERSION_ANALYTICS'] .= '<script></script>';
} else {
// this booking failed, send a status code back to the requesting page
if ($result->message == 'Availability Error') { // || $result->message == 'Fatal Error'
$response = 2;
} else if ($result->message == 'Payment Declined' || $result->message == 'Invalid Card Checksum' || $result->message == 'Invalid Card Expiry') {
$response = 3;
} else if ($result->message == 'Account Error') {
// hard system error, no commit requests are allowed if there is no valid payment method
$response = 5;
} else if ($result->message == 'Fatal Error' && $result->error == 'Expected total did not match actual total.') {
$response = 6;
} else {
$response = 4;
}
}
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// ajax response if we requested this page correctly
echo $response;
} else {
// if, for some reason, the ajax form submit failed, then we want to handle the user anyway
die ('Something went wrong during booking. Your booking may have still been completed.');
if ($result->status == 1) {
$site->sendTo("/complete/".$trans_num);
} else {
echo 'ERROR: '.$result->message;
}
}
?>