@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 | 30 | */ |
31 | 31 | |
32 | -add_action( 'admin_init', function () { |
|
33 | - if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) { |
|
34 | - add_action( 'admin_notices', function () { |
|
32 | +add_action( 'admin_init', function() { |
|
33 | + if ( is_admin() && current_user_can( 'activate_plugins' ) && ( !is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && !is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) { |
|
34 | + add_action( 'admin_notices', function() { |
|
35 | 35 | ?> |
36 | 36 | <div class="error"> |
37 | 37 | <p><?php esc_html_e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-wp-klarna-checkout' ); ?></p> |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | } |
46 | 46 | } ); |
47 | 47 | |
48 | -if ( ! class_exists( 'EDU_KlarnaCheckout_Loader' ) ) { |
|
48 | +if ( !class_exists( 'EDU_KlarnaCheckout_Loader' ) ) { |
|
49 | 49 | final class EDU_KlarnaCheckout_Loader { |
50 | 50 | public function __construct() { |
51 | 51 | add_action( 'plugins_loaded', array( $this, 'init' ) ); |
52 | 52 | } |
53 | 53 | |
54 | 54 | public function init() { |
55 | - if ( ! class_exists( 'Klarna_Checkout_Connector' ) ) { |
|
55 | + if ( !class_exists( 'Klarna_Checkout_Connector' ) ) { |
|
56 | 56 | require_once __DIR__ . '/klarna_kco_php_4.0.0/src/Klarna/Checkout.php'; |
57 | 57 | } |
58 | 58 |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 | 30 | */ |
31 | 31 | |
32 | -add_action( 'admin_init', function () { |
|
33 | - if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) { |
|
34 | - add_action( 'admin_notices', function () { |
|
32 | +add_action( 'admin_init', function () { |
|
33 | + if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) { |
|
34 | + add_action( 'admin_notices', function () { |
|
35 | 35 | ?> |
36 | 36 | <div class="error"> |
37 | 37 | <p><?php esc_html_e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-wp-klarna-checkout' ); ?></p> |
@@ -39,24 +39,24 @@ discard block |
||
39 | 39 | <?php |
40 | 40 | } ); |
41 | 41 | deactivate_plugins( plugin_basename( __FILE__ ) ); |
42 | - if ( isset( $_GET['activate'] ) ) { |
|
42 | + if ( isset( $_GET['activate'] ) ) { |
|
43 | 43 | unset( $_GET['activate'] ); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | } ); |
47 | 47 | |
48 | -if ( ! class_exists( 'EDU_KlarnaCheckout_Loader' ) ) { |
|
49 | - final class EDU_KlarnaCheckout_Loader { |
|
50 | - public function __construct() { |
|
48 | +if ( ! class_exists( 'EDU_KlarnaCheckout_Loader' ) ) { |
|
49 | + final class EDU_KlarnaCheckout_Loader { |
|
50 | + public function __construct() { |
|
51 | 51 | add_action( 'plugins_loaded', array( $this, 'init' ) ); |
52 | 52 | } |
53 | 53 | |
54 | - public function init() { |
|
55 | - if ( ! class_exists( 'Klarna_Checkout_Connector' ) ) { |
|
54 | + public function init() { |
|
55 | + if ( ! class_exists( 'Klarna_Checkout_Connector' ) ) { |
|
56 | 56 | require_once __DIR__ . '/klarna_kco_php_4.0.0/src/Klarna/Checkout.php'; |
57 | 57 | } |
58 | 58 | |
59 | - if ( class_exists( 'EDU_Integration' ) ) { |
|
59 | + if ( class_exists( 'EDU_Integration' ) ) { |
|
60 | 60 | |
61 | 61 | require_once __DIR__ . '/class-edu-klarnacheckout.php'; |
62 | 62 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | - public function add_integration( $integrations ) { |
|
67 | + public function add_integration( $integrations ) { |
|
68 | 68 | $integrations[] = 'EDU_KlarnaCheckout'; |
69 | 69 | |
70 | 70 | return $integrations; |
@@ -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'; |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | 'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows', |
38 | 38 | false |
39 | 39 | ); |
40 | - $_customer = EDUAPI()->OData->Customers->GetItem( |
|
40 | + $_customer = EDUAPI()->OData->Customers->GetItem( |
|
41 | 41 | $event_booking['Customer']['CustomerId'], |
42 | 42 | null, |
43 | 43 | null, |
44 | 44 | false |
45 | 45 | ); |
46 | - $_contact = EDUAPI()->OData->Persons->GetItem( |
|
46 | + $_contact = EDUAPI()->OData->Persons->GetItem( |
|
47 | 47 | $event_booking['ContactPerson']['PersonId'], |
48 | 48 | null, |
49 | 49 | null, |
@@ -52,7 +52,7 @@ 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 | 57 | } else { |
58 | 58 | do_action( 'eduadmin-processbooking', $ebi ); |
@@ -67,7 +67,7 @@ discard block |
||
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 | } |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | if ( 'no' === $this->get_option( 'enabled', 'no' ) ) { |
95 | 95 | return; |
96 | 96 | } |
97 | - $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
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'] ) { |
|
100 | + if ( !empty( $_GET['klarna_order_id'] ) && !empty( EDU()->session['klarna-order-id'] ) && EDU()->session['klarna-order-id'] === $_GET['klarna_order_id'] ) { |
|
101 | 101 | try { |
102 | 102 | $connector = Klarna_Checkout_Connector::create( |
103 | 103 | $shared_secret, |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function create_checkout( $ebi = null ) { |
165 | 165 | |
166 | - $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
166 | + $checkout_url = !checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
167 | 167 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
168 | 168 | |
169 | 169 | $create = array(); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $cart_item['name'] = $order_row['Description']; |
215 | 215 | $cart_item['quantity'] = intval( $order_row['Quantity'] ); |
216 | 216 | |
217 | - if ( ! $order_row['PriceIncVat'] ) { |
|
217 | + if ( !$order_row['PriceIncVat'] ) { |
|
218 | 218 | $price_per_unit = $order_row['PricePerUnit'] * ( 1 + ( $order_row['VatPercent'] / 100 ) ) * 100; |
219 | 219 | } else { |
220 | 220 | $price_per_unit = $order_row['PricePerUnit'] * 100; |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | } |
252 | 252 | |
253 | 253 | public function process_paymentstatus() { |
254 | - if ( ! empty( $_GET['klarna_order_id'] ) && ! empty( $_GET['status'] ) ) { |
|
255 | - $checkout_url = ! checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
254 | + if ( !empty( $_GET['klarna_order_id'] ) && !empty( $_GET['status'] ) ) { |
|
255 | + $checkout_url = !checked( $this->get_option( 'test_mode', 'no' ), '1', false ) ? Klarna_Checkout_Connector::BASE_URL : Klarna_Checkout_Connector::BASE_TEST_URL; |
|
256 | 256 | $shared_secret = $this->get_option( 'shared_secret', '' ); |
257 | 257 | |
258 | 258 | 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, |
@@ -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,13 +269,14 @@ discard block |
||
267 | 269 | |
268 | 270 | $order->fetch(); |
269 | 271 | |
270 | - if ( 'checkout_complete' === $order['status'] ) { |
|
272 | + if ( 'checkout_complete' === $order['status'] ) { |
|
271 | 273 | $update = array(); |
272 | 274 | $update['status'] = 'created'; |
273 | 275 | $order->update( $update ); |
274 | 276 | } |
275 | 277 | exit( 0 ); |
276 | - } catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
278 | + } |
|
279 | + catch ( Klarna_Checkout_ApiErrorException $ex ) { |
|
277 | 280 | EDU()->write_debug( $ex->getMessage() ); |
278 | 281 | EDU()->write_debug( $ex->getPayload() ); |
279 | 282 | exit( 1 ); |