@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @param Config $config |
| 47 | 47 | */ |
| 48 | - public function __construct( Config $config ) { |
|
| 49 | - parent::__construct( $config ); |
|
| 48 | + public function __construct(Config $config) { |
|
| 49 | + parent::__construct($config); |
|
| 50 | 50 | |
| 51 | 51 | $this->supports = array( |
| 52 | 52 | 'payment_status_request', |
@@ -55,18 +55,18 @@ discard block |
||
| 55 | 55 | 'recurring', |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - $this->set_method( self::METHOD_HTTP_REDIRECT ); |
|
| 59 | - $this->set_slug( self::SLUG ); |
|
| 58 | + $this->set_method(self::METHOD_HTTP_REDIRECT); |
|
| 59 | + $this->set_slug(self::SLUG); |
|
| 60 | 60 | |
| 61 | - $this->client = new Client( $config->api_key ); |
|
| 62 | - $this->client->set_mode( $config->mode ); |
|
| 61 | + $this->client = new Client($config->api_key); |
|
| 62 | + $this->client->set_mode($config->mode); |
|
| 63 | 63 | |
| 64 | - if ( self::MODE_TEST === $config->mode ) { |
|
| 64 | + if (self::MODE_TEST === $config->mode) { |
|
| 65 | 65 | $this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test'; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Actions. |
| 69 | - add_action( 'pronamic_payment_status_update', array( $this, 'copy_customer_id_to_wp_user' ), 99, 1 ); |
|
| 69 | + add_action('pronamic_payment_status_update', array($this, 'copy_customer_id_to_wp_user'), 99, 1); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $result = $this->client->get_issuers(); |
| 81 | 81 | |
| 82 | - if ( ! $result ) { |
|
| 82 | + if ( ! $result) { |
|
| 83 | 83 | $this->error = $this->client->get_error(); |
| 84 | 84 | |
| 85 | 85 | return $groups; |
@@ -101,51 +101,51 @@ discard block |
||
| 101 | 101 | $payment_methods = array(); |
| 102 | 102 | |
| 103 | 103 | // Set recurring types to get payment methods for. |
| 104 | - $recurring_types = array( null, Recurring::RECURRING, Recurring::FIRST ); |
|
| 104 | + $recurring_types = array(null, Recurring::RECURRING, Recurring::FIRST); |
|
| 105 | 105 | |
| 106 | 106 | $results = array(); |
| 107 | 107 | |
| 108 | - foreach ( $recurring_types as $recurring_type ) { |
|
| 108 | + foreach ($recurring_types as $recurring_type) { |
|
| 109 | 109 | // Get active payment methods for Mollie account. |
| 110 | - $result = $this->client->get_payment_methods( $recurring_type ); |
|
| 110 | + $result = $this->client->get_payment_methods($recurring_type); |
|
| 111 | 111 | |
| 112 | - if ( ! $result ) { |
|
| 112 | + if ( ! $result) { |
|
| 113 | 113 | $this->error = $this->client->get_error(); |
| 114 | 114 | |
| 115 | 115 | break; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ( Recurring::FIRST === $recurring_type ) { |
|
| 119 | - foreach ( $result as $method => $title ) { |
|
| 120 | - unset( $result[ $method ] ); |
|
| 118 | + if (Recurring::FIRST === $recurring_type) { |
|
| 119 | + foreach ($result as $method => $title) { |
|
| 120 | + unset($result[$method]); |
|
| 121 | 121 | |
| 122 | 122 | // Get WordPress payment method for direct debit method. |
| 123 | - $method = Methods::transform_gateway_method( $method ); |
|
| 124 | - $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); |
|
| 123 | + $method = Methods::transform_gateway_method($method); |
|
| 124 | + $payment_method = array_search($method, PaymentMethods::get_recurring_methods(), true); |
|
| 125 | 125 | |
| 126 | - if ( $payment_method ) { |
|
| 127 | - $results[ $payment_method ] = $title; |
|
| 126 | + if ($payment_method) { |
|
| 127 | + $results[$payment_method] = $title; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $results = array_merge( $results, $result ); |
|
| 132 | + $results = array_merge($results, $result); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Transform to WordPress payment methods. |
| 136 | - foreach ( $results as $method => $title ) { |
|
| 137 | - if ( PaymentMethods::is_recurring_method( $method ) ) { |
|
| 136 | + foreach ($results as $method => $title) { |
|
| 137 | + if (PaymentMethods::is_recurring_method($method)) { |
|
| 138 | 138 | $payment_method = $method; |
| 139 | 139 | } else { |
| 140 | - $payment_method = Methods::transform_gateway_method( $method ); |
|
| 140 | + $payment_method = Methods::transform_gateway_method($method); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if ( $payment_method ) { |
|
| 143 | + if ($payment_method) { |
|
| 144 | 144 | $payment_methods[] = $payment_method; |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $payment_methods = array_unique( $payment_methods ); |
|
| 148 | + $payment_methods = array_unique($payment_methods); |
|
| 149 | 149 | |
| 150 | 150 | return $payment_methods; |
| 151 | 151 | } |
@@ -179,22 +179,22 @@ discard block |
||
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | 181 | public function get_webhook_url() { |
| 182 | - $url = home_url( '/' ); |
|
| 182 | + $url = home_url('/'); |
|
| 183 | 183 | |
| 184 | - $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
| 184 | + $host = wp_parse_url($url, PHP_URL_HOST); |
|
| 185 | 185 | |
| 186 | - if ( 'localhost' === $host ) { |
|
| 186 | + if ('localhost' === $host) { |
|
| 187 | 187 | // Mollie doesn't allow localhost. |
| 188 | 188 | return null; |
| 189 | - } elseif ( '.dev' === substr( $host, -4 ) ) { |
|
| 189 | + } elseif ('.dev' === substr($host, -4)) { |
|
| 190 | 190 | // Mollie doesn't allow the .dev TLD. |
| 191 | 191 | return null; |
| 192 | - } elseif ( '.local' === substr( $host, -6 ) ) { |
|
| 192 | + } elseif ('.local' === substr($host, -6)) { |
|
| 193 | 193 | // Mollie doesn't allow the .local TLD. |
| 194 | 194 | return null; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $url = add_query_arg( 'mollie_webhook', '', $url ); |
|
| 197 | + $url = add_query_arg('mollie_webhook', '', $url); |
|
| 198 | 198 | |
| 199 | 199 | return $url; |
| 200 | 200 | } |
@@ -204,19 +204,19 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @see Pronamic_WP_Pay_Gateway::start() |
| 206 | 206 | */ |
| 207 | - public function start( Payment $payment ) { |
|
| 207 | + public function start(Payment $payment) { |
|
| 208 | 208 | $request = new PaymentRequest(); |
| 209 | 209 | |
| 210 | 210 | $request->amount = $payment->get_amount()->get_amount(); |
| 211 | 211 | $request->description = $payment->get_description(); |
| 212 | 212 | $request->redirect_url = $payment->get_return_url(); |
| 213 | 213 | $request->webhook_url = $this->get_webhook_url(); |
| 214 | - $request->locale = LocaleHelper::transform( $payment->get_language() ); |
|
| 214 | + $request->locale = LocaleHelper::transform($payment->get_language()); |
|
| 215 | 215 | |
| 216 | 216 | // Customer ID. |
| 217 | - $customer_id = $this->get_customer_id_for_payment( $payment ); |
|
| 217 | + $customer_id = $this->get_customer_id_for_payment($payment); |
|
| 218 | 218 | |
| 219 | - if ( ! empty( $customer_id ) ) { |
|
| 219 | + if ( ! empty($customer_id)) { |
|
| 220 | 220 | $request->customer_id = $customer_id; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -226,49 +226,49 @@ discard block |
||
| 226 | 226 | // Subscription. |
| 227 | 227 | $subscription = $payment->get_subscription(); |
| 228 | 228 | |
| 229 | - if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { |
|
| 229 | + if ($subscription && PaymentMethods::is_recurring_method($payment_method)) { |
|
| 230 | 230 | $request->recurring_type = $payment->get_recurring() ? Recurring::RECURRING : Recurring::FIRST; |
| 231 | 231 | |
| 232 | - if ( Recurring::FIRST === $request->recurring_type ) { |
|
| 233 | - $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); |
|
| 232 | + if (Recurring::FIRST === $request->recurring_type) { |
|
| 233 | + $payment_method = PaymentMethods::get_first_payment_method($payment_method); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if ( Recurring::RECURRING === $request->recurring_type ) { |
|
| 237 | - $payment->set_action_url( $payment->get_return_url() ); |
|
| 236 | + if (Recurring::RECURRING === $request->recurring_type) { |
|
| 237 | + $payment->set_action_url($payment->get_return_url()); |
|
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? |
| 242 | - $request->method = Methods::transform( $payment_method, $payment_method ); |
|
| 242 | + $request->method = Methods::transform($payment_method, $payment_method); |
|
| 243 | 243 | |
| 244 | 244 | // Issuer. |
| 245 | - if ( Methods::IDEAL === $request->method ) { |
|
| 245 | + if (Methods::IDEAL === $request->method) { |
|
| 246 | 246 | // If payment method is iDEAL we set the user chosen issuer ID. |
| 247 | 247 | $request->issuer = $payment->get_issuer(); |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | // Create payment. |
| 251 | - $result = $this->client->create_payment( $request ); |
|
| 251 | + $result = $this->client->create_payment($request); |
|
| 252 | 252 | |
| 253 | - if ( ! $result ) { |
|
| 253 | + if ( ! $result) { |
|
| 254 | 254 | $this->error = $this->client->get_error(); |
| 255 | 255 | |
| 256 | 256 | return false; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Set transaction ID. |
| 260 | - if ( isset( $result->id ) ) { |
|
| 261 | - $payment->set_transaction_id( $result->id ); |
|
| 260 | + if (isset($result->id)) { |
|
| 261 | + $payment->set_transaction_id($result->id); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Set status |
| 265 | - if ( isset( $result->status ) ) { |
|
| 266 | - $payment->set_status( Statuses::transform( $result->status ) ); |
|
| 265 | + if (isset($result->status)) { |
|
| 266 | + $payment->set_status(Statuses::transform($result->status)); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Set action URL. |
| 270 | - if ( isset( $result->links, $result->links->paymentUrl ) ) { |
|
| 271 | - $payment->set_action_url( $result->links->paymentUrl ); |
|
| 270 | + if (isset($result->links, $result->links->paymentUrl)) { |
|
| 271 | + $payment->set_action_url($result->links->paymentUrl); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
@@ -277,36 +277,36 @@ discard block |
||
| 277 | 277 | * |
| 278 | 278 | * @param Payment $payment |
| 279 | 279 | */ |
| 280 | - public function update_status( Payment $payment ) { |
|
| 281 | - $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); |
|
| 280 | + public function update_status(Payment $payment) { |
|
| 281 | + $mollie_payment = $this->client->get_payment($payment->get_transaction_id()); |
|
| 282 | 282 | |
| 283 | - if ( ! $mollie_payment ) { |
|
| 284 | - $payment->set_status( Core_Statuses::FAILURE ); |
|
| 283 | + if ( ! $mollie_payment) { |
|
| 284 | + $payment->set_status(Core_Statuses::FAILURE); |
|
| 285 | 285 | |
| 286 | 286 | $this->error = $this->client->get_error(); |
| 287 | 287 | |
| 288 | 288 | return; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $payment->set_status( Statuses::transform( $mollie_payment->status ) ); |
|
| 291 | + $payment->set_status(Statuses::transform($mollie_payment->status)); |
|
| 292 | 292 | |
| 293 | - if ( isset( $mollie_payment->details ) ) { |
|
| 293 | + if (isset($mollie_payment->details)) { |
|
| 294 | 294 | $details = $mollie_payment->details; |
| 295 | 295 | |
| 296 | - if ( isset( $details->consumerName ) ) { |
|
| 297 | - $payment->set_consumer_name( $details->consumerName ); |
|
| 296 | + if (isset($details->consumerName)) { |
|
| 297 | + $payment->set_consumer_name($details->consumerName); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( isset( $details->cardHolder ) ) { |
|
| 301 | - $payment->set_consumer_name( $details->cardHolder ); |
|
| 300 | + if (isset($details->cardHolder)) { |
|
| 301 | + $payment->set_consumer_name($details->cardHolder); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( isset( $details->consumerAccount ) ) { |
|
| 305 | - $payment->set_consumer_iban( $details->consumerAccount ); |
|
| 304 | + if (isset($details->consumerAccount)) { |
|
| 305 | + $payment->set_consumer_iban($details->consumerAccount); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if ( isset( $details->consumerBic ) ) { |
|
| 309 | - $payment->set_consumer_bic( $details->consumerBic ); |
|
| 308 | + if (isset($details->consumerBic)) { |
|
| 309 | + $payment->set_consumer_bic($details->consumerBic); |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -318,42 +318,42 @@ discard block |
||
| 318 | 318 | * |
| 319 | 319 | * @return bool|string |
| 320 | 320 | */ |
| 321 | - public function get_customer_id_for_payment( Payment $payment ) { |
|
| 321 | + public function get_customer_id_for_payment(Payment $payment) { |
|
| 322 | 322 | // Get Mollie customer ID from user meta. |
| 323 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 323 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 324 | 324 | |
| 325 | 325 | $subscription = $payment->get_subscription(); |
| 326 | 326 | |
| 327 | 327 | // Get customer ID from subscription meta. |
| 328 | - if ( $subscription ) { |
|
| 329 | - $subscription_customer_id = $subscription->get_meta( 'mollie_customer_id' ); |
|
| 328 | + if ($subscription) { |
|
| 329 | + $subscription_customer_id = $subscription->get_meta('mollie_customer_id'); |
|
| 330 | 330 | |
| 331 | 331 | // Try to get (legacy) customer ID from first payment. |
| 332 | - if ( empty( $subscription_customer_id ) && $subscription->get_first_payment() ) { |
|
| 332 | + if (empty($subscription_customer_id) && $subscription->get_first_payment()) { |
|
| 333 | 333 | $first_payment = $subscription->get_first_payment(); |
| 334 | 334 | |
| 335 | - $subscription_customer_id = $first_payment->get_meta( 'mollie_customer_id' ); |
|
| 335 | + $subscription_customer_id = $first_payment->get_meta('mollie_customer_id'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( ! empty( $subscription_customer_id ) ) { |
|
| 338 | + if ( ! empty($subscription_customer_id)) { |
|
| 339 | 339 | $customer_id = $subscription_customer_id; |
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // Create new customer if the customer does not exist at Mollie. |
| 344 | - if ( ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) && Core_Recurring::RECURRING !== $payment->recurring_type ) { |
|
| 345 | - $customer_id = $this->client->create_customer( $payment->get_email(), $payment->get_customer_name() ); |
|
| 344 | + if ((empty($customer_id) || ! $this->client->get_customer($customer_id)) && Core_Recurring::RECURRING !== $payment->recurring_type) { |
|
| 345 | + $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name()); |
|
| 346 | 346 | |
| 347 | - $this->update_wp_user_customer_id( $payment->user_id, $customer_id ); |
|
| 347 | + $this->update_wp_user_customer_id($payment->user_id, $customer_id); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | // Store customer ID in subscription meta. |
| 351 | - if ( $subscription && empty( $subscription_customer_id ) && ! empty( $customer_id ) ) { |
|
| 352 | - $subscription->set_meta( 'mollie_customer_id', $customer_id ); |
|
| 351 | + if ($subscription && empty($subscription_customer_id) && ! empty($customer_id)) { |
|
| 352 | + $subscription->set_meta('mollie_customer_id', $customer_id); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | // Copy customer ID from subscription to user meta. |
| 356 | - $this->copy_customer_id_to_wp_user( $payment ); |
|
| 356 | + $this->copy_customer_id_to_wp_user($payment); |
|
| 357 | 357 | |
| 358 | 358 | return $customer_id; |
| 359 | 359 | } |
@@ -365,12 +365,12 @@ discard block |
||
| 365 | 365 | * |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function get_customer_id_by_wp_user_id( $user_id ) { |
|
| 369 | - if ( empty( $user_id ) ) { |
|
| 368 | + public function get_customer_id_by_wp_user_id($user_id) { |
|
| 369 | + if (empty($user_id)) { |
|
| 370 | 370 | return false; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - return get_user_meta( $user_id, $this->meta_key_customer_id, true ); |
|
| 373 | + return get_user_meta($user_id, $this->meta_key_customer_id, true); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -381,16 +381,16 @@ discard block |
||
| 381 | 381 | * |
| 382 | 382 | * @return bool |
| 383 | 383 | */ |
| 384 | - private function update_wp_user_customer_id( $user_id, $customer_id ) { |
|
| 385 | - if ( empty( $user_id ) || is_bool( $user_id ) ) { |
|
| 384 | + private function update_wp_user_customer_id($user_id, $customer_id) { |
|
| 385 | + if (empty($user_id) || is_bool($user_id)) { |
|
| 386 | 386 | return false; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - if ( ! is_string( $customer_id ) || empty( $customer_id ) || 1 === strlen( $customer_id ) ) { |
|
| 389 | + if ( ! is_string($customer_id) || empty($customer_id) || 1 === strlen($customer_id)) { |
|
| 390 | 390 | return false; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id ); |
|
| 393 | + update_user_meta($user_id, $this->meta_key_customer_id, $customer_id); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,25 +400,25 @@ discard block |
||
| 400 | 400 | * |
| 401 | 401 | * @return void |
| 402 | 402 | */ |
| 403 | - public function copy_customer_id_to_wp_user( Payment $payment ) { |
|
| 404 | - if ( $this->config->id !== $payment->config_id ) { |
|
| 403 | + public function copy_customer_id_to_wp_user(Payment $payment) { |
|
| 404 | + if ($this->config->id !== $payment->config_id) { |
|
| 405 | 405 | return; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | $subscription = $payment->get_subscription(); |
| 409 | 409 | |
| 410 | - if ( ! $subscription || empty( $subscription->user_id ) ) { |
|
| 410 | + if ( ! $subscription || empty($subscription->user_id)) { |
|
| 411 | 411 | return; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | // Get customer ID from subscription meta. |
| 415 | - $customer_id = $subscription->get_meta( 'mollie_customer_id' ); |
|
| 415 | + $customer_id = $subscription->get_meta('mollie_customer_id'); |
|
| 416 | 416 | |
| 417 | - $user_customer_id = $this->get_customer_id_by_wp_user_id( $subscription->user_id ); |
|
| 417 | + $user_customer_id = $this->get_customer_id_by_wp_user_id($subscription->user_id); |
|
| 418 | 418 | |
| 419 | - if ( empty( $user_customer_id ) ) { |
|
| 419 | + if (empty($user_customer_id)) { |
|
| 420 | 420 | // Set customer ID as user meta. |
| 421 | - $this->update_wp_user_customer_id( $subscription->user_id, $customer_id ); |
|
| 421 | + $this->update_wp_user_customer_id($subscription->user_id, $customer_id); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | } |