@@ -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, |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | |
53 | 53 | $ebi = new EduAdmin_BookingInfo( $event_booking, $_customer, $_contact ); |
54 | 54 | |
55 | - if ( ! empty( EDU()->session['klarna-order-id'] ) && ! empty( $_GET['klarna_order_id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
55 | + if ( ! empty( EDU()->session['klarna-order-id'] ) && ! empty( $_GET['klarna_order_id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
56 | 56 | do_action( 'eduadmin-bookingcompleted', $ebi ); |
57 | - } else { |
|
57 | + } else { |
|
58 | 58 | do_action( 'eduadmin-processbooking', $ebi ); |
59 | 59 | } |
60 | 60 | } |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @param EduAdmin_BookingInfo|null $ebi |
64 | 64 | */ |
65 | - public function intercept_booking( $ebi = null ) { |
|
66 | - if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
65 | + public function intercept_booking( $ebi = null ) { |
|
66 | + if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - if ( ! empty( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) { |
|
70 | + if ( ! empty( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) { |
|
71 | 71 | $ebi->NoRedirect = true; |
72 | 72 | } |
73 | 73 | } |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | /** |
76 | 76 | * @param EduAdmin_BookingInfo|null $ebi |
77 | 77 | */ |
78 | - public function process_booking( $ebi = null ) { |
|
79 | - if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
78 | + public function process_booking( $ebi = null ) { |
|
79 | + if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | 83 | $ebi->NoRedirect = true; |
84 | 84 | |
85 | - if ( empty( EDU()->session['klarna-order-id'] ) && empty( $_GET['klarna_order_id'] ) ) { |
|
85 | + if ( empty( EDU()->session['klarna-order-id'] ) && empty( $_GET['klarna_order_id'] ) ) { |
|
86 | 86 | $checkout = $this->create_checkout( $ebi ); |
87 | 87 | |
88 | 88 | $snippet = $checkout['gui']['snippet']; |
@@ -90,15 +90,15 @@ discard block |
||
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - public function process_klarnaresponse() { |
|
94 | - if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
93 | + public function process_klarnaresponse() { |
|
94 | + if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
98 | 98 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
99 | 99 | |
100 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
101 | - try { |
|
100 | + if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
101 | + try { |
|
102 | 102 | $connector = Klarna_Checkout_Connector::create( |
103 | 103 | $shared_secret, |
104 | 104 | $checkout_url |
@@ -114,14 +114,15 @@ discard block |
||
114 | 114 | echo "<div>{$snippet}</div>"; |
115 | 115 | EDU()->session['klarna-order-id'] = null; |
116 | 116 | |
117 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
117 | + } |
|
118 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
118 | 119 | EDU()->write_debug( $ex->getMessage() ); |
119 | 120 | EDU()->write_debug( $ex->getPayload() ); |
120 | 121 | } |
121 | 122 | } |
122 | 123 | } |
123 | 124 | |
124 | - public function init_form_fields() { |
|
125 | + public function init_form_fields() { |
|
125 | 126 | $this->setting_fields = array( |
126 | 127 | 'enabled' => array( |
127 | 128 | 'title' => __( 'Enabled', 'edauadmin-wp-klarna-checkout' ), |
@@ -161,7 +162,7 @@ discard block |
||
161 | 162 | * |
162 | 163 | * @return Klarna_Checkout_Order|null |
163 | 164 | */ |
164 | - public function create_checkout( $ebi = null ) { |
|
165 | + public function create_checkout( $ebi = null ) { |
|
165 | 166 | |
166 | 167 | $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
167 | 168 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
@@ -207,16 +208,16 @@ discard block |
||
207 | 208 | $create['cart'] = array(); |
208 | 209 | $create['cart']['items'] = array(); |
209 | 210 | |
210 | - foreach ( $ebi->EventBooking['OrderRows'] as $order_row ) { |
|
211 | + foreach ( $ebi->EventBooking['OrderRows'] as $order_row ) { |
|
211 | 212 | $cart_item = array(); |
212 | 213 | |
213 | 214 | $cart_item['reference'] = $order_row['ItemNumber']; |
214 | 215 | $cart_item['name'] = $order_row['Description']; |
215 | 216 | $cart_item['quantity'] = intval( $order_row['Quantity'] ); |
216 | 217 | |
217 | - if ( ! $order_row['PriceIncVat'] ) { |
|
218 | + if ( ! $order_row['PriceIncVat'] ) { |
|
218 | 219 | $price_per_unit = $order_row['PricePerUnit'] * ( 1 + ( $order_row['VatPercent'] / 100 ) ) * 100; |
219 | - } else { |
|
220 | + } else { |
|
220 | 221 | $price_per_unit = $order_row['PricePerUnit'] * 100; |
221 | 222 | } |
222 | 223 | |
@@ -227,7 +228,7 @@ discard block |
||
227 | 228 | $create['cart']['items'][] = $cart_item; |
228 | 229 | } |
229 | 230 | |
230 | - try { |
|
231 | + try { |
|
231 | 232 | $connector = Klarna_Checkout_Connector::create( |
232 | 233 | $shared_secret, |
233 | 234 | $checkout_url |
@@ -242,7 +243,8 @@ discard block |
||
242 | 243 | EDU()->session['klarna-order-id'] = $order_id; |
243 | 244 | |
244 | 245 | return $order; |
245 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
246 | + } |
|
247 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
246 | 248 | EDU()->write_debug( $ex->getMessage() ); |
247 | 249 | EDU()->write_debug( $ex->getPayload() ); |
248 | 250 | |
@@ -250,12 +252,12 @@ discard block |
||
250 | 252 | } |
251 | 253 | } |
252 | 254 | |
253 | - public function process_paymentstatus() { |
|
254 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( $_GET['status'] ) ) { |
|
255 | + public function process_paymentstatus() { |
|
256 | + if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( $_GET['status'] ) ) { |
|
255 | 257 | $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
256 | 258 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
257 | 259 | |
258 | - try { |
|
260 | + try { |
|
259 | 261 | $connector = Klarna_Checkout_Connector::create( |
260 | 262 | $shared_secret, |
261 | 263 | $checkout_url |
@@ -267,7 +269,7 @@ discard block |
||
267 | 269 | |
268 | 270 | $order->fetch(); |
269 | 271 | |
270 | - if ( 'checkout_complete' === $order['status'] ) { |
|
272 | + if ( 'checkout_complete' === $order['status'] ) { |
|
271 | 273 | |
272 | 274 | $patch_booking = new stdClass(); |
273 | 275 | $patch_booking->Paid = true; |
@@ -282,7 +284,8 @@ discard block |
||
282 | 284 | $order->update( $update ); |
283 | 285 | } |
284 | 286 | exit( 0 ); |
285 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
287 | + } |
|
288 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
286 | 289 | EDU()->write_debug( $ex->getMessage() ); |
287 | 290 | EDU()->write_debug( $ex->getPayload() ); |
288 | 291 | exit( 1 ); |