@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | defined( 'ABSPATH' ) || die( 'This plugin must be run within the scope of WordPress.' ); |
3 | 3 | |
4 | -if ( ! class_exists( 'EDU_KlarnaCheckout' ) ) { |
|
4 | +if ( !class_exists( 'EDU_KlarnaCheckout' ) ) { |
|
5 | 5 | class EDU_KlarnaCheckout extends EDU_Integration { |
6 | 6 | public function __construct() { |
7 | 7 | $this->id = 'eduadmin-klarnacheckout'; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | $ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact ); |
66 | 66 | |
67 | - if ( ! empty( EDU()->session['klarna-order-id'] ) && ! empty( $_GET['klarna_order_id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
67 | + if ( !empty( EDU()->session['klarna-order-id'] ) && !empty( $_GET['klarna_order_id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
68 | 68 | do_action( 'eduadmin-bookingcompleted', $ebi ); |
69 | 69 | } else { |
70 | 70 | do_action( 'eduadmin-processbooking', $ebi ); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | - if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) { |
|
82 | + if ( !empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) { |
|
83 | 83 | $ebi->NoRedirect = true; |
84 | 84 | } |
85 | 85 | } |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
107 | 107 | return; |
108 | 108 | } |
109 | - $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
109 | + $checkout_url = !checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
110 | 110 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
111 | 111 | |
112 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
112 | + if ( !empty( $_GET['klarna_order_id'] ) && !empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
113 | 113 | try { |
114 | 114 | $connector = Klarna_Checkout_Connector::create( |
115 | 115 | $shared_secret, |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function create_checkout( $ebi = null ) { |
177 | 177 | |
178 | - $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
178 | + $checkout_url = !checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
179 | 179 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
180 | 180 | |
181 | 181 | $create = array(); |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | |
198 | 198 | $_event = null; |
199 | 199 | |
200 | - if ( ! empty( $ebi->EventBooking['BookingId'] ) ) { |
|
200 | + if ( !empty( $ebi->EventBooking['BookingId'] ) ) { |
|
201 | 201 | $booking_id = intval( $ebi->EventBooking['BookingId'] ); |
202 | 202 | $reference_id = $booking_id; |
203 | 203 | |
204 | 204 | $_event = EDUAPI()->OData->Events->GetItem( $ebi->EventBooking['EventId'] ); |
205 | 205 | } |
206 | 206 | |
207 | - if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) { |
|
207 | + if ( !empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) { |
|
208 | 208 | $programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] ); |
209 | 209 | $reference_id = $programme_booking_id; |
210 | 210 | |
@@ -214,15 +214,15 @@ discard block |
||
214 | 214 | $rowExtraInfo = ""; |
215 | 215 | |
216 | 216 | if ( null != $_event ) { |
217 | - if ( ! empty( $_event['City'] ) ) { |
|
217 | + if ( !empty( $_event['City'] ) ) { |
|
218 | 218 | $rowExtraInfo .= ';' . $_event['City']; |
219 | 219 | } |
220 | 220 | |
221 | - if ( ! empty( $_event['StartDate'] ) ) { |
|
221 | + if ( !empty( $_event['StartDate'] ) ) { |
|
222 | 222 | $rowExtraInfo .= ';' . date( "Y-m-d", strtotime( $_event['StartDate'] ) ); |
223 | 223 | } |
224 | 224 | |
225 | - if ( ! empty( $_event['EndDate'] ) ) { |
|
225 | + if ( !empty( $_event['EndDate'] ) ) { |
|
226 | 226 | $rowExtraInfo .= ';' . date( "Y-m-d", strtotime( $_event['EndDate'] ) ); |
227 | 227 | } |
228 | 228 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $cart_item['name'] = $order_row['Description'] . $rowExtraInfo; |
269 | 269 | $cart_item['quantity'] = intval( $order_row['Quantity'] ); |
270 | 270 | |
271 | - if ( ! $order_row['PriceIncVat'] ) { |
|
271 | + if ( !$order_row['PriceIncVat'] ) { |
|
272 | 272 | $price_per_unit = $order_row['PricePerUnit'] * ( 1 + ( $order_row['VatPercent'] / 100 ) ) * 100; |
273 | 273 | } else { |
274 | 274 | $price_per_unit = $order_row['PricePerUnit'] * 100; |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | public function process_paymentstatus() { |
308 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( $_GET['status'] ) ) { |
|
309 | - $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
308 | + if ( !empty( $_GET['klarna_order_id'] ) && !empty( $_GET['status'] ) ) { |
|
309 | + $checkout_url = !checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
310 | 310 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
311 | 311 | |
312 | 312 | try { |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | defined( 'ABSPATH' ) || die( 'This plugin must be run within the scope of WordPress.' ); |
3 | 3 | |
4 | -if ( ! class_exists( 'EDU_KlarnaCheckout' ) ) { |
|
5 | - class EDU_KlarnaCheckout extends EDU_Integration { |
|
6 | - public function __construct() { |
|
4 | +if ( ! class_exists( 'EDU_KlarnaCheckout' ) ) { |
|
5 | + class EDU_KlarnaCheckout extends EDU_Integration { |
|
6 | + public function __construct() { |
|
7 | 7 | $this->id = 'eduadmin-klarnacheckout'; |
8 | 8 | $this->displayName = __( 'Klarna Checkout', 'eduadmin-wp-klarna-checkout' ); |
9 | 9 | $this->description = ''; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param $attributes |
24 | 24 | */ |
25 | - public function test_page( $attributes ) { |
|
25 | + public function test_page( $attributes ) { |
|
26 | 26 | $attributes = shortcode_atts( |
27 | 27 | array( |
28 | 28 | 'bookingid' => 0, |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | 'test_page' |
33 | 33 | ); |
34 | 34 | |
35 | - if ( $attributes['bookingid'] > 0 ) { |
|
35 | + if ( $attributes['bookingid'] > 0 ) { |
|
36 | 36 | $event_booking = EDUAPI()->OData->Bookings->GetItem( |
37 | 37 | $attributes['bookingid'], |
38 | 38 | null, |
39 | 39 | 'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows', |
40 | 40 | false |
41 | 41 | ); |
42 | - } elseif ( $attributes['programmebookingid'] > 0 ) { |
|
42 | + } elseif ( $attributes['programmebookingid'] > 0 ) { |
|
43 | 43 | $event_booking = EDUAPI()->OData->ProgrammeBookings->GetItem( |
44 | 44 | $attributes['programmebookingid'], |
45 | 45 | null, |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | |
65 | 65 | $ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact ); |
66 | 66 | |
67 | - if ( ! empty( EDU()->session['klarna-order-id'] ) && ! empty( $_GET['klarna_order_id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
67 | + if ( ! empty( EDU()->session['klarna-order-id'] ) && ! empty( $_GET['klarna_order_id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
68 | 68 | do_action( 'eduadmin-bookingcompleted', $ebi ); |
69 | - } else { |
|
69 | + } else { |
|
70 | 70 | do_action( 'eduadmin-processbooking', $ebi ); |
71 | 71 | } |
72 | 72 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * @param EduAdmin_BookingInfo|null $ebi |
76 | 76 | */ |
77 | - public function intercept_booking( $ebi = null ) { |
|
78 | - if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
77 | + public function intercept_booking( $ebi = null ) { |
|
78 | + if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | - if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) { |
|
82 | + if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) { |
|
83 | 83 | $ebi->NoRedirect = true; |
84 | 84 | } |
85 | 85 | } |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * @param EduAdmin_BookingInfo|null $ebi |
89 | 89 | */ |
90 | - public function process_booking( $ebi = null ) { |
|
91 | - if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
90 | + public function process_booking( $ebi = null ) { |
|
91 | + if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
92 | 92 | return; |
93 | 93 | } |
94 | 94 | |
95 | 95 | $ebi->NoRedirect = true; |
96 | 96 | |
97 | - if ( empty( $_GET['klarna_order_id'] ) || empty( EDU()->session['klarna-order-id'] ) ) { |
|
97 | + if ( empty( $_GET['klarna_order_id'] ) || empty( EDU()->session['klarna-order-id'] ) ) { |
|
98 | 98 | $checkout = $this->create_checkout( $ebi ); |
99 | 99 | |
100 | 100 | $snippet = $checkout['gui']['snippet']; |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | - public function process_klarnaresponse() { |
|
106 | - if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
105 | + public function process_klarnaresponse() { |
|
106 | + if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
110 | 110 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
111 | 111 | |
112 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
113 | - try { |
|
112 | + if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
113 | + try { |
|
114 | 114 | $connector = Klarna_Checkout_Connector::create( |
115 | 115 | $shared_secret, |
116 | 116 | $checkout_url |
@@ -126,14 +126,15 @@ discard block |
||
126 | 126 | echo "<div>{$snippet}</div>"; |
127 | 127 | EDU()->session['klarna-order-id'] = null; |
128 | 128 | |
129 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
129 | + } |
|
130 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
130 | 131 | EDU()->write_debug( $ex->getMessage() ); |
131 | 132 | EDU()->write_debug( $ex->getPayload() ); |
132 | 133 | } |
133 | 134 | } |
134 | 135 | } |
135 | 136 | |
136 | - public function init_form_fields() { |
|
137 | + public function init_form_fields() { |
|
137 | 138 | $this->setting_fields = array( |
138 | 139 | 'enabled' => array( |
139 | 140 | 'title' => __( 'Enabled', 'edauadmin-wp-klarna-checkout' ), |
@@ -173,7 +174,7 @@ discard block |
||
173 | 174 | * |
174 | 175 | * @return Klarna_Checkout_Order|null |
175 | 176 | */ |
176 | - public function create_checkout( $ebi = null ) { |
|
177 | + public function create_checkout( $ebi = null ) { |
|
177 | 178 | |
178 | 179 | $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
179 | 180 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
@@ -197,14 +198,14 @@ discard block |
||
197 | 198 | |
198 | 199 | $_event = null; |
199 | 200 | |
200 | - if ( ! empty( $ebi->EventBooking['BookingId'] ) ) { |
|
201 | + if ( ! empty( $ebi->EventBooking['BookingId'] ) ) { |
|
201 | 202 | $booking_id = intval( $ebi->EventBooking['BookingId'] ); |
202 | 203 | $reference_id = $booking_id; |
203 | 204 | |
204 | 205 | $_event = EDUAPI()->OData->Events->GetItem( $ebi->EventBooking['EventId'] ); |
205 | 206 | } |
206 | 207 | |
207 | - if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) { |
|
208 | + if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) { |
|
208 | 209 | $programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] ); |
209 | 210 | $reference_id = $programme_booking_id; |
210 | 211 | |
@@ -213,16 +214,16 @@ discard block |
||
213 | 214 | |
214 | 215 | $rowExtraInfo = ""; |
215 | 216 | |
216 | - if ( null != $_event ) { |
|
217 | - if ( ! empty( $_event['City'] ) ) { |
|
217 | + if ( null != $_event ) { |
|
218 | + if ( ! empty( $_event['City'] ) ) { |
|
218 | 219 | $rowExtraInfo .= ';' . $_event['City']; |
219 | 220 | } |
220 | 221 | |
221 | - if ( ! empty( $_event['StartDate'] ) ) { |
|
222 | + if ( ! empty( $_event['StartDate'] ) ) { |
|
222 | 223 | $rowExtraInfo .= ';' . date( "Y-m-d", strtotime( $_event['StartDate'] ) ); |
223 | 224 | } |
224 | 225 | |
225 | - if ( ! empty( $_event['EndDate'] ) ) { |
|
226 | + if ( ! empty( $_event['EndDate'] ) ) { |
|
226 | 227 | $rowExtraInfo .= ';' . date( "Y-m-d", strtotime( $_event['EndDate'] ) ); |
227 | 228 | } |
228 | 229 | } |
@@ -261,16 +262,16 @@ discard block |
||
261 | 262 | $create['cart'] = array(); |
262 | 263 | $create['cart']['items'] = array(); |
263 | 264 | |
264 | - foreach ( $ebi->EventBooking['OrderRows'] as $order_row ) { |
|
265 | + foreach ( $ebi->EventBooking['OrderRows'] as $order_row ) { |
|
265 | 266 | $cart_item = array(); |
266 | 267 | |
267 | 268 | $cart_item['reference'] = $order_row['ItemNumber']; |
268 | 269 | $cart_item['name'] = $order_row['Description'] . $rowExtraInfo; |
269 | 270 | $cart_item['quantity'] = intval( $order_row['Quantity'] ); |
270 | 271 | |
271 | - if ( ! $order_row['PriceIncVat'] ) { |
|
272 | + if ( ! $order_row['PriceIncVat'] ) { |
|
272 | 273 | $price_per_unit = $order_row['PricePerUnit'] * ( 1 + ( $order_row['VatPercent'] / 100 ) ) * 100; |
273 | - } else { |
|
274 | + } else { |
|
274 | 275 | $price_per_unit = $order_row['PricePerUnit'] * 100; |
275 | 276 | } |
276 | 277 | |
@@ -281,7 +282,7 @@ discard block |
||
281 | 282 | $create['cart']['items'][] = $cart_item; |
282 | 283 | } |
283 | 284 | |
284 | - try { |
|
285 | + try { |
|
285 | 286 | $connector = Klarna_Checkout_Connector::create( |
286 | 287 | $shared_secret, |
287 | 288 | $checkout_url |
@@ -296,7 +297,8 @@ discard block |
||
296 | 297 | EDU()->session['klarna-order-id'] = $order_id; |
297 | 298 | |
298 | 299 | return $order; |
299 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
300 | + } |
|
301 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
300 | 302 | EDU()->write_debug( $ex->getMessage() ); |
301 | 303 | EDU()->write_debug( $ex->getPayload() ); |
302 | 304 | |
@@ -304,12 +306,12 @@ discard block |
||
304 | 306 | } |
305 | 307 | } |
306 | 308 | |
307 | - public function process_paymentstatus() { |
|
308 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( $_GET['status'] ) ) { |
|
309 | + public function process_paymentstatus() { |
|
310 | + if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( $_GET['status'] ) ) { |
|
309 | 311 | $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
310 | 312 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
311 | 313 | |
312 | - try { |
|
314 | + try { |
|
313 | 315 | $connector = Klarna_Checkout_Connector::create( |
314 | 316 | $shared_secret, |
315 | 317 | $checkout_url |
@@ -325,7 +327,7 @@ discard block |
||
325 | 327 | $programme_booking_id = intval( $_GET['programme_booking_id'] ); |
326 | 328 | |
327 | 329 | |
328 | - if ( 'checkout_complete' === $order['status'] ) { |
|
330 | + if ( 'checkout_complete' === $order['status'] ) { |
|
329 | 331 | |
330 | 332 | $patch_booking = new stdClass(); |
331 | 333 | $patch_booking->Paid = true; |
@@ -333,14 +335,14 @@ discard block |
||
333 | 335 | // We're setting this as a Card Payment, so that our service in the background will remove it if it doesn't get paid in time (15 minute slot) |
334 | 336 | $patch_booking->PaymentMethodId = 2; |
335 | 337 | |
336 | - if ( $booking_id > 0 ) { |
|
338 | + if ( $booking_id > 0 ) { |
|
337 | 339 | EDUAPI()->REST->Booking->PatchBooking( |
338 | 340 | $booking_id, |
339 | 341 | $patch_booking |
340 | 342 | ); |
341 | 343 | } |
342 | 344 | |
343 | - if ( $programme_booking_id > 0 ) { |
|
345 | + if ( $programme_booking_id > 0 ) { |
|
344 | 346 | EDUAPI()->REST->ProgrammeBooking->PatchBooking( |
345 | 347 | $programme_booking_id, |
346 | 348 | $patch_booking |
@@ -352,7 +354,8 @@ discard block |
||
352 | 354 | $order->update( $update ); |
353 | 355 | } |
354 | 356 | exit( 0 ); |
355 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
357 | + } |
|
358 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
356 | 359 | EDU()->write_debug( $ex->getMessage() ); |
357 | 360 | EDU()->write_debug( $ex->getPayload() ); |
358 | 361 | exit( 1 ); |