@@ -35,23 +35,23 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param Config $config Config. |
| 37 | 37 | */ |
| 38 | - public function __construct( Config $config ) { |
|
| 39 | - parent::__construct( $config ); |
|
| 38 | + public function __construct(Config $config) { |
|
| 39 | + parent::__construct($config); |
|
| 40 | 40 | |
| 41 | - $this->set_method( self::METHOD_HTTP_REDIRECT ); |
|
| 41 | + $this->set_method(self::METHOD_HTTP_REDIRECT); |
|
| 42 | 42 | |
| 43 | 43 | // Client. |
| 44 | 44 | $this->client = new Client(); |
| 45 | 45 | |
| 46 | 46 | $url = Client::URL_PRODUCTION; |
| 47 | 47 | |
| 48 | - if ( self::MODE_TEST === $config->mode ) { |
|
| 48 | + if (self::MODE_TEST === $config->mode) { |
|
| 49 | 49 | $url = Client::URL_SANDBOX; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - $this->client->set_url( $url ); |
|
| 53 | - $this->client->set_refresh_token( $config->refresh_token ); |
|
| 54 | - $this->client->set_signing_key( $config->signing_key ); |
|
| 52 | + $this->client->set_url($url); |
|
| 53 | + $this->client->set_refresh_token($config->refresh_token); |
|
| 54 | + $this->client->set_signing_key($config->signing_key); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -78,139 +78,139 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param Payment $payment Payment. |
| 80 | 80 | */ |
| 81 | - public function start( Payment $payment ) { |
|
| 81 | + public function start(Payment $payment) { |
|
| 82 | 82 | // Merchant order ID. |
| 83 | - $merchant_order_id = $payment->format_string( $this->config->order_id ); |
|
| 83 | + $merchant_order_id = $payment->format_string($this->config->order_id); |
|
| 84 | 84 | |
| 85 | - $payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id ); |
|
| 85 | + $payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id); |
|
| 86 | 86 | |
| 87 | 87 | // Shipping address. |
| 88 | 88 | $shipping_address = $payment->get_shipping_address(); |
| 89 | 89 | |
| 90 | - if ( null !== $shipping_address ) { |
|
| 90 | + if (null !== $shipping_address) { |
|
| 91 | 91 | $shipping_detail = new Address(); |
| 92 | 92 | |
| 93 | 93 | $name = $shipping_address->get_name(); |
| 94 | 94 | |
| 95 | - if ( null !== $name ) { |
|
| 96 | - $shipping_detail->set_first_name( $name->get_first_name() ); |
|
| 97 | - $shipping_detail->set_middle_name( $name->get_middle_name() ); |
|
| 98 | - $shipping_detail->set_last_name( $name->get_last_name() ); |
|
| 95 | + if (null !== $name) { |
|
| 96 | + $shipping_detail->set_first_name($name->get_first_name()); |
|
| 97 | + $shipping_detail->set_middle_name($name->get_middle_name()); |
|
| 98 | + $shipping_detail->set_last_name($name->get_last_name()); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $shipping_detail->set_street( $shipping_address->get_street_name() ); |
|
| 102 | - $shipping_detail->set_house_number( $shipping_address->get_house_number() ); |
|
| 103 | - $shipping_detail->set_house_number_addition( $shipping_address->get_house_number_addition() ); |
|
| 104 | - $shipping_detail->set_postal_code( $shipping_address->get_postal_code() ); |
|
| 105 | - $shipping_detail->set_city( $shipping_address->get_city() ); |
|
| 106 | - $shipping_detail->set_country_code( $shipping_address->get_country_code() ); |
|
| 101 | + $shipping_detail->set_street($shipping_address->get_street_name()); |
|
| 102 | + $shipping_detail->set_house_number($shipping_address->get_house_number()); |
|
| 103 | + $shipping_detail->set_house_number_addition($shipping_address->get_house_number_addition()); |
|
| 104 | + $shipping_detail->set_postal_code($shipping_address->get_postal_code()); |
|
| 105 | + $shipping_detail->set_city($shipping_address->get_city()); |
|
| 106 | + $shipping_detail->set_country_code($shipping_address->get_country_code()); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Billing address. |
| 110 | 110 | $billing_address = $payment->get_billing_address(); |
| 111 | 111 | |
| 112 | - if ( null !== $billing_address ) { |
|
| 112 | + if (null !== $billing_address) { |
|
| 113 | 113 | $billing_detail = new Address(); |
| 114 | 114 | |
| 115 | 115 | $name = $billing_address->get_name(); |
| 116 | 116 | |
| 117 | - if ( null !== $name ) { |
|
| 118 | - $billing_detail->set_first_name( $name->get_first_name() ); |
|
| 119 | - $billing_detail->set_middle_name( $name->get_middle_name() ); |
|
| 120 | - $billing_detail->set_last_name( $name->get_last_name() ); |
|
| 117 | + if (null !== $name) { |
|
| 118 | + $billing_detail->set_first_name($name->get_first_name()); |
|
| 119 | + $billing_detail->set_middle_name($name->get_middle_name()); |
|
| 120 | + $billing_detail->set_last_name($name->get_last_name()); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $billing_detail->set_street( $billing_address->get_street_name() ); |
|
| 124 | - $billing_detail->set_house_number( $billing_address->get_house_number() ); |
|
| 125 | - $billing_detail->set_house_number_addition( $billing_address->get_house_number_addition() ); |
|
| 126 | - $billing_detail->set_postal_code( $billing_address->get_postal_code() ); |
|
| 127 | - $billing_detail->set_city( $billing_address->get_city() ); |
|
| 128 | - $billing_detail->set_country_code( $billing_address->get_country_code() ); |
|
| 123 | + $billing_detail->set_street($billing_address->get_street_name()); |
|
| 124 | + $billing_detail->set_house_number($billing_address->get_house_number()); |
|
| 125 | + $billing_detail->set_house_number_addition($billing_address->get_house_number_addition()); |
|
| 126 | + $billing_detail->set_postal_code($billing_address->get_postal_code()); |
|
| 127 | + $billing_detail->set_city($billing_address->get_city()); |
|
| 128 | + $billing_detail->set_country_code($billing_address->get_country_code()); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Customer information. |
| 132 | 132 | $customer = $payment->get_customer(); |
| 133 | 133 | |
| 134 | - if ( null !== $customer ) { |
|
| 134 | + if (null !== $customer) { |
|
| 135 | 135 | $customer_information = new CustomerInformation(); |
| 136 | 136 | |
| 137 | - $customer_information->set_email_address( $customer->get_email() ); |
|
| 138 | - $customer_information->set_telephone_number( $customer->get_phone() ); |
|
| 137 | + $customer_information->set_email_address($customer->get_email()); |
|
| 138 | + $customer_information->set_telephone_number($customer->get_phone()); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Payment brand. |
| 142 | - $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
|
| 142 | + $payment_brand = PaymentBrands::transform($payment->get_method()); |
|
| 143 | 143 | |
| 144 | 144 | // New order. |
| 145 | 145 | $order = new Order( |
| 146 | 146 | $merchant_order_id, |
| 147 | 147 | new Money( |
| 148 | 148 | $payment->get_currency(), |
| 149 | - intval( $payment->get_amount()->get_cents() ) |
|
| 149 | + intval($payment->get_amount()->get_cents()) |
|
| 150 | 150 | ), |
| 151 | 151 | $payment->get_return_url() |
| 152 | 152 | ); |
| 153 | 153 | |
| 154 | - $order->set_description( $payment->get_description() ); |
|
| 155 | - $order->set_language( $payment->get_customer()->get_language() ); |
|
| 154 | + $order->set_description($payment->get_description()); |
|
| 155 | + $order->set_language($payment->get_customer()->get_language()); |
|
| 156 | 156 | |
| 157 | - if ( null !== $payment->get_lines() ) { |
|
| 157 | + if (null !== $payment->get_lines()) { |
|
| 158 | 158 | $order_items = new OrderItems(); |
| 159 | 159 | |
| 160 | - foreach ( $payment->get_lines() as $line ) { |
|
| 160 | + foreach ($payment->get_lines() as $line) { |
|
| 161 | 161 | $item = new OrderItem( |
| 162 | 162 | $line->get_name(), |
| 163 | 163 | $line->get_quantity(), |
| 164 | 164 | new Money( |
| 165 | 165 | $line->get_total_amount()->get_currency()->get_alphabetic_code(), |
| 166 | - intval( $line->get_total_amount()->get_cents() ) |
|
| 166 | + intval($line->get_total_amount()->get_cents()) |
|
| 167 | 167 | ), |
| 168 | - Category::transform( $line->get_type() ) |
|
| 168 | + Category::transform($line->get_type()) |
|
| 169 | 169 | ); |
| 170 | 170 | |
| 171 | - $order_items->add_item( $item ); |
|
| 171 | + $order_items->add_item($item); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | //$order->set_order_items( $order_items ); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if ( isset( $shipping_detail ) ) { |
|
| 178 | - $order->set_shipping_detail( $shipping_detail ); |
|
| 177 | + if (isset($shipping_detail)) { |
|
| 178 | + $order->set_shipping_detail($shipping_detail); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if ( isset( $billing_detail ) ) { |
|
| 182 | - $order->set_billing_detail( $billing_detail ); |
|
| 181 | + if (isset($billing_detail)) { |
|
| 182 | + $order->set_billing_detail($billing_detail); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if ( isset( $customer_information ) ) { |
|
| 186 | - $order->set_customer_information( $customer_information ); |
|
| 185 | + if (isset($customer_information)) { |
|
| 186 | + $order->set_customer_information($customer_information); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - $order->set_payment_brand( $payment_brand ); |
|
| 189 | + $order->set_payment_brand($payment_brand); |
|
| 190 | 190 | |
| 191 | - if ( null !== $payment_brand ) { |
|
| 191 | + if (null !== $payment_brand) { |
|
| 192 | 192 | // Payment brand force should only be set if payment brand is not empty. |
| 193 | - $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
|
| 193 | + $order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // Maybe update access token. |
| 197 | 197 | $this->maybe_update_access_token(); |
| 198 | 198 | |
| 199 | 199 | // Handle errors. |
| 200 | - if ( $this->get_client_error() ) { |
|
| 200 | + if ($this->get_client_error()) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Announce order. |
| 205 | - $result = $this->client->order_announce( $this->config, $order ); |
|
| 205 | + $result = $this->client->order_announce($this->config, $order); |
|
| 206 | 206 | |
| 207 | 207 | // Handle errors. |
| 208 | - if ( $this->get_client_error() ) { |
|
| 208 | + if ($this->get_client_error()) { |
|
| 209 | 209 | return; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if ( $result ) { |
|
| 213 | - $payment->set_action_url( $result->redirectUrl ); |
|
| 212 | + if ($result) { |
|
| 213 | + $payment->set_action_url($result->redirectUrl); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -219,45 +219,45 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @param Payment $payment Payment. |
| 221 | 221 | */ |
| 222 | - public function update_status( Payment $payment ) { |
|
| 223 | - if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok. |
|
| 222 | + public function update_status(Payment $payment) { |
|
| 223 | + if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok. |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - $parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok. |
|
| 227 | + $parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok. |
|
| 228 | 228 | |
| 229 | 229 | // Note. |
| 230 | 230 | $note_values = array( |
| 231 | 231 | 'order_id' => $parameters->get_order_id(), |
| 232 | 232 | 'status' => $parameters->get_status(), |
| 233 | 233 | 'signature' => $parameters->get_signature(), |
| 234 | - 'valid' => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false', |
|
| 234 | + 'valid' => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false', |
|
| 235 | 235 | ); |
| 236 | 236 | |
| 237 | 237 | $note = ''; |
| 238 | 238 | |
| 239 | 239 | $note .= '<p>'; |
| 240 | - $note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' ); |
|
| 240 | + $note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal'); |
|
| 241 | 241 | $note .= '</p>'; |
| 242 | 242 | |
| 243 | 243 | $note .= '<dl>'; |
| 244 | 244 | |
| 245 | - foreach ( $note_values as $key => $value ) { |
|
| 246 | - $note .= sprintf( '<dt>%s</dt>', esc_html( $key ) ); |
|
| 247 | - $note .= sprintf( '<dd>%s</dd>', esc_html( $value ) ); |
|
| 245 | + foreach ($note_values as $key => $value) { |
|
| 246 | + $note .= sprintf('<dt>%s</dt>', esc_html($key)); |
|
| 247 | + $note .= sprintf('<dd>%s</dd>', esc_html($value)); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $note .= '</dl>'; |
| 251 | 251 | |
| 252 | - $payment->add_note( $note ); |
|
| 252 | + $payment->add_note($note); |
|
| 253 | 253 | |
| 254 | 254 | // Validate. |
| 255 | - if ( ! $parameters->is_valid( $this->config->signing_key ) ) { |
|
| 255 | + if ( ! $parameters->is_valid($this->config->signing_key)) { |
|
| 256 | 256 | return; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Status. |
| 260 | - $payment->set_status( Statuses::transform( $parameters->get_status() ) ); |
|
| 260 | + $payment->set_status(Statuses::transform($parameters->get_status())); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -267,14 +267,14 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - public function handle_notification( Notification $notification ) { |
|
| 271 | - if ( ! $notification->is_valid( $this->config->signing_key ) ) { |
|
| 270 | + public function handle_notification(Notification $notification) { |
|
| 271 | + if ( ! $notification->is_valid($this->config->signing_key)) { |
|
| 272 | 272 | return; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - switch ( $notification->get_event_name() ) { |
|
| 275 | + switch ($notification->get_event_name()) { |
|
| 276 | 276 | case 'merchant.order.status.changed': |
| 277 | - $this->handle_merchant_order_status_changed( $notification ); |
|
| 277 | + $this->handle_merchant_order_status_changed($notification); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -285,39 +285,39 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return void |
| 287 | 287 | */ |
| 288 | - private function handle_merchant_order_status_changed( Notification $notification ) { |
|
| 288 | + private function handle_merchant_order_status_changed(Notification $notification) { |
|
| 289 | 289 | do { |
| 290 | - $order_results = $this->client->get_order_results( $notification->get_authentication() ); |
|
| 290 | + $order_results = $this->client->get_order_results($notification->get_authentication()); |
|
| 291 | 291 | |
| 292 | - if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) { |
|
| 292 | + if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) { |
|
| 293 | 293 | return; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - foreach ( $order_results as $order_result ) { |
|
| 297 | - $payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() ); |
|
| 296 | + foreach ($order_results as $order_result) { |
|
| 297 | + $payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id()); |
|
| 298 | 298 | |
| 299 | - if ( empty( $payment ) ) { |
|
| 299 | + if (empty($payment)) { |
|
| 300 | 300 | continue; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $payment->set_transaction_id( $order_result->get_omnikassa_order_id() ); |
|
| 304 | - $payment->set_status( Statuses::transform( $order_result->get_order_status() ) ); |
|
| 303 | + $payment->set_transaction_id($order_result->get_omnikassa_order_id()); |
|
| 304 | + $payment->set_status(Statuses::transform($order_result->get_order_status())); |
|
| 305 | 305 | |
| 306 | 306 | // Note. |
| 307 | 307 | $note = ''; |
| 308 | 308 | |
| 309 | 309 | $note .= '<p>'; |
| 310 | - $note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' ); |
|
| 310 | + $note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal'); |
|
| 311 | 311 | $note .= '</p>'; |
| 312 | 312 | $note .= '<pre>'; |
| 313 | - $note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT ); |
|
| 313 | + $note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT); |
|
| 314 | 314 | $note .= '</pre>'; |
| 315 | 315 | |
| 316 | - $payment->add_note( $note ); |
|
| 316 | + $payment->add_note($note); |
|
| 317 | 317 | |
| 318 | 318 | $payment->save(); |
| 319 | 319 | } |
| 320 | - } while ( $order_results->more_available() ); |
|
| 320 | + } while ($order_results->more_available()); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -326,20 +326,20 @@ discard block |
||
| 326 | 326 | * @return void |
| 327 | 327 | */ |
| 328 | 328 | private function maybe_update_access_token() { |
| 329 | - if ( $this->config->is_access_token_valid() ) { |
|
| 329 | + if ($this->config->is_access_token_valid()) { |
|
| 330 | 330 | return; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | $data = $this->client->get_access_token_data(); |
| 334 | 334 | |
| 335 | - if ( ! is_object( $data ) ) { |
|
| 335 | + if ( ! is_object($data)) { |
|
| 336 | 336 | return; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | $this->config->access_token = $data->token; |
| 340 | 340 | $this->config->access_token_valid_until = $data->validUntil; |
| 341 | 341 | |
| 342 | - update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token ); |
|
| 342 | + update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token); |
|
| 343 | 343 | update_post_meta( |
| 344 | 344 | $this->config->post_id, |
| 345 | 345 | '_pronamic_gateway_omnikassa_2_access_token_valid_until', |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | private function get_client_error() { |
| 356 | 356 | $error = $this->client->get_error(); |
| 357 | 357 | |
| 358 | - if ( is_wp_error( $error ) ) { |
|
| 358 | + if (is_wp_error($error)) { |
|
| 359 | 359 | $this->error = $error; |
| 360 | 360 | |
| 361 | 361 | return $error; |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | * @param Money $amount Amount. |
| 83 | 83 | * @param string $category Category. |
| 84 | 84 | */ |
| 85 | - public function __construct( $name, $quantity, Money $amount, $category ) { |
|
| 85 | + public function __construct($name, $quantity, Money $amount, $category) { |
|
| 86 | 86 | $this->name = $name; |
| 87 | 87 | $this->quantity = $quantity; |
| 88 | 88 | $this->amount = $amount; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @param string $email_address E-mailadress of the consumer. |
| 60 | 60 | */ |
| 61 | - public function set_email_address( $email_address ) { |
|
| 61 | + public function set_email_address($email_address) { |
|
| 62 | 62 | $this->email_address = $email_address; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param string $date_of_birth Date of birth. |
| 69 | 69 | */ |
| 70 | - public function set_date_of_birth( $date_of_birth ) { |
|
| 70 | + public function set_date_of_birth($date_of_birth) { |
|
| 71 | 71 | $this->date_of_birth = $date_of_birth; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @param string $gender Gender. |
| 78 | 78 | */ |
| 79 | - public function set_gender( $gender ) { |
|
| 79 | + public function set_gender($gender) { |
|
| 80 | 80 | $this->gender = $gender; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @param string $initials Initials. |
| 87 | 87 | */ |
| 88 | - public function set_initials( $initials ) { |
|
| 88 | + public function set_initials($initials) { |
|
| 89 | 89 | $this->initials = $initials; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @param string $telephone_number Telephone number. |
| 96 | 96 | */ |
| 97 | - public function set_telephone_number( $telephone_number ) { |
|
| 97 | + public function set_telephone_number($telephone_number) { |
|
| 98 | 98 | $this->telephone_number = $telephone_number; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | 'telephoneNumber' => $this->telephone_number, |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | - $data = array_filter( $data ); |
|
| 115 | + $data = array_filter($data); |
|
| 116 | 116 | |
| 117 | - if ( empty( $data ) ) { |
|
| 117 | + if (empty($data)) { |
|
| 118 | 118 | return null; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param array $data Data. |
| 128 | 128 | * @return array |
| 129 | 129 | */ |
| 130 | - public function get_signature_data( $data = array() ) { |
|
| 130 | + public function get_signature_data($data = array()) { |
|
| 131 | 131 | $data[] = $this->email_address; |
| 132 | 132 | $data[] = $this->date_of_birth; |
| 133 | 133 | $data[] = $this->gender; |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @param array $items Order items. |
| 32 | 32 | */ |
| 33 | - public function __construct( $items = null ) { |
|
| 34 | - if ( is_array( $items ) ) { |
|
| 35 | - foreach ( $items as $item ) { |
|
| 36 | - $this->add_item( $item ); |
|
| 33 | + public function __construct($items = null) { |
|
| 34 | + if (is_array($items)) { |
|
| 35 | + foreach ($items as $item) { |
|
| 36 | + $this->add_item($item); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return void |
| 47 | 47 | */ |
| 48 | - public function add_item( $order_item ) { |
|
| 49 | - if ( ! ( $order_item instanceof OrderItem ) ) { |
|
| 50 | - $order_item = new OrderItem( $order_item ); |
|
| 48 | + public function add_item($order_item) { |
|
| 49 | + if ( ! ($order_item instanceof OrderItem)) { |
|
| 50 | + $order_item = new OrderItem($order_item); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $this->order_items[] = $order_item; |
@@ -72,29 +72,29 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $items = $this->get_order_items(); |
| 74 | 74 | |
| 75 | - foreach ( $items as $item ) { |
|
| 75 | + foreach ($items as $item) { |
|
| 76 | 76 | $amount = $item->get_amount(); |
| 77 | 77 | $tax = $item->get_tax(); |
| 78 | 78 | |
| 79 | 79 | $item_data = array( |
| 80 | - 'id' => strval( $item->get_id() ), |
|
| 80 | + 'id' => strval($item->get_id()), |
|
| 81 | 81 | 'name' => $item->get_name(), |
| 82 | 82 | 'description' => $item->get_description(), |
| 83 | 83 | 'quantity' => $item->get_quantity(), |
| 84 | - 'amount' => ( $amount instanceof Money ) ? $amount->get_json() : null, |
|
| 85 | - 'tax' => ( $tax instanceof Money ) ? $tax->get_json() : null, |
|
| 84 | + 'amount' => ($amount instanceof Money) ? $amount->get_json() : null, |
|
| 85 | + 'tax' => ($tax instanceof Money) ? $tax->get_json() : null, |
|
| 86 | 86 | 'category' => $item->get_category(), |
| 87 | 87 | 'vatCategory' => $item->get_vat_category(), |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - $item_data = array_filter( $item_data ); |
|
| 90 | + $item_data = array_filter($item_data); |
|
| 91 | 91 | |
| 92 | - if ( ! empty( $item_data ) ) { |
|
| 92 | + if ( ! empty($item_data)) { |
|
| 93 | 93 | $data[] = (object) $item_data; |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if ( empty( $data ) ) { |
|
| 97 | + if (empty($data)) { |
|
| 98 | 98 | return null; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | $order_items = $this->get_order_items(); |
| 113 | 113 | |
| 114 | - foreach ( $order_items as $item ) { |
|
| 114 | + foreach ($order_items as $item) { |
|
| 115 | 115 | // Optional ID. |
| 116 | 116 | $item_id = $item->get_id(); |
| 117 | 117 | |
| 118 | - if ( ! empty( $item_id ) ) { |
|
| 119 | - $data[] = strval( $item_id ); |
|
| 118 | + if ( ! empty($item_id)) { |
|
| 119 | + $data[] = strval($item_id); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Required fields. |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | $tax = $item->get_tax(); |
| 135 | 135 | |
| 136 | - if ( empty( $tax ) ) { |
|
| 136 | + if (empty($tax)) { |
|
| 137 | 137 | $data[] = ''; |
| 138 | 138 | } else { |
| 139 | 139 | $data[] = $tax->get_currency(); |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | // Optional VAT category. |
| 147 | 147 | $vat_category = $item->get_vat_category(); |
| 148 | 148 | |
| 149 | - if ( ! empty( $vat_category ) ) { |
|
| 149 | + if ( ! empty($vat_category)) { |
|
| 150 | 150 | $data[] = $vat_category; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - var_dump( $data ); |
|
| 153 | + var_dump($data); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return $data; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @param string $first_name First name. |
| 106 | 106 | */ |
| 107 | - public function set_first_name( $first_name ) { |
|
| 107 | + public function set_first_name($first_name) { |
|
| 108 | 108 | $this->first_name = $first_name; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param string $middle_name Middle name. |
| 124 | 124 | */ |
| 125 | - public function set_middle_name( $middle_name ) { |
|
| 125 | + public function set_middle_name($middle_name) { |
|
| 126 | 126 | $this->middle_name = $middle_name; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @param string $last_name Last name. |
| 142 | 142 | */ |
| 143 | - public function set_last_name( $last_name ) { |
|
| 143 | + public function set_last_name($last_name) { |
|
| 144 | 144 | $this->last_name = $last_name; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @param string $street Street. |
| 160 | 160 | */ |
| 161 | - public function set_street( $street ) { |
|
| 161 | + public function set_street($street) { |
|
| 162 | 162 | $this->street = $street; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @param string $house_number House number. |
| 178 | 178 | */ |
| 179 | - public function set_house_number( $house_number ) { |
|
| 179 | + public function set_house_number($house_number) { |
|
| 180 | 180 | $this->house_number = $house_number; |
| 181 | 181 | } |
| 182 | 182 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param string $house_number_addition House number addition. |
| 196 | 196 | */ |
| 197 | - public function set_house_number_addition( $house_number_addition ) { |
|
| 197 | + public function set_house_number_addition($house_number_addition) { |
|
| 198 | 198 | $this->house_number_addition = $house_number_addition; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @param string $postal_code Postal code. |
| 214 | 214 | */ |
| 215 | - public function set_postal_code( $postal_code ) { |
|
| 215 | + public function set_postal_code($postal_code) { |
|
| 216 | 216 | $this->postal_code = $postal_code; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @param string $city City. |
| 232 | 232 | */ |
| 233 | - public function set_city( $city ) { |
|
| 233 | + public function set_city($city) { |
|
| 234 | 234 | $this->city = $city; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * |
| 249 | 249 | * @param string $country_code Country code. |
| 250 | 250 | */ |
| 251 | - public function set_country_code( $country_code ) { |
|
| 251 | + public function set_country_code($country_code) { |
|
| 252 | 252 | $this->country_code = $country_code; |
| 253 | 253 | } |
| 254 | 254 | |
@@ -265,11 +265,11 @@ discard block |
||
| 265 | 265 | $object->lastName = $this->last_name; |
| 266 | 266 | $object->street = $this->street; |
| 267 | 267 | |
| 268 | - if ( null !== $this->house_number ) { |
|
| 268 | + if (null !== $this->house_number) { |
|
| 269 | 269 | $object->houseNumber = $this->house_number; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if ( null !== $this->house_number_addition ) { |
|
| 272 | + if (null !== $this->house_number_addition) { |
|
| 273 | 273 | $object->houseNumberAddition = $this->house_number_addition; |
| 274 | 274 | } |
| 275 | 275 | |
@@ -286,17 +286,17 @@ discard block |
||
| 286 | 286 | * @param array $data Data. |
| 287 | 287 | * @return array |
| 288 | 288 | */ |
| 289 | - public function get_signature_data( $data = array() ) { |
|
| 289 | + public function get_signature_data($data = array()) { |
|
| 290 | 290 | $data[] = $this->first_name; |
| 291 | 291 | $data[] = $this->middle_name; |
| 292 | 292 | $data[] = $this->last_name; |
| 293 | 293 | $data[] = $this->street; |
| 294 | 294 | |
| 295 | - if ( null !== $this->house_number ) { |
|
| 295 | + if (null !== $this->house_number) { |
|
| 296 | 296 | $data[] = $this->house_number; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( null !== $this->house_number_addition ) { |
|
| 299 | + if (null !== $this->house_number_addition) { |
|
| 300 | 300 | $data[] = $this->house_number_addition; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -40,8 +40,8 @@ |
||
| 40 | 40 | * @param string $status OmniKassa 2.0 status. |
| 41 | 41 | * @return string|null |
| 42 | 42 | */ |
| 43 | - public static function transform( $type ) { |
|
| 44 | - switch ( $type ) { |
|
| 43 | + public static function transform($type) { |
|
| 44 | + switch ($type) { |
|
| 45 | 45 | case PaymentLineType::DIGITAL: |
| 46 | 46 | return self::DIGITAL; |
| 47 | 47 | case PaymentLineType::DISCOUNT: |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * @param Money $amount Amount. |
| 154 | 154 | * @param string $merchant_return_url Merchant return URL. |
| 155 | 155 | */ |
| 156 | - public function __construct( $merchant_order_id, $amount, $merchant_return_url ) { |
|
| 157 | - $this->timestamp = date( DATE_ATOM ); |
|
| 156 | + public function __construct($merchant_order_id, $amount, $merchant_return_url) { |
|
| 157 | + $this->timestamp = date(DATE_ATOM); |
|
| 158 | 158 | $this->merchant_order_id = $merchant_order_id; |
| 159 | 159 | $this->amount = $amount; |
| 160 | 160 | $this->merchant_return_url = $merchant_return_url; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @param string $description Description. |
| 167 | 167 | */ |
| 168 | - public function set_description( $description ) { |
|
| 168 | + public function set_description($description) { |
|
| 169 | 169 | $this->description = $description; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param string $language Language. |
| 176 | 176 | */ |
| 177 | - public function set_language( $language ) { |
|
| 177 | + public function set_language($language) { |
|
| 178 | 178 | $this->language = $language; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @param string|null $payment_brand Payment brand. |
| 185 | 185 | */ |
| 186 | - public function set_payment_brand( $payment_brand ) { |
|
| 186 | + public function set_payment_brand($payment_brand) { |
|
| 187 | 187 | $this->payment_brand = $payment_brand; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * |
| 193 | 193 | * @param string $payment_brand_force Payment brand force. |
| 194 | 194 | */ |
| 195 | - public function set_payment_brand_force( $payment_brand_force ) { |
|
| 195 | + public function set_payment_brand_force($payment_brand_force) { |
|
| 196 | 196 | $this->payment_brand_force = $payment_brand_force; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @param OrderItems|null $order_items Order items. |
| 203 | 203 | */ |
| 204 | - public function set_order_items( OrderItems $order_items = null ) { |
|
| 204 | + public function set_order_items(OrderItems $order_items = null) { |
|
| 205 | 205 | $this->order_items = $order_items; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @param Address $shipping_detail Shipping address details. |
| 212 | 212 | */ |
| 213 | - public function set_shipping_detail( Address $shipping_detail ) { |
|
| 213 | + public function set_shipping_detail(Address $shipping_detail) { |
|
| 214 | 214 | $this->shipping_detail = $shipping_detail; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @param Address $billing_detail Billing address details. |
| 221 | 221 | */ |
| 222 | - public function set_billing_detail( Address $billing_detail ) { |
|
| 222 | + public function set_billing_detail(Address $billing_detail) { |
|
| 223 | 223 | $this->billing_detail = $billing_detail; |
| 224 | 224 | } |
| 225 | 225 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @param CustomerInformation $customer_information Customer information. |
| 230 | 230 | */ |
| 231 | - public function set_customer_information( CustomerInformation $customer_information ) { |
|
| 231 | + public function set_customer_information(CustomerInformation $customer_information) { |
|
| 232 | 232 | $this->customer_information = $customer_information; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -244,21 +244,21 @@ discard block |
||
| 244 | 244 | 'description' => $this->description, |
| 245 | 245 | ); |
| 246 | 246 | |
| 247 | - if ( null !== $this->order_items ) { |
|
| 247 | + if (null !== $this->order_items) { |
|
| 248 | 248 | $data['orderItems'] = $this->order_items->get_json(); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $data['amount'] = $this->amount->get_json(); |
| 252 | 252 | |
| 253 | - if ( null !== $this->shipping_detail ) { |
|
| 253 | + if (null !== $this->shipping_detail) { |
|
| 254 | 254 | $data['shippingDetail'] = $this->shipping_detail->get_json(); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( null !== $this->billing_detail ) { |
|
| 257 | + if (null !== $this->billing_detail) { |
|
| 258 | 258 | $data['billingDetail'] = $this->billing_detail->get_json(); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ( null !== $this->customer_information ) { |
|
| 261 | + if (null !== $this->customer_information) { |
|
| 262 | 262 | $data['customerInformation'] = $this->customer_information->get_json(); |
| 263 | 263 | } |
| 264 | 264 | |
@@ -276,35 +276,35 @@ discard block |
||
| 276 | 276 | * @param array $data Data. |
| 277 | 277 | * @return array |
| 278 | 278 | */ |
| 279 | - public function get_signature_data( $data = array() ) { |
|
| 279 | + public function get_signature_data($data = array()) { |
|
| 280 | 280 | // Required fields. |
| 281 | 281 | $fields = array( |
| 282 | 282 | $this->timestamp, |
| 283 | 283 | $this->merchant_order_id, |
| 284 | 284 | $this->amount->get_currency(), |
| 285 | 285 | $this->amount->get_amount(), |
| 286 | - empty( $this->language ) ? '' : $this->language, |
|
| 287 | - empty( $this->description ) ? '' : $this->description, |
|
| 286 | + empty($this->language) ? '' : $this->language, |
|
| 287 | + empty($this->description) ? '' : $this->description, |
|
| 288 | 288 | $this->merchant_return_url, |
| 289 | 289 | ); |
| 290 | 290 | |
| 291 | - if ( null !== $this->order_items ) { |
|
| 292 | - $fields = array_merge( $fields, $this->order_items->get_signature_data() ); |
|
| 291 | + if (null !== $this->order_items) { |
|
| 292 | + $fields = array_merge($fields, $this->order_items->get_signature_data()); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( null !== $this->shipping_detail ) { |
|
| 296 | - $fields = array_merge( $fields, $this->shipping_detail->get_signature_data() ); |
|
| 295 | + if (null !== $this->shipping_detail) { |
|
| 296 | + $fields = array_merge($fields, $this->shipping_detail->get_signature_data()); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | $fields[] = $this->payment_brand; |
| 300 | 300 | $fields[] = $this->payment_brand_force; |
| 301 | 301 | |
| 302 | - if ( null !== $this->customer_information ) { |
|
| 303 | - $fields = $this->customer_information->get_signature_data( $fields ); |
|
| 302 | + if (null !== $this->customer_information) { |
|
| 303 | + $fields = $this->customer_information->get_signature_data($fields); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( null !== $this->billing_detail ) { |
|
| 307 | - $fields = $this->billing_detail->get_signature_data( $fields ); |
|
| 306 | + if (null !== $this->billing_detail) { |
|
| 307 | + $fields = $this->billing_detail->get_signature_data($fields); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | return $fields; |
@@ -25,26 +25,26 @@ discard block |
||
| 25 | 25 | * @param string $signing_key Signing Key. |
| 26 | 26 | * @return string|null |
| 27 | 27 | */ |
| 28 | - public static function get_signature( Signable $signable, $signing_key ) { |
|
| 28 | + public static function get_signature(Signable $signable, $signing_key) { |
|
| 29 | 29 | $data = $signable->get_signature_data(); |
| 30 | 30 | |
| 31 | - if ( empty( $data ) ) { |
|
| 31 | + if (empty($data)) { |
|
| 32 | 32 | return null; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ( empty( $signing_key ) ) { |
|
| 35 | + if (empty($signing_key)) { |
|
| 36 | 36 | return null; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - $decoded_signing_key = base64_decode( $signing_key ); |
|
| 39 | + $decoded_signing_key = base64_decode($signing_key); |
|
| 40 | 40 | |
| 41 | - if ( false === $decoded_signing_key ) { |
|
| 41 | + if (false === $decoded_signing_key) { |
|
| 42 | 42 | return null; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $combined = implode( ',', $data ); |
|
| 45 | + $combined = implode(',', $data); |
|
| 46 | 46 | |
| 47 | - var_dump( $combined ); |
|
| 47 | + var_dump($combined); |
|
| 48 | 48 | |
| 49 | 49 | $signature = hash_hmac( |
| 50 | 50 | 'sha512', |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | * @param string $signature_b Signature B. |
| 63 | 63 | * @return bool True if valid, false otherwise. |
| 64 | 64 | */ |
| 65 | - public static function validate_signature( $signature_a, $signature_b ) { |
|
| 66 | - if ( empty( $signature_a ) || empty( $signature_b ) ) { |
|
| 65 | + public static function validate_signature($signature_a, $signature_b) { |
|
| 66 | + if (empty($signature_a) || empty($signature_b)) { |
|
| 67 | 67 | // Empty signature string or null from calculation. |
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - return ( 0 === strcasecmp( $signature_a, $signature_b ) ); |
|
| 71 | + return (0 === strcasecmp($signature_a, $signature_b)); |
|
| 72 | 72 | } |
| 73 | 73 | } |