Completed
Push — master ( a0d185...9fc190 )
by Chris
01:39
created

EDU_SveaWebPay::process_booking()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
defined( 'ABSPATH' ) or die( 'This plugin must be run within the scope of WordPress.' );
3
4
require_once( __DIR__ . '/class-edu-sveawebpay-config.php' );
5
6
use Svea\WebPay\WebPay;
7
use Svea\WebPay\WebPayItem;
8
use Svea\WebPay\Config\ConfigurationService;
9
use Svea\WebPay\Response\SveaResponse;
10
11
if ( ! class_exists( 'EDU_SveaWebPay' ) ):
12
13
	/**
14
	 * EDU_SveaWebPay integrates EduAdmin-WordPress plugin with SveaWebPay as payment gateway
15
	 */
16
	class EDU_SveaWebPay extends EDU_Integration {
17
		/**
18
		 * Constructor
19
		 */
20
		public function __construct() {
21
			$this->id          = 'eduadmin-sveawebpay';
22
			$this->displayName = __( 'Svea Webpay (Checkout)', 'eduadmin-sveawebpay' );
23
			$this->description = '';
24
			$this->type        = 'payment';
25
26
			$this->init_form_fields();
27
			$this->init_settings();
28
29
			add_action( 'eduadmin-checkpaymentplugins', array( $this, 'intercept_booking' ) );
30
			add_action( 'eduadmin-processbooking', array( $this, 'process_booking' ) );
31
			add_action( 'eduadmin-bookingcompleted', array( $this, 'process_svearesponse' ) );
32
			add_action( 'wp_loaded', array( $this, 'process_paymentstatus' ) );
33
34
			add_shortcode( 'eduadmin-svea-testpage', array( $this, 'test_page' ) );
35
		}
36
37
		/**
38
		 * @param $attributes
39
		 */
40
		public function test_page( $attributes ) {
41
			$attributes = shortcode_atts(
42
				array(
43
					'bookingid'          => 0,
44
					'programmebookingid' => 0,
45
				),
46
				normalize_empty_atts( $attributes ),
47
				'test_page'
48
			);
49
50
			if ( $attributes['bookingid'] > 0 ) {
51
				$event_booking = EDUAPI()->OData->Bookings->GetItem(
52
					$attributes['bookingid'],
53
					null,
54
					'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
55
					false
56
				);
57
			} elseif ( $attributes['programmebookingid'] > 0 ) {
58
				$event_booking = EDUAPI()->OData->ProgrammeBookings->GetItem(
59
					$attributes['programmebookingid'],
60
					null,
61
					'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
62
					false
63
				);
64
			}
65
66
			$_customer = EDUAPI()->OData->Customers->GetItem(
67
				$event_booking['Customer']['CustomerId'],
0 ignored issues
show
Bug introduced by
The variable $event_booking does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
68
				null,
69
				"BillingInfo",
70
				false
71
			);
72
73
			$_contact = EDUAPI()->OData->Persons->GetItem(
74
				$event_booking['ContactPerson']['PersonId'],
75
				null,
76
				null,
77
				false
78
			);
79
80
			$ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact );
81
82
			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
83
				do_action( 'eduadmin-bookingcompleted', $ebi );
84
			} else {
85
				do_action( 'eduadmin-processbooking', $ebi );
86
			}
87
		}
88
89
90
		/**
91
		 * @param EduAdmin_BookingInfo|null $ebi
92
		 */
93
		public function intercept_booking( $ebi = null ) {
94
			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
95
				return;
96
			}
97
98
			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
99
				$ebi->NoRedirect = true;
100
			}
101
		}
102
103
		/**
104
		 * Initializes the settingsfields
105
		 */
106
		public function init_form_fields() {
107
			$this->setting_fields = array(
108
				'enabled'         => array(
109
					'title'       => __( 'Enabled', 'eduadmin-sveawebpay' ),
110
					'type'        => 'checkbox',
111
					'description' => __( 'Enables/Disables the integration with Svea WebPay', 'eduadmin-sveawebpay' ),
112
					'default'     => 'no',
113
				),
114
				'testrun'         => array(
115
					'title'       => __( 'Sandbox mode', 'eduadmin-sveawebpay' ),
116
					'type'        => 'checkbox',
117
					'description' => __( 'Activate sandbox mode', 'eduadmin-sveawebpay' ),
118
					'default'     => 'no',
119
				),
120
				'merchant_key'    => array(
121
					'title'       => __( 'Merchant key', 'eduadmin-sveawebpay' ),
122
					'type'        => 'text',
123
					'description' => __( 'Please enter your merchant key from Svea WebPay.', 'eduadmin-sveawebpay' ),
124
					'placeholder' => __( 'Merchant key', 'eduadmin-sveawebpay' ),
125
				),
126
				'merchant_secret' => array(
127
					'title'       => __( 'Merchant secret', 'eduadmin-sveawebpay' ),
128
					'type'        => 'password',
129
					'description' => __( 'Please enter your merchant secret from Svea WebPay', 'eduadmin-sveawebpay' ),
130
					'placeholder' => __( 'Merchant secret', 'eduadmin-sveawebpay' ),
131
				),
132
			);
133
		}
134
135
		/**
136
		 *
137
		 */
138
		public function process_svearesponse() {
139
			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
140
				return;
141
			}
142
143 View Code Duplication
			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
				$booking_id           = intval( $_GET['booking_id'] );
145
				$programme_booking_id = intval( $_GET['programme_booking_id'] );
146
147
				$deleted = $this->update_booking( intval( EDU()->session['svea-order-id'] ), $booking_id, $programme_booking_id );
148
149
				EDU()->session['svea-order-id'] = null;
150
151
				if ( $deleted ) {
152
					@wp_redirect( get_home_url() );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
153
					echo "<script type='text/javascript>location.href = '" . esc_js( get_home_url() ) . "';</script>";
154
					exit( 0 );
155
				}
156
			}
157
		}
158
159
		/**
160
		 * @param $ebi EduAdmin_BookingInfo|null $bookingInfo
161
		 */
162
		public function process_booking( $ebi = null ) {
163
			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
164
				return;
165
			}
166
167
			$ebi->NoRedirect = true;
168
169
			if ( empty( $_GET['svea_order_id'] ) || empty( EDU()->session['svea-order-id'] ) ) {
170
				$checkout = $this->create_checkout( $ebi );
171
172
				$snippet = $checkout['Gui']['Snippet'];
173
				echo "<div>{$snippet}</div>";
174
			}
175
		}
176
177
		/**
178
		 * @param $ebi EduAdmin_BookingInfo|null
179
		 *
180
		 * @returns array
181
		 */
182
		public function create_checkout( $ebi ) {
183
			$countries = EDUAPI()->OData->Countries->Search()['value'];
184
185
			$selectedCountry = 'SE';
186
			$selectedLocale  = 'sv-SE';
187
188
			$invoiceCountry = $ebi->Customer['BillingInfo']['Country'];
189
			if ( empty( $invoiceCountry ) ) {
190
				$invoiceCountry = $ebi->Customer['Country'];
191
			}
192
193
			foreach ( $countries as $country ) {
194
				if ( $invoiceCountry == $country['CountryName'] ) {
195
					$selectedCountry = $country['CountryCode'];
196
					if ( ! empty( $country['CultureName'] ) ) {
197
						$selectedLocale = $country['CultureName'];
198
					}
199
					break;
200
				}
201
			}
202
203
			$booking_id           = 0;
204
			$programme_booking_id = 0;
205
206
			$reference_id = 0;
207
208
			$_event = null;
0 ignored issues
show
Unused Code introduced by
$_event is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
209
210
			$eventName = '';
211
212
			$locationAddress    = '';
0 ignored issues
show
Unused Code introduced by
$locationAddress is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
213
			$locationCountry    = '';
0 ignored issues
show
Unused Code introduced by
$locationCountry is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
214
			$locationPostalCode = '';
0 ignored issues
show
Unused Code introduced by
$locationPostalCode is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
215
216
			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
217
				$booking_id   = intval( $ebi->EventBooking['BookingId'] );
218
				$reference_id = $booking_id;
219
220
				$_event = EDUAPI()->OData->Events->GetItem( $ebi->EventBooking['EventId'], null, "LocationAddress" );
221
222
				$eventName = $_event['EventName'];
223
224
				if ( ! empty( $_event['LocationAddress'] ) && $_event['LocationAdress'] != null ) {
225
					$locationAddress    = $_event['LocationAddress']['Address'];
0 ignored issues
show
Unused Code introduced by
$locationAddress is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
226
					$locationCountry    = $_event['LocationAddress']['Country'];
0 ignored issues
show
Unused Code introduced by
$locationCountry is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
227
					$locationPostalCode = $_event['LocationAddress']['AddressZip'];
0 ignored issues
show
Unused Code introduced by
$locationPostalCode is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
228
				}
229
			}
230
231
			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
232
				$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
233
				$reference_id         = $programme_booking_id;
234
235
				$_event = EDUAPI()->OData->ProgrammeStarts->GetItem( $ebi->EventBooking['ProgrammeStartId'] );
236
237
				$eventName = $_event['ProgrammeStartName'];
238
			}
239
240
			$currency = EDU()->get_option( 'eduadmin-currency', 'SEK' );
241
242 View Code Duplication
			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
243
				$wpConfig = new EduSveaWebPayTestConfig( $this );
244
			} else {
245
				$wpConfig = new EduSveaWebPayProductionConfig( $this );
246
			}
247
248
			$wpOrder = WebPay::checkout( $wpConfig );
249
250
			$orderRow = WebPayItem::orderRow();
251
			$orderRow->setName( $eventName );
252
			$orderRow->setQuantity( 1 );
253
254
			$vatPercent = ( $ebi->EventBooking['VatSum'] / $ebi->EventBooking['TotalPriceExVat'] ) * 100;
255
			$orderRow->setVatPercent( $vatPercent );
256
			$orderRow->setAmountIncVat( (float) $ebi->EventBooking['TotalPriceIncVat'] );
257
258
			$customer = WebPayItem::companyCustomer();
259
260
			$customerName  = ! empty( $ebi->Customer['BillingInfo']['InvoiceName'] ) ? $ebi->Customer['BillingInfo']['InvoiceName'] : $ebi->Customer['CustomerName'];
261
			$streetAddress = ! empty( $ebi->Customer['BillingInfo']['Address'] ) ? $ebi->Customer['BillingInfo']['Address'] : $ebi->Customer['Address'];
262
			$zipCode       = ! empty( $ebi->Customer['BillingInfo']['Zip'] ) ? $ebi->Customer['BillingInfo']['Zip'] : $ebi->Customer['Zip'];
263
			$city          = $ebi->Customer['BillingInfo']['City'] ? $ebi->Customer['BillingInfo']['City'] : $ebi->Customer['City'];
264
			$phone         = $ebi->Customer['Phone'];
265
			$email         = ! empty( $ebi->Customer['BillingInfo']['Email'] ) ? $ebi->Customer['BillingInfo']['Email'] : $ebi->Customer['Email'];
266
267
			$customer->setCompanyName( $customerName );
268
			$customer->setStreetAddress( $streetAddress );
269
			$customer->setZipCode( $zipCode );
270
			$customer->setLocality( $city );
271
272
			if ( ! empty( $phone ) ) {
273
				$customer->setPhoneNumber( $phone );
274
				$phonePreset = WebPayItem::presetValue()
275
				                         ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER )
276
				                         ->setValue( $phone )
277
				                         ->setIsReadonly( false );
278
				$wpOrder->addPresetValue( $phonePreset );
279
			}
280
			$customer->setEmail( $email );
281
282
			$zipPreset = WebPayItem::presetValue()
283
			                       ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::POSTAL_CODE )
284
			                       ->setValue( $zipCode )
285
			                       ->setIsReadonly( false );
286
			$wpOrder->addPresetValue( $zipPreset );
287
288
			$emailPreset = WebPayItem::presetValue()
289
			                         ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::EMAIL_ADDRESS )
290
			                         ->setValue( $email )
291
			                         ->setIsReadonly( false );
292
			$wpOrder->addPresetValue( $emailPreset );
293
294
			$current_url = esc_url( "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" );
295
296
			$defaultThankYou = add_query_arg(
297
				array(
298
					'edu-thankyou'         => $reference_id,
299
					'svea'                 => '1',
300
					'booking_id'           => $booking_id,
301
					'programme_booking_id' => $programme_booking_id,
302
					'edu-valid-form'       => wp_create_nonce( 'edu-booking-confirm' ),
303
					'act'                  => 'paymentCompleted',
304
				),
305
				@get_page_link( get_option( 'eduadmin-thankYouPage', '/' ) )
306
			);
307
308
			$defaultCancel = add_query_arg(
309
				array(
310
					'edu-thankyou'         => $reference_id,
311
					'svea'                 => '1',
312
					'booking_id'           => $booking_id,
313
					'programme_booking_id' => $programme_booking_id,
314
					'status'               => 'cancel'
315
				),
316
				$current_url
317
			);
318
319
			$defaultPushUrl = add_query_arg(
320
				array(
321
					'edu-thankyou'         => $reference_id,
322
					'svea'                 => '1',
323
					'booking_id'           => $booking_id,
324
					'programme_booking_id' => $programme_booking_id,
325
					'svea_order_id'        => '{checkout.order.uri}',
326
					'status'               => 'push'
327
				),
328
				$current_url
329
			);
330
331
			$defaultTermsUrl = get_option( 'eduadmin-bookingTermsLink' );
332
333
			$wpBuild = $wpOrder
334
				->setCurrency( $currency )
335
				->setCountryCode( $selectedCountry )
336
				->setClientOrderNumber( $reference_id )
337
				->addOrderRow( $orderRow )
338
				->setLocale( $selectedLocale )
339
				->setTermsUri( $defaultTermsUrl )
340
				->setConfirmationUri( $defaultThankYou )
341
				->setPushUri( $defaultPushUrl )
342
				->setCheckoutUri( $defaultCancel ); // We have no "checkout"-url.. So we just cancel the booking instead.
343
			$wpForm  = $wpBuild->createOrder();
344
345
			EDU()->session['svea-order-id'] = $wpForm['OrderId'];
346
347
			return $wpForm;
348
		}
349
350
		public function process_paymentstatus() {
351
			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
352
353
				$booking_id           = intval( $_GET['booking_id'] );
354
				$programme_booking_id = intval( $_GET['programme_booking_id'] );
355
356
				$this->update_booking( intval( $_GET['svea_order_id'] ), $booking_id, $programme_booking_id );
357
358
				exit( 0 );
359
			}
360
361 View Code Duplication
			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
362
				$booking_id           = intval( $_GET['booking_id'] );
363
				$programme_booking_id = intval( $_GET['programme_booking_id'] );
364
365
				$deleted = $this->update_booking( intval( EDU()->session['svea-order-id'] ), $booking_id, $programme_booking_id );
366
367
				EDU()->session['svea-order-id'] = null;
368
369
				if ( $deleted ) {
370
					@wp_redirect( get_home_url() );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
371
					echo "<script type='text/javascript>location.href = '" . esc_js( get_home_url() ) . "';</script>";
372
					exit( 0 );
373
				}
374
			}
375
		}
376
377
		/**
378
		 * @param $order_id numeric SVEA WebPay OrderId
379
		 * @param $booking_id
380
		 * @param $programme_booking_id
381
		 *
382
		 * @return bool If the booking was deleted, due to cancellation
383
		 * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
384
		 */
385
		private function update_booking( $order_id, $booking_id, $programme_booking_id ) {
386 View Code Duplication
			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
387
				$wpConfig = new EduSveaWebPayTestConfig( $this );
388
			} else {
389
				$wpConfig = new EduSveaWebPayProductionConfig( $this );
390
			}
391
392
			$wpOrder = WebPay::checkout( $wpConfig );
393
			$wpOrder->setCheckoutOrderId( $order_id );
394
395
			$order = $wpOrder->getOrder();
396
397
			$delete_booking = false;
398
399
			$patch_booking                  = new stdClass();
400
			$patch_booking->PaymentMethodId = 2;
401
402
			if ( 'Cancelled' === $order['Status'] ) {
403
				$patch_booking->Paid = false;
404
				$delete_booking      = true;
405
			} else if ( 'Final' === $order['Status'] ) {
406
				$patch_booking->Paid = true;
407
			} else if ( 'Created' === $order['Status'] ) {
408
				$patch_booking->Paid = false;
409
			}
410
411
			if ( isset( $_GET['status'] ) && 'cancel' === $_GET['status'] ) {
412
				$patch_booking->Paid = false;
413
				$delete_booking      = true;
414
			}
415
416
			if ( $booking_id > 0 ) {
417
				EDUAPI()->REST->Booking->PatchBooking(
418
					$booking_id,
419
					$patch_booking
420
				);
421
422
				if ( $delete_booking ) {
423
					EDUAPI()->REST->Booking->DeleteBooking( $booking_id );
424
				}
425
			}
426
427
			if ( $programme_booking_id > 0 ) {
428
429
				EDUAPI()->REST->ProgrammeBooking->PatchBooking(
430
					$programme_booking_id,
431
					$patch_booking
432
				);
433
434
				if ( $delete_booking ) {
435
					EDUAPI()->REST->ProgrammeBooking->DeleteBooking( $programme_booking_id );
436
				}
437
			}
438
439
			return $delete_booking;
440
		}
441
	}
442
443
endif;
444