Completed
Push — master ( a0d185...9fc190 )
by Chris
01:39
created
class/class-edu-sveawebpay.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -375,9 +375,9 @@
 block discarded – undo
375 375
 		}
376 376
 
377 377
 		/**
378
-		 * @param $order_id numeric SVEA WebPay OrderId
379
-		 * @param $booking_id
380
-		 * @param $programme_booking_id
378
+		 * @param integer $order_id numeric SVEA WebPay OrderId
379
+		 * @param integer $booking_id
380
+		 * @param integer $programme_booking_id
381 381
 		 *
382 382
 		 * @return bool If the booking was deleted, due to cancellation
383 383
 		 * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use Svea\WebPay\Config\ConfigurationService;
9 9
 use Svea\WebPay\Response\SveaResponse;
10 10
 
11
-if ( ! class_exists( 'EDU_SveaWebPay' ) ):
11
+if ( !class_exists( 'EDU_SveaWebPay' ) ):
12 12
 
13 13
 	/**
14 14
 	 * EDU_SveaWebPay integrates EduAdmin-WordPress plugin with SveaWebPay as payment gateway
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 
80 80
 			$ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact );
81 81
 
82
-			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
82
+			if ( !empty( EDU()->session['svea-order-id'] ) && !empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
83 83
 				do_action( 'eduadmin-bookingcompleted', $ebi );
84 84
 			} else {
85 85
 				do_action( 'eduadmin-processbooking', $ebi );
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 				return;
96 96
 			}
97 97
 
98
-			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
98
+			if ( !empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
99 99
 				$ebi->NoRedirect = true;
100 100
 			}
101 101
 		}
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 			foreach ( $countries as $country ) {
194 194
 				if ( $invoiceCountry == $country['CountryName'] ) {
195 195
 					$selectedCountry = $country['CountryCode'];
196
-					if ( ! empty( $country['CultureName'] ) ) {
196
+					if ( !empty( $country['CultureName'] ) ) {
197 197
 						$selectedLocale = $country['CultureName'];
198 198
 					}
199 199
 					break;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			$locationCountry    = '';
214 214
 			$locationPostalCode = '';
215 215
 
216
-			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
216
+			if ( !empty( $ebi->EventBooking['BookingId'] ) ) {
217 217
 				$booking_id   = intval( $ebi->EventBooking['BookingId'] );
218 218
 				$reference_id = $booking_id;
219 219
 
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 
222 222
 				$eventName = $_event['EventName'];
223 223
 
224
-				if ( ! empty( $_event['LocationAddress'] ) && $_event['LocationAdress'] != null ) {
224
+				if ( !empty( $_event['LocationAddress'] ) && $_event['LocationAdress'] != null ) {
225 225
 					$locationAddress    = $_event['LocationAddress']['Address'];
226 226
 					$locationCountry    = $_event['LocationAddress']['Country'];
227 227
 					$locationPostalCode = $_event['LocationAddress']['AddressZip'];
228 228
 				}
229 229
 			}
230 230
 
231
-			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
231
+			if ( !empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
232 232
 				$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
233 233
 				$reference_id         = $programme_booking_id;
234 234
 
@@ -257,19 +257,19 @@  discard block
 block discarded – undo
257 257
 
258 258
 			$customer = WebPayItem::companyCustomer();
259 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'];
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 263
 			$city          = $ebi->Customer['BillingInfo']['City'] ? $ebi->Customer['BillingInfo']['City'] : $ebi->Customer['City'];
264 264
 			$phone         = $ebi->Customer['Phone'];
265
-			$email         = ! empty( $ebi->Customer['BillingInfo']['Email'] ) ? $ebi->Customer['BillingInfo']['Email'] : $ebi->Customer['Email'];
265
+			$email         = !empty( $ebi->Customer['BillingInfo']['Email'] ) ? $ebi->Customer['BillingInfo']['Email'] : $ebi->Customer['Email'];
266 266
 
267 267
 			$customer->setCompanyName( $customerName );
268 268
 			$customer->setStreetAddress( $streetAddress );
269 269
 			$customer->setZipCode( $zipCode );
270 270
 			$customer->setLocality( $city );
271 271
 
272
-			if ( ! empty( $phone ) ) {
272
+			if ( !empty( $phone ) ) {
273 273
 				$customer->setPhoneNumber( $phone );
274 274
 				$phonePreset = WebPayItem::presetValue()
275 275
 				                         ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER )
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 				->setConfirmationUri( $defaultThankYou )
341 341
 				->setPushUri( $defaultPushUrl )
342 342
 				->setCheckoutUri( $defaultCancel ); // We have no "checkout"-url.. So we just cancel the booking instead.
343
-			$wpForm  = $wpBuild->createOrder();
343
+			$wpForm = $wpBuild->createOrder();
344 344
 
345 345
 			EDU()->session['svea-order-id'] = $wpForm['OrderId'];
346 346
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 		}
349 349
 
350 350
 		public function process_paymentstatus() {
351
-			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
351
+			if ( !empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && !empty( $_GET['status'] ) ) {
352 352
 
353 353
 				$booking_id           = intval( $_GET['booking_id'] );
354 354
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 				exit( 0 );
359 359
 			}
360 360
 
361
-			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
361
+			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && !empty( $_GET['status'] ) ) {
362 362
 				$booking_id           = intval( $_GET['booking_id'] );
363 363
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
364 364
 
Please login to merge, or discard this patch.
Braces   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 	/**
14 14
 	 * EDU_SveaWebPay integrates EduAdmin-WordPress plugin with SveaWebPay as payment gateway
15 15
 	 */
16
-	class EDU_SveaWebPay extends EDU_Integration {
16
+	class EDU_SveaWebPay extends EDU_Integration {
17 17
 		/**
18 18
 		 * Constructor
19 19
 		 */
20
-		public function __construct() {
20
+		public function __construct() {
21 21
 			$this->id          = 'eduadmin-sveawebpay';
22 22
 			$this->displayName = __( 'Svea Webpay (Checkout)', 'eduadmin-sveawebpay' );
23 23
 			$this->description = '';
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 		/**
38 38
 		 * @param $attributes
39 39
 		 */
40
-		public function test_page( $attributes ) {
40
+		public function test_page( $attributes ) {
41 41
 			$attributes = shortcode_atts(
42 42
 				array(
43 43
 					'bookingid'          => 0,
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 				'test_page'
48 48
 			);
49 49
 
50
-			if ( $attributes['bookingid'] > 0 ) {
50
+			if ( $attributes['bookingid'] > 0 ) {
51 51
 				$event_booking = EDUAPI()->OData->Bookings->GetItem(
52 52
 					$attributes['bookingid'],
53 53
 					null,
54 54
 					'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
55 55
 					false
56 56
 				);
57
-			} elseif ( $attributes['programmebookingid'] > 0 ) {
57
+			} elseif ( $attributes['programmebookingid'] > 0 ) {
58 58
 				$event_booking = EDUAPI()->OData->ProgrammeBookings->GetItem(
59 59
 					$attributes['programmebookingid'],
60 60
 					null,
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 
80 80
 			$ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact );
81 81
 
82
-			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
82
+			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
83 83
 				do_action( 'eduadmin-bookingcompleted', $ebi );
84
-			} else {
84
+			} else {
85 85
 				do_action( 'eduadmin-processbooking', $ebi );
86 86
 			}
87 87
 		}
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 		/**
91 91
 		 * @param EduAdmin_BookingInfo|null $ebi
92 92
 		 */
93
-		public function intercept_booking( $ebi = null ) {
94
-			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
93
+		public function intercept_booking( $ebi = null ) {
94
+			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
95 95
 				return;
96 96
 			}
97 97
 
98
-			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
98
+			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
99 99
 				$ebi->NoRedirect = true;
100 100
 			}
101 101
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		/**
104 104
 		 * Initializes the settingsfields
105 105
 		 */
106
-		public function init_form_fields() {
106
+		public function init_form_fields() {
107 107
 			$this->setting_fields = array(
108 108
 				'enabled'         => array(
109 109
 					'title'       => __( 'Enabled', 'eduadmin-sveawebpay' ),
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 		/**
136 136
 		 *
137 137
 		 */
138
-		public function process_svearesponse() {
139
-			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
138
+		public function process_svearesponse() {
139
+			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
140 140
 				return;
141 141
 			}
142 142
 
143
-			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) ) {
143
+			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) ) {
144 144
 				$booking_id           = intval( $_GET['booking_id'] );
145 145
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
146 146
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 				EDU()->session['svea-order-id'] = null;
150 150
 
151
-				if ( $deleted ) {
151
+				if ( $deleted ) {
152 152
 					@wp_redirect( get_home_url() );
153 153
 					echo "<script type='text/javascript>location.href = '" . esc_js( get_home_url() ) . "';</script>";
154 154
 					exit( 0 );
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
 		/**
160 160
 		 * @param $ebi EduAdmin_BookingInfo|null $bookingInfo
161 161
 		 */
162
-		public function process_booking( $ebi = null ) {
163
-			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
162
+		public function process_booking( $ebi = null ) {
163
+			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
164 164
 				return;
165 165
 			}
166 166
 
167 167
 			$ebi->NoRedirect = true;
168 168
 
169
-			if ( empty( $_GET['svea_order_id'] ) || empty( EDU()->session['svea-order-id'] ) ) {
169
+			if ( empty( $_GET['svea_order_id'] ) || empty( EDU()->session['svea-order-id'] ) ) {
170 170
 				$checkout = $this->create_checkout( $ebi );
171 171
 
172 172
 				$snippet = $checkout['Gui']['Snippet'];
@@ -179,21 +179,21 @@  discard block
 block discarded – undo
179 179
 		 *
180 180
 		 * @returns array
181 181
 		 */
182
-		public function create_checkout( $ebi ) {
182
+		public function create_checkout( $ebi ) {
183 183
 			$countries = EDUAPI()->OData->Countries->Search()['value'];
184 184
 
185 185
 			$selectedCountry = 'SE';
186 186
 			$selectedLocale  = 'sv-SE';
187 187
 
188 188
 			$invoiceCountry = $ebi->Customer['BillingInfo']['Country'];
189
-			if ( empty( $invoiceCountry ) ) {
189
+			if ( empty( $invoiceCountry ) ) {
190 190
 				$invoiceCountry = $ebi->Customer['Country'];
191 191
 			}
192 192
 
193
-			foreach ( $countries as $country ) {
194
-				if ( $invoiceCountry == $country['CountryName'] ) {
193
+			foreach ( $countries as $country ) {
194
+				if ( $invoiceCountry == $country['CountryName'] ) {
195 195
 					$selectedCountry = $country['CountryCode'];
196
-					if ( ! empty( $country['CultureName'] ) ) {
196
+					if ( ! empty( $country['CultureName'] ) ) {
197 197
 						$selectedLocale = $country['CultureName'];
198 198
 					}
199 199
 					break;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			$locationCountry    = '';
214 214
 			$locationPostalCode = '';
215 215
 
216
-			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
216
+			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
217 217
 				$booking_id   = intval( $ebi->EventBooking['BookingId'] );
218 218
 				$reference_id = $booking_id;
219 219
 
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 
222 222
 				$eventName = $_event['EventName'];
223 223
 
224
-				if ( ! empty( $_event['LocationAddress'] ) && $_event['LocationAdress'] != null ) {
224
+				if ( ! empty( $_event['LocationAddress'] ) && $_event['LocationAdress'] != null ) {
225 225
 					$locationAddress    = $_event['LocationAddress']['Address'];
226 226
 					$locationCountry    = $_event['LocationAddress']['Country'];
227 227
 					$locationPostalCode = $_event['LocationAddress']['AddressZip'];
228 228
 				}
229 229
 			}
230 230
 
231
-			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
231
+			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
232 232
 				$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
233 233
 				$reference_id         = $programme_booking_id;
234 234
 
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
 
240 240
 			$currency = EDU()->get_option( 'eduadmin-currency', 'SEK' );
241 241
 
242
-			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
242
+			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
243 243
 				$wpConfig = new EduSveaWebPayTestConfig( $this );
244
-			} else {
244
+			} else {
245 245
 				$wpConfig = new EduSveaWebPayProductionConfig( $this );
246 246
 			}
247 247
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 			$customer->setZipCode( $zipCode );
270 270
 			$customer->setLocality( $city );
271 271
 
272
-			if ( ! empty( $phone ) ) {
272
+			if ( ! empty( $phone ) ) {
273 273
 				$customer->setPhoneNumber( $phone );
274 274
 				$phonePreset = WebPayItem::presetValue()
275 275
 				                         ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER )
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 			return $wpForm;
348 348
 		}
349 349
 
350
-		public function process_paymentstatus() {
351
-			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
350
+		public function process_paymentstatus() {
351
+			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
352 352
 
353 353
 				$booking_id           = intval( $_GET['booking_id'] );
354 354
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 				exit( 0 );
359 359
 			}
360 360
 
361
-			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
361
+			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
362 362
 				$booking_id           = intval( $_GET['booking_id'] );
363 363
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
364 364
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 
367 367
 				EDU()->session['svea-order-id'] = null;
368 368
 
369
-				if ( $deleted ) {
369
+				if ( $deleted ) {
370 370
 					@wp_redirect( get_home_url() );
371 371
 					echo "<script type='text/javascript>location.href = '" . esc_js( get_home_url() ) . "';</script>";
372 372
 					exit( 0 );
@@ -382,10 +382,10 @@  discard block
 block discarded – undo
382 382
 		 * @return bool If the booking was deleted, due to cancellation
383 383
 		 * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
384 384
 		 */
385
-		private function update_booking( $order_id, $booking_id, $programme_booking_id ) {
386
-			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
385
+		private function update_booking( $order_id, $booking_id, $programme_booking_id ) {
386
+			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
387 387
 				$wpConfig = new EduSveaWebPayTestConfig( $this );
388
-			} else {
388
+			} else {
389 389
 				$wpConfig = new EduSveaWebPayProductionConfig( $this );
390 390
 			}
391 391
 
@@ -399,39 +399,39 @@  discard block
 block discarded – undo
399 399
 			$patch_booking                  = new stdClass();
400 400
 			$patch_booking->PaymentMethodId = 2;
401 401
 
402
-			if ( 'Cancelled' === $order['Status'] ) {
402
+			if ( 'Cancelled' === $order['Status'] ) {
403 403
 				$patch_booking->Paid = false;
404 404
 				$delete_booking      = true;
405
-			} else if ( 'Final' === $order['Status'] ) {
405
+			} else if ( 'Final' === $order['Status'] ) {
406 406
 				$patch_booking->Paid = true;
407
-			} else if ( 'Created' === $order['Status'] ) {
407
+			} else if ( 'Created' === $order['Status'] ) {
408 408
 				$patch_booking->Paid = false;
409 409
 			}
410 410
 
411
-			if ( isset( $_GET['status'] ) && 'cancel' === $_GET['status'] ) {
411
+			if ( isset( $_GET['status'] ) && 'cancel' === $_GET['status'] ) {
412 412
 				$patch_booking->Paid = false;
413 413
 				$delete_booking      = true;
414 414
 			}
415 415
 
416
-			if ( $booking_id > 0 ) {
416
+			if ( $booking_id > 0 ) {
417 417
 				EDUAPI()->REST->Booking->PatchBooking(
418 418
 					$booking_id,
419 419
 					$patch_booking
420 420
 				);
421 421
 
422
-				if ( $delete_booking ) {
422
+				if ( $delete_booking ) {
423 423
 					EDUAPI()->REST->Booking->DeleteBooking( $booking_id );
424 424
 				}
425 425
 			}
426 426
 
427
-			if ( $programme_booking_id > 0 ) {
427
+			if ( $programme_booking_id > 0 ) {
428 428
 
429 429
 				EDUAPI()->REST->ProgrammeBooking->PatchBooking(
430 430
 					$programme_booking_id,
431 431
 					$patch_booking
432 432
 				);
433 433
 
434
-				if ( $delete_booking ) {
434
+				if ( $delete_booking ) {
435 435
 					EDUAPI()->REST->ProgrammeBooking->DeleteBooking( $programme_booking_id );
436 436
 				}
437 437
 			}
Please login to merge, or discard this patch.