Completed
Push — master ( 4147c2...077ccb )
by Chris
23s
created
class/class-edu-sveawebpay.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use Svea\WebPay\WebPay;
7 7
 use Svea\WebPay\WebPayItem;
8 8
 
9
-if ( ! class_exists( 'EDU_SveaWebPay' ) ):
9
+if ( !class_exists( 'EDU_SveaWebPay' ) ):
10 10
 
11 11
 	/**
12 12
 	 * EDU_SveaWebPay integrates EduAdmin-WordPress plugin with SveaWebPay as payment gateway
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
 			$ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact );
79 79
 
80
-			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
80
+			if ( !empty( EDU()->session['svea-order-id'] ) && !empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
81 81
 				do_action( 'eduadmin-bookingcompleted', $ebi );
82 82
 			} else {
83 83
 				do_action( 'eduadmin-processbooking', $ebi );
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 				return;
94 94
 			}
95 95
 
96
-			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
96
+			if ( !empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
97 97
 				$ebi->NoRedirect = true;
98 98
 			}
99 99
 		}
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			foreach ( $countries as $country ) {
190 190
 				if ( $invoiceCountry == $country['CountryName'] ) {
191 191
 					$selectedCountry = $country['CountryCode'];
192
-					if ( ! empty( $country['CultureName'] ) ) {
192
+					if ( !empty( $country['CultureName'] ) ) {
193 193
 						$selectedLocale = $country['CultureName'];
194 194
 					}
195 195
 					break;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 
206 206
 			$eventName = '';
207 207
 
208
-			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
208
+			if ( !empty( $ebi->EventBooking['BookingId'] ) ) {
209 209
 				$booking_id   = intval( $ebi->EventBooking['BookingId'] );
210 210
 				$reference_id = $booking_id;
211 211
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 				$eventName = $_event['EventName'];
215 215
 			}
216 216
 
217
-			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
217
+			if ( !empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
218 218
 				$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
219 219
 				$reference_id         = $programme_booking_id;
220 220
 
@@ -235,19 +235,19 @@  discard block
 block discarded – undo
235 235
 
236 236
 			$customer = WebPayItem::companyCustomer();
237 237
 
238
-			$customerName  = ! empty( $ebi->Customer['BillingInfo']['InvoiceName'] ) ? $ebi->Customer['BillingInfo']['InvoiceName'] : $ebi->Customer['CustomerName'];
239
-			$streetAddress = ! empty( $ebi->Customer['BillingInfo']['Address'] ) ? $ebi->Customer['BillingInfo']['Address'] : $ebi->Customer['Address'];
240
-			$zipCode       = ! empty( $ebi->Customer['BillingInfo']['Zip'] ) ? $ebi->Customer['BillingInfo']['Zip'] : $ebi->Customer['Zip'];
241
-			$city          = ! empty ( $ebi->Customer['BillingInfo']['City'] ) ? $ebi->Customer['BillingInfo']['City'] : $ebi->Customer['City'];
238
+			$customerName  = !empty( $ebi->Customer['BillingInfo']['InvoiceName'] ) ? $ebi->Customer['BillingInfo']['InvoiceName'] : $ebi->Customer['CustomerName'];
239
+			$streetAddress = !empty( $ebi->Customer['BillingInfo']['Address'] ) ? $ebi->Customer['BillingInfo']['Address'] : $ebi->Customer['Address'];
240
+			$zipCode       = !empty( $ebi->Customer['BillingInfo']['Zip'] ) ? $ebi->Customer['BillingInfo']['Zip'] : $ebi->Customer['Zip'];
241
+			$city          = !empty ( $ebi->Customer['BillingInfo']['City'] ) ? $ebi->Customer['BillingInfo']['City'] : $ebi->Customer['City'];
242 242
 			$phone         = $ebi->Customer['Phone'];
243
-			$email         = ! empty( $ebi->Customer['BillingInfo']['Email'] ) ? $ebi->Customer['BillingInfo']['Email'] : $ebi->Customer['Email'];
243
+			$email         = !empty( $ebi->Customer['BillingInfo']['Email'] ) ? $ebi->Customer['BillingInfo']['Email'] : $ebi->Customer['Email'];
244 244
 
245 245
 			$customer->setCompanyName( $customerName );
246 246
 			$customer->setStreetAddress( $streetAddress );
247 247
 			$customer->setZipCode( $zipCode );
248 248
 			$customer->setLocality( $city );
249 249
 
250
-			if ( ! empty( $phone ) ) {
250
+			if ( !empty( $phone ) ) {
251 251
 				$customer->setPhoneNumber( $phone );
252 252
 				$phonePreset = WebPayItem::presetValue()
253 253
 				                         ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER )
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 		}
374 374
 
375 375
 		public function process_paymentstatus() {
376
-			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
376
+			if ( !empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && !empty( $_GET['status'] ) ) {
377 377
 
378 378
 				$booking_id           = intval( $_GET['booking_id'] );
379 379
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				exit( 0 );
384 384
 			}
385 385
 
386
-			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
386
+			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && !empty( $_GET['status'] ) ) {
387 387
 				$booking_id           = intval( $_GET['booking_id'] );
388 388
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
389 389
 
Please login to merge, or discard this patch.
Braces   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 	/**
12 12
 	 * EDU_SveaWebPay integrates EduAdmin-WordPress plugin with SveaWebPay as payment gateway
13 13
 	 */
14
-	class EDU_SveaWebPay extends EDU_Integration {
14
+	class EDU_SveaWebPay extends EDU_Integration {
15 15
 		/**
16 16
 		 * Constructor
17 17
 		 */
18
-		public function __construct() {
18
+		public function __construct() {
19 19
 			$this->id          = 'eduadmin-sveawebpay';
20 20
 			$this->displayName = __( 'Svea Webpay (Checkout)', 'eduadmin-sveawebpay' );
21 21
 			$this->description = '';
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		/**
36 36
 		 * @param $attributes
37 37
 		 */
38
-		public function test_page( $attributes ) {
38
+		public function test_page( $attributes ) {
39 39
 			$attributes = shortcode_atts(
40 40
 				array(
41 41
 					'bookingid'          => 0,
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 				'test_page'
46 46
 			);
47 47
 
48
-			if ( $attributes['bookingid'] > 0 ) {
48
+			if ( $attributes['bookingid'] > 0 ) {
49 49
 				$event_booking = EDUAPI()->OData->Bookings->GetItem(
50 50
 					$attributes['bookingid'],
51 51
 					null,
52 52
 					'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
53 53
 					false
54 54
 				);
55
-			} elseif ( $attributes['programmebookingid'] > 0 ) {
55
+			} elseif ( $attributes['programmebookingid'] > 0 ) {
56 56
 				$event_booking = EDUAPI()->OData->ProgrammeBookings->GetItem(
57 57
 					$attributes['programmebookingid'],
58 58
 					null,
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 
78 78
 			$ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact );
79 79
 
80
-			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
80
+			if ( ! empty( EDU()->session['svea-order-id'] ) && ! empty( $_GET['svea_order_id'] ) && EDU()->session['svea-order-id'] === $_GET['svea_order_id'] ) {
81 81
 				do_action( 'eduadmin-bookingcompleted', $ebi );
82
-			} else {
82
+			} else {
83 83
 				do_action( 'eduadmin-processbooking', $ebi );
84 84
 			}
85 85
 		}
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 		/**
89 89
 		 * @param EduAdmin_BookingInfo|null $ebi
90 90
 		 */
91
-		public function intercept_booking( $ebi = null ) {
92
-			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
91
+		public function intercept_booking( $ebi = null ) {
92
+			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
93 93
 				return;
94 94
 			}
95 95
 
96
-			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
96
+			if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
97 97
 				$ebi->NoRedirect = true;
98 98
 			}
99 99
 		}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		/**
102 102
 		 * Initializes the settingsfields
103 103
 		 */
104
-		public function init_form_fields() {
104
+		public function init_form_fields() {
105 105
 			$this->setting_fields = array(
106 106
 				'enabled'         => array(
107 107
 					'title'       => __( 'Enabled', 'eduadmin-sveawebpay' ),
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
 		/**
134 134
 		 *
135 135
 		 */
136
-		public function process_svearesponse() {
137
-			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
136
+		public function process_svearesponse() {
137
+			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
138 138
 				return;
139 139
 			}
140 140
 
141
-			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) ) {
141
+			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) ) {
142 142
 				$booking_id           = intval( $_GET['booking_id'] );
143 143
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
144 144
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
 				EDU()->session['svea-order-id'] = null;
148 148
 
149
-				if ( $deleted ) {
149
+				if ( $deleted ) {
150 150
 					$this->handle_cancelled_payment();
151 151
 				}
152 152
 			}
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
 		/**
156 156
 		 * @param $ebi EduAdmin_BookingInfo|null $bookingInfo
157 157
 		 */
158
-		public function process_booking( $ebi = null ) {
159
-			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
158
+		public function process_booking( $ebi = null ) {
159
+			if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
160 160
 				return;
161 161
 			}
162 162
 
163 163
 			$ebi->NoRedirect = true;
164 164
 
165
-			if ( empty( $_GET['svea_order_id'] ) || empty( EDU()->session['svea-order-id'] ) ) {
165
+			if ( empty( $_GET['svea_order_id'] ) || empty( EDU()->session['svea-order-id'] ) ) {
166 166
 				$checkout = $this->create_checkout( $ebi );
167 167
 
168 168
 				$snippet = $checkout['Gui']['Snippet'];
@@ -175,21 +175,21 @@  discard block
 block discarded – undo
175 175
 		 *
176 176
 		 * @returns array
177 177
 		 */
178
-		public function create_checkout( $ebi ) {
178
+		public function create_checkout( $ebi ) {
179 179
 			$countries = EDUAPI()->OData->Countries->Search()['value'];
180 180
 
181 181
 			$selectedCountry = 'SE';
182 182
 			$selectedLocale  = 'sv-SE';
183 183
 
184 184
 			$invoiceCountry = $ebi->Customer['BillingInfo']['Country'];
185
-			if ( empty( $invoiceCountry ) ) {
185
+			if ( empty( $invoiceCountry ) ) {
186 186
 				$invoiceCountry = $ebi->Customer['Country'];
187 187
 			}
188 188
 
189
-			foreach ( $countries as $country ) {
190
-				if ( $invoiceCountry == $country['CountryName'] ) {
189
+			foreach ( $countries as $country ) {
190
+				if ( $invoiceCountry == $country['CountryName'] ) {
191 191
 					$selectedCountry = $country['CountryCode'];
192
-					if ( ! empty( $country['CultureName'] ) ) {
192
+					if ( ! empty( $country['CultureName'] ) ) {
193 193
 						$selectedLocale = $country['CultureName'];
194 194
 					}
195 195
 					break;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 
206 206
 			$eventName = '';
207 207
 
208
-			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
208
+			if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
209 209
 				$booking_id   = intval( $ebi->EventBooking['BookingId'] );
210 210
 				$reference_id = $booking_id;
211 211
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 				$eventName = $_event['EventName'];
215 215
 			}
216 216
 
217
-			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
217
+			if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
218 218
 				$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
219 219
 				$reference_id         = $programme_booking_id;
220 220
 
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
 
226 226
 			$currency = EDU()->get_option( 'eduadmin-currency', 'SEK' );
227 227
 
228
-			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
228
+			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
229 229
 				$wpConfig = new EduSveaWebPayTestConfig( $this );
230
-			} else {
230
+			} else {
231 231
 				$wpConfig = new EduSveaWebPayProductionConfig( $this );
232 232
 			}
233 233
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 			$customer->setZipCode( $zipCode );
248 248
 			$customer->setLocality( $city );
249 249
 
250
-			if ( ! empty( $phone ) ) {
250
+			if ( ! empty( $phone ) ) {
251 251
 				$customer->setPhoneNumber( $phone );
252 252
 				$phonePreset = WebPayItem::presetValue()
253 253
 				                         ->setTypeName( \Svea\WebPay\Checkout\Model\PresetValue::PHONE_NUMBER )
@@ -343,18 +343,18 @@  discard block
 block discarded – undo
343 343
 
344 344
 			$wpBuild->addOrderRow( $orderRow );
345 345
 
346
-			foreach ( $ebi->EventBooking['OrderRows'] as $eduOrderRow ) {
346
+			foreach ( $ebi->EventBooking['OrderRows'] as $eduOrderRow ) {
347 347
 				$orderRow = WebPayItem::orderRow();
348 348
 				$orderRow->setName( substr( $eduOrderRow['Description'], 0, 40 ) );
349 349
 				$orderRow->setQuantity( $eduOrderRow['Quantity'] );
350 350
 
351 351
 				$orderRow->setVatPercent( $eduOrderRow['VatPercent'] );
352 352
 
353
-				if ( $eduOrderRow['PriceIncVat'] ) {
353
+				if ( $eduOrderRow['PriceIncVat'] ) {
354 354
 					$orderRow->setAmountIncVat( $eduOrderRow['TotalPrice'] );
355
-				} else {
355
+				} else {
356 356
 					$priceInclVat = $eduOrderRow['TotalPrice'];
357
-					if ( $eduOrderRow['VatPercent'] > 0 ) {
357
+					if ( $eduOrderRow['VatPercent'] > 0 ) {
358 358
 						$priceInclVat = $eduOrderRow['TotalPrice'] * ( 1 + ( $eduOrderRow['VatPercent'] / 100 ) );
359 359
 					}
360 360
 					$orderRow->setAmountIncVat( $priceInclVat );
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
 			return $wpForm;
373 373
 		}
374 374
 
375
-		public function process_paymentstatus() {
376
-			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
375
+		public function process_paymentstatus() {
376
+			if ( ! empty( $_GET['svea_order_id'] ) && intval( $_GET['svea_order_id'] ) != 0 && ! empty( $_GET['status'] ) ) {
377 377
 
378 378
 				$booking_id           = intval( $_GET['booking_id'] );
379 379
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 				exit( 0 );
384 384
 			}
385 385
 
386
-			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
386
+			if ( isset( $_REQUEST['edu-thankyou'] ) && isset( $_REQUEST['svea'] ) && ! empty( $_GET['status'] ) ) {
387 387
 				$booking_id           = intval( $_GET['booking_id'] );
388 388
 				$programme_booking_id = intval( $_GET['programme_booking_id'] );
389 389
 
@@ -391,13 +391,13 @@  discard block
 block discarded – undo
391 391
 
392 392
 				EDU()->session['svea-order-id'] = null;
393 393
 
394
-				if ( $deleted ) {
394
+				if ( $deleted ) {
395 395
 					$this->handle_cancelled_payment();
396 396
 				}
397 397
 			}
398 398
 		}
399 399
 
400
-		private function handle_cancelled_payment() {
400
+		private function handle_cancelled_payment() {
401 401
 			$url = EDU()->session['svea-cancel-url'];
402 402
 
403 403
 			EDU()->session['svea-cancel-url'] = null;
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
 		 * @return bool If the booking was deleted, due to cancellation
418 418
 		 * @throws \Svea\WebPay\BuildOrder\Validator\ValidationException
419 419
 		 */
420
-		private function update_booking( $order_id, $booking_id, $programme_booking_id ) {
421
-			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
420
+		private function update_booking( $order_id, $booking_id, $programme_booking_id ) {
421
+			if ( 'no' !== $this->get_option( 'testrun', 'no' ) ) {
422 422
 				$wpConfig = new EduSveaWebPayTestConfig( $this );
423
-			} else {
423
+			} else {
424 424
 				$wpConfig = new EduSveaWebPayProductionConfig( $this );
425 425
 			}
426 426
 
@@ -434,39 +434,39 @@  discard block
 block discarded – undo
434 434
 			$patch_booking                  = new stdClass();
435 435
 			$patch_booking->PaymentMethodId = 2;
436 436
 
437
-			if ( 'Cancelled' === $order['Status'] ) {
437
+			if ( 'Cancelled' === $order['Status'] ) {
438 438
 				$patch_booking->Paid = false;
439 439
 				$delete_booking      = true;
440
-			} else if ( 'Final' === $order['Status'] ) {
440
+			} else if ( 'Final' === $order['Status'] ) {
441 441
 				$patch_booking->Paid = true;
442
-			} else if ( 'Created' === $order['Status'] ) {
442
+			} else if ( 'Created' === $order['Status'] ) {
443 443
 				$patch_booking->Paid = false;
444 444
 			}
445 445
 
446
-			if ( isset( $_GET['status'] ) && 'cancel' === $_GET['status'] ) {
446
+			if ( isset( $_GET['status'] ) && 'cancel' === $_GET['status'] ) {
447 447
 				$patch_booking->Paid = false;
448 448
 				$delete_booking      = true;
449 449
 			}
450 450
 
451
-			if ( $booking_id > 0 ) {
451
+			if ( $booking_id > 0 ) {
452 452
 				EDUAPI()->REST->Booking->PatchBooking(
453 453
 					$booking_id,
454 454
 					$patch_booking
455 455
 				);
456 456
 
457
-				if ( $delete_booking ) {
457
+				if ( $delete_booking ) {
458 458
 					EDUAPI()->REST->Booking->DeleteBooking( $booking_id );
459 459
 				}
460 460
 			}
461 461
 
462
-			if ( $programme_booking_id > 0 ) {
462
+			if ( $programme_booking_id > 0 ) {
463 463
 
464 464
 				EDUAPI()->REST->ProgrammeBooking->PatchBooking(
465 465
 					$programme_booking_id,
466 466
 					$patch_booking
467 467
 				);
468 468
 
469
-				if ( $delete_booking ) {
469
+				if ( $delete_booking ) {
470 470
 					EDUAPI()->REST->ProgrammeBooking->DeleteBooking( $programme_booking_id );
471 471
 				}
472 472
 			}
Please login to merge, or discard this patch.