@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @param Config $config |
| 48 | 48 | */ |
| 49 | - public function __construct( Config $config ) { |
|
| 50 | - parent::__construct( $config ); |
|
| 49 | + public function __construct(Config $config) { |
|
| 50 | + parent::__construct($config); |
|
| 51 | 51 | |
| 52 | 52 | $this->supports = array( |
| 53 | 53 | 'payment_status_request', |
@@ -56,18 +56,18 @@ discard block |
||
| 56 | 56 | 'recurring', |
| 57 | 57 | ); |
| 58 | 58 | |
| 59 | - $this->set_method( self::METHOD_HTTP_REDIRECT ); |
|
| 60 | - $this->set_slug( self::SLUG ); |
|
| 59 | + $this->set_method(self::METHOD_HTTP_REDIRECT); |
|
| 60 | + $this->set_slug(self::SLUG); |
|
| 61 | 61 | |
| 62 | - $this->client = new Client( $config->api_key ); |
|
| 63 | - $this->client->set_mode( $config->mode ); |
|
| 62 | + $this->client = new Client($config->api_key); |
|
| 63 | + $this->client->set_mode($config->mode); |
|
| 64 | 64 | |
| 65 | - if ( self::MODE_TEST === $config->mode ) { |
|
| 65 | + if (self::MODE_TEST === $config->mode) { |
|
| 66 | 66 | $this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test'; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // Actions. |
| 70 | - add_action( 'pronamic_payment_status_update', array( $this, 'copy_customer_id_to_wp_user' ), 99, 1 ); |
|
| 70 | + add_action('pronamic_payment_status_update', array($this, 'copy_customer_id_to_wp_user'), 99, 1); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | $result = $this->client->get_issuers(); |
| 82 | 82 | |
| 83 | - if ( ! $result ) { |
|
| 83 | + if ( ! $result) { |
|
| 84 | 84 | $this->error = $this->client->get_error(); |
| 85 | 85 | |
| 86 | 86 | return $groups; |
@@ -102,51 +102,51 @@ discard block |
||
| 102 | 102 | $payment_methods = array(); |
| 103 | 103 | |
| 104 | 104 | // Set recurring types to get payment methods for. |
| 105 | - $recurring_types = array( null, Recurring::RECURRING, Recurring::FIRST ); |
|
| 105 | + $recurring_types = array(null, Recurring::RECURRING, Recurring::FIRST); |
|
| 106 | 106 | |
| 107 | 107 | $results = array(); |
| 108 | 108 | |
| 109 | - foreach ( $recurring_types as $recurring_type ) { |
|
| 109 | + foreach ($recurring_types as $recurring_type) { |
|
| 110 | 110 | // Get active payment methods for Mollie account. |
| 111 | - $result = $this->client->get_payment_methods( $recurring_type ); |
|
| 111 | + $result = $this->client->get_payment_methods($recurring_type); |
|
| 112 | 112 | |
| 113 | - if ( ! $result ) { |
|
| 113 | + if ( ! $result) { |
|
| 114 | 114 | $this->error = $this->client->get_error(); |
| 115 | 115 | |
| 116 | 116 | break; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( Recurring::FIRST === $recurring_type ) { |
|
| 120 | - foreach ( $result as $method => $title ) { |
|
| 121 | - unset( $result[ $method ] ); |
|
| 119 | + if (Recurring::FIRST === $recurring_type) { |
|
| 120 | + foreach ($result as $method => $title) { |
|
| 121 | + unset($result[$method]); |
|
| 122 | 122 | |
| 123 | 123 | // Get WordPress payment method for direct debit method. |
| 124 | - $method = Methods::transform_gateway_method( $method ); |
|
| 125 | - $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); |
|
| 124 | + $method = Methods::transform_gateway_method($method); |
|
| 125 | + $payment_method = array_search($method, PaymentMethods::get_recurring_methods(), true); |
|
| 126 | 126 | |
| 127 | - if ( $payment_method ) { |
|
| 128 | - $results[ $payment_method ] = $title; |
|
| 127 | + if ($payment_method) { |
|
| 128 | + $results[$payment_method] = $title; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $results = array_merge( $results, $result ); |
|
| 133 | + $results = array_merge($results, $result); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Transform to WordPress payment methods. |
| 137 | - foreach ( $results as $method => $title ) { |
|
| 138 | - if ( PaymentMethods::is_recurring_method( $method ) ) { |
|
| 137 | + foreach ($results as $method => $title) { |
|
| 138 | + if (PaymentMethods::is_recurring_method($method)) { |
|
| 139 | 139 | $payment_method = $method; |
| 140 | 140 | } else { |
| 141 | - $payment_method = Methods::transform_gateway_method( $method ); |
|
| 141 | + $payment_method = Methods::transform_gateway_method($method); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( $payment_method ) { |
|
| 144 | + if ($payment_method) { |
|
| 145 | 145 | $payment_methods[] = $payment_method; |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $payment_methods = array_unique( $payment_methods ); |
|
| 149 | + $payment_methods = array_unique($payment_methods); |
|
| 150 | 150 | |
| 151 | 151 | return $payment_methods; |
| 152 | 152 | } |
@@ -180,27 +180,27 @@ discard block |
||
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | 182 | public function get_webhook_url() { |
| 183 | - $url = home_url( '/' ); |
|
| 183 | + $url = home_url('/'); |
|
| 184 | 184 | |
| 185 | - $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
| 185 | + $host = wp_parse_url($url, PHP_URL_HOST); |
|
| 186 | 186 | |
| 187 | - if ( is_array( $host ) ) { |
|
| 187 | + if (is_array($host)) { |
|
| 188 | 188 | // Parsing failure. |
| 189 | 189 | $host = ''; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if ( 'localhost' === $host ) { |
|
| 192 | + if ('localhost' === $host) { |
|
| 193 | 193 | // Mollie doesn't allow localhost. |
| 194 | 194 | return null; |
| 195 | - } elseif ( '.dev' === substr( $host, -4 ) ) { |
|
| 195 | + } elseif ('.dev' === substr($host, -4)) { |
|
| 196 | 196 | // Mollie doesn't allow the .dev TLD. |
| 197 | 197 | return null; |
| 198 | - } elseif ( '.local' === substr( $host, -6 ) ) { |
|
| 198 | + } elseif ('.local' === substr($host, -6)) { |
|
| 199 | 199 | // Mollie doesn't allow the .local TLD. |
| 200 | 200 | return null; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - $url = add_query_arg( 'mollie_webhook', '', $url ); |
|
| 203 | + $url = add_query_arg('mollie_webhook', '', $url); |
|
| 204 | 204 | |
| 205 | 205 | return $url; |
| 206 | 206 | } |
@@ -210,19 +210,19 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @see Pronamic_WP_Pay_Gateway::start() |
| 212 | 212 | */ |
| 213 | - public function start( Payment $payment ) { |
|
| 213 | + public function start(Payment $payment) { |
|
| 214 | 214 | $request = new PaymentRequest(); |
| 215 | 215 | |
| 216 | 216 | $request->amount = $payment->get_amount()->get_amount(); |
| 217 | 217 | $request->description = $payment->get_description(); |
| 218 | 218 | $request->redirect_url = $payment->get_return_url(); |
| 219 | 219 | $request->webhook_url = $this->get_webhook_url(); |
| 220 | - $request->locale = LocaleHelper::transform( $payment->get_language() ); |
|
| 220 | + $request->locale = LocaleHelper::transform($payment->get_language()); |
|
| 221 | 221 | |
| 222 | 222 | // Customer ID. |
| 223 | - $customer_id = $this->get_customer_id_for_payment( $payment ); |
|
| 223 | + $customer_id = $this->get_customer_id_for_payment($payment); |
|
| 224 | 224 | |
| 225 | - if ( is_string( $customer_id ) && ! empty( $customer_id ) ) { |
|
| 225 | + if (is_string($customer_id) && ! empty($customer_id)) { |
|
| 226 | 226 | $request->customer_id = $customer_id; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -232,49 +232,49 @@ discard block |
||
| 232 | 232 | // Subscription. |
| 233 | 233 | $subscription = $payment->get_subscription(); |
| 234 | 234 | |
| 235 | - if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { |
|
| 235 | + if ($subscription && PaymentMethods::is_recurring_method($payment_method)) { |
|
| 236 | 236 | $request->recurring_type = $payment->get_recurring() ? Recurring::RECURRING : Recurring::FIRST; |
| 237 | 237 | |
| 238 | - if ( Recurring::FIRST === $request->recurring_type ) { |
|
| 239 | - $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); |
|
| 238 | + if (Recurring::FIRST === $request->recurring_type) { |
|
| 239 | + $payment_method = PaymentMethods::get_first_payment_method($payment_method); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if ( Recurring::RECURRING === $request->recurring_type ) { |
|
| 243 | - $payment->set_action_url( $payment->get_return_url() ); |
|
| 242 | + if (Recurring::RECURRING === $request->recurring_type) { |
|
| 243 | + $payment->set_action_url($payment->get_return_url()); |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? |
| 248 | - $request->method = Methods::transform( $payment_method, $payment_method ); |
|
| 248 | + $request->method = Methods::transform($payment_method, $payment_method); |
|
| 249 | 249 | |
| 250 | 250 | // Issuer. |
| 251 | - if ( Methods::IDEAL === $request->method ) { |
|
| 251 | + if (Methods::IDEAL === $request->method) { |
|
| 252 | 252 | // If payment method is iDEAL we set the user chosen issuer ID. |
| 253 | 253 | $request->issuer = $payment->get_issuer(); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Create payment. |
| 257 | - $result = $this->client->create_payment( $request ); |
|
| 257 | + $result = $this->client->create_payment($request); |
|
| 258 | 258 | |
| 259 | - if ( ! $result ) { |
|
| 259 | + if ( ! $result) { |
|
| 260 | 260 | $this->error = $this->client->get_error(); |
| 261 | 261 | |
| 262 | 262 | return false; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | // Set transaction ID. |
| 266 | - if ( isset( $result->id ) ) { |
|
| 267 | - $payment->set_transaction_id( $result->id ); |
|
| 266 | + if (isset($result->id)) { |
|
| 267 | + $payment->set_transaction_id($result->id); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Set status |
| 271 | - if ( isset( $result->status ) ) { |
|
| 272 | - $payment->set_status( Statuses::transform( $result->status ) ); |
|
| 271 | + if (isset($result->status)) { |
|
| 272 | + $payment->set_status(Statuses::transform($result->status)); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Set action URL. |
| 276 | - if ( isset( $result->links, $result->links->paymentUrl ) ) { |
|
| 277 | - $payment->set_action_url( $result->links->paymentUrl ); |
|
| 276 | + if (isset($result->links, $result->links->paymentUrl)) { |
|
| 277 | + $payment->set_action_url($result->links->paymentUrl); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -283,36 +283,36 @@ discard block |
||
| 283 | 283 | * |
| 284 | 284 | * @param Payment $payment |
| 285 | 285 | */ |
| 286 | - public function update_status( Payment $payment ) { |
|
| 287 | - $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); |
|
| 286 | + public function update_status(Payment $payment) { |
|
| 287 | + $mollie_payment = $this->client->get_payment($payment->get_transaction_id()); |
|
| 288 | 288 | |
| 289 | - if ( ! $mollie_payment ) { |
|
| 290 | - $payment->set_status( Core_Statuses::FAILURE ); |
|
| 289 | + if ( ! $mollie_payment) { |
|
| 290 | + $payment->set_status(Core_Statuses::FAILURE); |
|
| 291 | 291 | |
| 292 | 292 | $this->error = $this->client->get_error(); |
| 293 | 293 | |
| 294 | 294 | return; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - $payment->set_status( Statuses::transform( $mollie_payment->status ) ); |
|
| 297 | + $payment->set_status(Statuses::transform($mollie_payment->status)); |
|
| 298 | 298 | |
| 299 | - if ( isset( $mollie_payment->details ) ) { |
|
| 299 | + if (isset($mollie_payment->details)) { |
|
| 300 | 300 | $details = $mollie_payment->details; |
| 301 | 301 | |
| 302 | - if ( isset( $details->consumerName ) ) { |
|
| 303 | - $payment->set_consumer_name( $details->consumerName ); |
|
| 302 | + if (isset($details->consumerName)) { |
|
| 303 | + $payment->set_consumer_name($details->consumerName); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( isset( $details->cardHolder ) ) { |
|
| 307 | - $payment->set_consumer_name( $details->cardHolder ); |
|
| 306 | + if (isset($details->cardHolder)) { |
|
| 307 | + $payment->set_consumer_name($details->cardHolder); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( isset( $details->consumerAccount ) ) { |
|
| 311 | - $payment->set_consumer_iban( $details->consumerAccount ); |
|
| 310 | + if (isset($details->consumerAccount)) { |
|
| 311 | + $payment->set_consumer_iban($details->consumerAccount); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if ( isset( $details->consumerBic ) ) { |
|
| 315 | - $payment->set_consumer_bic( $details->consumerBic ); |
|
| 314 | + if (isset($details->consumerBic)) { |
|
| 315 | + $payment->set_consumer_bic($details->consumerBic); |
|
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | } |
@@ -324,42 +324,42 @@ discard block |
||
| 324 | 324 | * |
| 325 | 325 | * @return bool|string |
| 326 | 326 | */ |
| 327 | - public function get_customer_id_for_payment( Payment $payment ) { |
|
| 327 | + public function get_customer_id_for_payment(Payment $payment) { |
|
| 328 | 328 | // Get Mollie customer ID from user meta. |
| 329 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 329 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 330 | 330 | |
| 331 | 331 | $subscription = $payment->get_subscription(); |
| 332 | 332 | |
| 333 | 333 | // Get customer ID from subscription meta. |
| 334 | - if ( $subscription ) { |
|
| 335 | - $subscription_customer_id = $subscription->get_meta( 'mollie_customer_id' ); |
|
| 334 | + if ($subscription) { |
|
| 335 | + $subscription_customer_id = $subscription->get_meta('mollie_customer_id'); |
|
| 336 | 336 | |
| 337 | 337 | // Try to get (legacy) customer ID from first payment. |
| 338 | - if ( empty( $subscription_customer_id ) && $subscription->get_first_payment() ) { |
|
| 338 | + if (empty($subscription_customer_id) && $subscription->get_first_payment()) { |
|
| 339 | 339 | $first_payment = $subscription->get_first_payment(); |
| 340 | 340 | |
| 341 | - $subscription_customer_id = $first_payment->get_meta( 'mollie_customer_id' ); |
|
| 341 | + $subscription_customer_id = $first_payment->get_meta('mollie_customer_id'); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if ( ! empty( $subscription_customer_id ) ) { |
|
| 344 | + if ( ! empty($subscription_customer_id)) { |
|
| 345 | 345 | $customer_id = $subscription_customer_id; |
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Create new customer if the customer does not exist at Mollie. |
| 350 | - if ( ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) && Core_Recurring::RECURRING !== $payment->recurring_type ) { |
|
| 351 | - $customer_id = $this->client->create_customer( $payment->get_email(), $payment->get_customer_name() ); |
|
| 350 | + if ((empty($customer_id) || ! $this->client->get_customer($customer_id)) && Core_Recurring::RECURRING !== $payment->recurring_type) { |
|
| 351 | + $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name()); |
|
| 352 | 352 | |
| 353 | - $this->update_wp_user_customer_id( $payment->user_id, $customer_id ); |
|
| 353 | + $this->update_wp_user_customer_id($payment->user_id, $customer_id); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Store customer ID in subscription meta. |
| 357 | - if ( $subscription && empty( $subscription_customer_id ) && ! empty( $customer_id ) ) { |
|
| 358 | - $subscription->set_meta( 'mollie_customer_id', $customer_id ); |
|
| 357 | + if ($subscription && empty($subscription_customer_id) && ! empty($customer_id)) { |
|
| 358 | + $subscription->set_meta('mollie_customer_id', $customer_id); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // Copy customer ID from subscription to user meta. |
| 362 | - $this->copy_customer_id_to_wp_user( $payment ); |
|
| 362 | + $this->copy_customer_id_to_wp_user($payment); |
|
| 363 | 363 | |
| 364 | 364 | return $customer_id; |
| 365 | 365 | } |
@@ -371,12 +371,12 @@ discard block |
||
| 371 | 371 | * |
| 372 | 372 | * @return string|bool |
| 373 | 373 | */ |
| 374 | - public function get_customer_id_by_wp_user_id( $user_id ) { |
|
| 375 | - if ( empty( $user_id ) ) { |
|
| 374 | + public function get_customer_id_by_wp_user_id($user_id) { |
|
| 375 | + if (empty($user_id)) { |
|
| 376 | 376 | return false; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - return get_user_meta( $user_id, $this->meta_key_customer_id, true ); |
|
| 379 | + return get_user_meta($user_id, $this->meta_key_customer_id, true); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | /** |
@@ -387,16 +387,16 @@ discard block |
||
| 387 | 387 | * |
| 388 | 388 | * @return bool |
| 389 | 389 | */ |
| 390 | - private function update_wp_user_customer_id( $user_id, $customer_id ) { |
|
| 391 | - if ( empty( $user_id ) || is_bool( $user_id ) ) { |
|
| 390 | + private function update_wp_user_customer_id($user_id, $customer_id) { |
|
| 391 | + if (empty($user_id) || is_bool($user_id)) { |
|
| 392 | 392 | return false; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if ( ! is_string( $customer_id ) || empty( $customer_id ) || 1 === strlen( $customer_id ) ) { |
|
| 395 | + if ( ! is_string($customer_id) || empty($customer_id) || 1 === strlen($customer_id)) { |
|
| 396 | 396 | return false; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id ); |
|
| 399 | + update_user_meta($user_id, $this->meta_key_customer_id, $customer_id); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -406,25 +406,25 @@ discard block |
||
| 406 | 406 | * |
| 407 | 407 | * @return void |
| 408 | 408 | */ |
| 409 | - public function copy_customer_id_to_wp_user( Payment $payment ) { |
|
| 410 | - if ( $this->config->id !== $payment->config_id ) { |
|
| 409 | + public function copy_customer_id_to_wp_user(Payment $payment) { |
|
| 410 | + if ($this->config->id !== $payment->config_id) { |
|
| 411 | 411 | return; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | $subscription = $payment->get_subscription(); |
| 415 | 415 | |
| 416 | - if ( ! $subscription || empty( $subscription->user_id ) ) { |
|
| 416 | + if ( ! $subscription || empty($subscription->user_id)) { |
|
| 417 | 417 | return; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // Get customer ID from subscription meta. |
| 421 | - $customer_id = $subscription->get_meta( 'mollie_customer_id' ); |
|
| 421 | + $customer_id = $subscription->get_meta('mollie_customer_id'); |
|
| 422 | 422 | |
| 423 | - $user_customer_id = $this->get_customer_id_by_wp_user_id( $subscription->user_id ); |
|
| 423 | + $user_customer_id = $this->get_customer_id_by_wp_user_id($subscription->user_id); |
|
| 424 | 424 | |
| 425 | - if ( empty( $user_customer_id ) ) { |
|
| 425 | + if (empty($user_customer_id)) { |
|
| 426 | 426 | // Set customer ID as user meta. |
| 427 | - $this->update_wp_user_customer_id( $subscription->user_id, $customer_id ); |
|
| 427 | + $this->update_wp_user_customer_id($subscription->user_id, $customer_id); |
|
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | 430 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @param string $api_key |
| 53 | 53 | */ |
| 54 | - public function __construct( $api_key ) { |
|
| 54 | + public function __construct($api_key) { |
|
| 55 | 55 | $this->api_key = $api_key; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @since 1.1.9 |
| 62 | 62 | * @param string $mode |
| 63 | 63 | */ |
| 64 | - public function set_mode( $mode ) { |
|
| 64 | + public function set_mode($mode) { |
|
| 65 | 65 | $this->mode = $mode; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return bool|object |
| 86 | 86 | */ |
| 87 | - private function send_request( $end_point, $method = 'GET', array $data = array(), $expected_response_code = 200 ) { |
|
| 87 | + private function send_request($end_point, $method = 'GET', array $data = array(), $expected_response_code = 200) { |
|
| 88 | 88 | // Request |
| 89 | 89 | $url = self::API_URL . $end_point; |
| 90 | 90 | |
@@ -100,26 +100,26 @@ discard block |
||
| 100 | 100 | ); |
| 101 | 101 | |
| 102 | 102 | // Response code |
| 103 | - $response_code = wp_remote_retrieve_response_code( $response ); |
|
| 103 | + $response_code = wp_remote_retrieve_response_code($response); |
|
| 104 | 104 | |
| 105 | - if ( $expected_response_code != $response_code ) { // WPCS: loose comparison ok. |
|
| 106 | - $this->error = new WP_Error( 'mollie_error', 'Unexpected response code.' ); |
|
| 105 | + if ($expected_response_code != $response_code) { // WPCS: loose comparison ok. |
|
| 106 | + $this->error = new WP_Error('mollie_error', 'Unexpected response code.'); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // Body |
| 110 | - $body = wp_remote_retrieve_body( $response ); |
|
| 110 | + $body = wp_remote_retrieve_body($response); |
|
| 111 | 111 | |
| 112 | - $data = json_decode( $body ); |
|
| 112 | + $data = json_decode($body); |
|
| 113 | 113 | |
| 114 | - if ( ! is_object( $data ) ) { |
|
| 115 | - $this->error = new WP_Error( 'mollie_error', 'Could not parse response.' ); |
|
| 114 | + if ( ! is_object($data)) { |
|
| 115 | + $this->error = new WP_Error('mollie_error', 'Could not parse response.'); |
|
| 116 | 116 | |
| 117 | 117 | return false; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Mollie error |
| 121 | - if ( isset( $data->error, $data->error->message ) ) { |
|
| 122 | - $this->error = new \WP_Error( 'mollie_error', $data->error->message, $data->error ); |
|
| 121 | + if (isset($data->error, $data->error->message)) { |
|
| 122 | + $this->error = new \WP_Error('mollie_error', $data->error->message, $data->error); |
|
| 123 | 123 | |
| 124 | 124 | return false; |
| 125 | 125 | } |
@@ -127,20 +127,20 @@ discard block |
||
| 127 | 127 | return $data; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function create_payment( PaymentRequest $request ) { |
|
| 131 | - return $this->send_request( 'payments/', 'POST', $request->get_array(), 201 ); |
|
| 130 | + public function create_payment(PaymentRequest $request) { |
|
| 131 | + return $this->send_request('payments/', 'POST', $request->get_array(), 201); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public function get_payments() { |
| 135 | - return $this->send_request( 'payments/', 'GET' ); |
|
| 135 | + return $this->send_request('payments/', 'GET'); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function get_payment( $payment_id ) { |
|
| 139 | - if ( empty( $payment_id ) ) { |
|
| 138 | + public function get_payment($payment_id) { |
|
| 139 | + if (empty($payment_id)) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - return $this->send_request( 'payments/' . $payment_id, 'GET' ); |
|
| 143 | + return $this->send_request('payments/' . $payment_id, 'GET'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | * @return array|bool |
| 150 | 150 | */ |
| 151 | 151 | public function get_issuers() { |
| 152 | - $response = $this->send_request( 'issuers/', 'GET' ); |
|
| 152 | + $response = $this->send_request('issuers/', 'GET'); |
|
| 153 | 153 | |
| 154 | - if ( false === $response ) { |
|
| 154 | + if (false === $response) { |
|
| 155 | 155 | return false; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | $issuers = array(); |
| 159 | 159 | |
| 160 | - if ( isset( $response->data ) ) { |
|
| 161 | - foreach ( $response->data as $issuer ) { |
|
| 162 | - if ( Methods::IDEAL === $issuer->method ) { |
|
| 163 | - $id = Security::filter( $issuer->id ); |
|
| 164 | - $name = Security::filter( $issuer->name ); |
|
| 160 | + if (isset($response->data)) { |
|
| 161 | + foreach ($response->data as $issuer) { |
|
| 162 | + if (Methods::IDEAL === $issuer->method) { |
|
| 163 | + $id = Security::filter($issuer->id); |
|
| 164 | + $name = Security::filter($issuer->name); |
|
| 165 | 165 | |
| 166 | - $issuers[ $id ] = $name; |
|
| 166 | + $issuers[$id] = $name; |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -178,27 +178,27 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return array|bool |
| 180 | 180 | */ |
| 181 | - public function get_payment_methods( $recurring_type = '' ) { |
|
| 181 | + public function get_payment_methods($recurring_type = '') { |
|
| 182 | 182 | $data = array(); |
| 183 | 183 | |
| 184 | - if ( '' !== $recurring_type ) { |
|
| 184 | + if ('' !== $recurring_type) { |
|
| 185 | 185 | $data['recurringType'] = $recurring_type; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - $response = $this->send_request( 'methods/', 'GET', $data ); |
|
| 188 | + $response = $this->send_request('methods/', 'GET', $data); |
|
| 189 | 189 | |
| 190 | - if ( false === $response ) { |
|
| 190 | + if (false === $response) { |
|
| 191 | 191 | return false; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | $payment_methods = array(); |
| 195 | 195 | |
| 196 | - if ( isset( $response->data ) ) { |
|
| 197 | - foreach ( $response->data as $payment_method ) { |
|
| 198 | - $id = Security::filter( $payment_method->id ); |
|
| 199 | - $name = Security::filter( $payment_method->description ); |
|
| 196 | + if (isset($response->data)) { |
|
| 197 | + foreach ($response->data as $payment_method) { |
|
| 198 | + $id = Security::filter($payment_method->id); |
|
| 199 | + $name = Security::filter($payment_method->description); |
|
| 200 | 200 | |
| 201 | - $payment_methods[ $id ] = $name; |
|
| 201 | + $payment_methods[$id] = $name; |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @return string|bool |
| 217 | 217 | */ |
| 218 | - public function create_customer( $email, $name ) { |
|
| 219 | - if ( empty( $email ) || empty( $name ) ) { |
|
| 218 | + public function create_customer($email, $name) { |
|
| 219 | + if (empty($email) || empty($name)) { |
|
| 220 | 220 | return false; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -230,11 +230,11 @@ discard block |
||
| 230 | 230 | 201 |
| 231 | 231 | ); |
| 232 | 232 | |
| 233 | - if ( false === $response ) { |
|
| 233 | + if (false === $response) { |
|
| 234 | 234 | return false; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( ! isset( $response->id ) ) { |
|
| 237 | + if ( ! isset($response->id)) { |
|
| 238 | 238 | return false; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -250,18 +250,18 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @return object|bool |
| 252 | 252 | */ |
| 253 | - public function get_customer( $customer_id ) { |
|
| 254 | - if ( empty( $customer_id ) ) { |
|
| 253 | + public function get_customer($customer_id) { |
|
| 254 | + if (empty($customer_id)) { |
|
| 255 | 255 | return false; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - $response = $this->send_request( 'customers/' . $customer_id, 'GET', array(), 200 ); |
|
| 258 | + $response = $this->send_request('customers/' . $customer_id, 'GET', array(), 200); |
|
| 259 | 259 | |
| 260 | - if ( false === $response ) { |
|
| 260 | + if (false === $response) { |
|
| 261 | 261 | return false; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - if ( is_wp_error( $this->error ) ) { |
|
| 264 | + if (is_wp_error($this->error)) { |
|
| 265 | 265 | return false; |
| 266 | 266 | } |
| 267 | 267 | |
@@ -275,12 +275,12 @@ discard block |
||
| 275 | 275 | * |
| 276 | 276 | * @return object|bool |
| 277 | 277 | */ |
| 278 | - public function get_mandates( $customer_id ) { |
|
| 279 | - if ( '' === $customer_id ) { |
|
| 278 | + public function get_mandates($customer_id) { |
|
| 279 | + if ('' === $customer_id) { |
|
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - return $this->send_request( 'customers/' . $customer_id . '/mandates?count=250', 'GET' ); |
|
| 283 | + return $this->send_request('customers/' . $customer_id . '/mandates?count=250', 'GET'); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -291,21 +291,21 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @return boolean |
| 293 | 293 | */ |
| 294 | - public function has_valid_mandate( $customer_id, $payment_method = null ) { |
|
| 295 | - $mandates = $this->get_mandates( $customer_id ); |
|
| 294 | + public function has_valid_mandate($customer_id, $payment_method = null) { |
|
| 295 | + $mandates = $this->get_mandates($customer_id); |
|
| 296 | 296 | |
| 297 | - if ( ! $mandates ) { |
|
| 297 | + if ( ! $mandates) { |
|
| 298 | 298 | return false; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $mollie_method = Methods::transform( $payment_method ); |
|
| 301 | + $mollie_method = Methods::transform($payment_method); |
|
| 302 | 302 | |
| 303 | - foreach ( $mandates->data as $mandate ) { |
|
| 304 | - if ( $mollie_method !== $mandate->method ) { |
|
| 303 | + foreach ($mandates->data as $mandate) { |
|
| 304 | + if ($mollie_method !== $mandate->method) { |
|
| 305 | 305 | continue; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if ( 'valid' === $mandate->status ) { |
|
| 308 | + if ('valid' === $mandate->status) { |
|
| 309 | 309 | return true; |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -321,40 +321,40 @@ discard block |
||
| 321 | 321 | * |
| 322 | 322 | * @return null|DateTime |
| 323 | 323 | */ |
| 324 | - public function get_first_valid_mandate_datetime( $customer_id, $payment_method = null ) { |
|
| 325 | - $mandates = $this->get_mandates( $customer_id ); |
|
| 324 | + public function get_first_valid_mandate_datetime($customer_id, $payment_method = null) { |
|
| 325 | + $mandates = $this->get_mandates($customer_id); |
|
| 326 | 326 | |
| 327 | - if ( ! $mandates ) { |
|
| 327 | + if ( ! $mandates) { |
|
| 328 | 328 | return null; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $mollie_method = Methods::transform( $payment_method ); |
|
| 331 | + $mollie_method = Methods::transform($payment_method); |
|
| 332 | 332 | |
| 333 | - foreach ( $mandates->data as $mandate ) { |
|
| 334 | - if ( $mollie_method !== $mandate->method ) { |
|
| 333 | + foreach ($mandates->data as $mandate) { |
|
| 334 | + if ($mollie_method !== $mandate->method) { |
|
| 335 | 335 | continue; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( 'valid' !== $mandate->status ) { |
|
| 338 | + if ('valid' !== $mandate->status) { |
|
| 339 | 339 | continue; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if ( ! isset( $valid_mandates ) ) { |
|
| 342 | + if ( ! isset($valid_mandates)) { |
|
| 343 | 343 | $valid_mandates = array(); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // @codingStandardsIgnoreStart |
| 347 | - $valid_mandates[ $mandate->createdDatetime ] = $mandate; |
|
| 347 | + $valid_mandates[$mandate->createdDatetime] = $mandate; |
|
| 348 | 348 | // @codingStandardsIgnoreEnd |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if ( isset( $valid_mandates ) ) { |
|
| 352 | - ksort( $valid_mandates ); |
|
| 351 | + if (isset($valid_mandates)) { |
|
| 352 | + ksort($valid_mandates); |
|
| 353 | 353 | |
| 354 | - $mandate = array_shift( $valid_mandates ); |
|
| 354 | + $mandate = array_shift($valid_mandates); |
|
| 355 | 355 | |
| 356 | 356 | // @codingStandardsIgnoreStart |
| 357 | - $create_date = new DateTime( $mandate->createdDatetime ); |
|
| 357 | + $create_date = new DateTime($mandate->createdDatetime); |
|
| 358 | 358 | // @codingStandardsIgnoreEnd |
| 359 | 359 | |
| 360 | 360 | return $create_date; |