@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param Config $config |
| 40 | 40 | */ |
| 41 | - public function __construct( Config $config ) { |
|
| 42 | - parent::__construct( $config ); |
|
| 41 | + public function __construct(Config $config) { |
|
| 42 | + parent::__construct($config); |
|
| 43 | 43 | |
| 44 | 44 | $this->supports = array( |
| 45 | 45 | 'payment_status_request', |
@@ -48,20 +48,20 @@ discard block |
||
| 48 | 48 | 'recurring', |
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | - $this->set_method( Core_Gateway::METHOD_HTTP_REDIRECT ); |
|
| 52 | - $this->set_has_feedback( true ); |
|
| 53 | - $this->set_amount_minimum( 1.20 ); |
|
| 54 | - $this->set_slug( self::SLUG ); |
|
| 51 | + $this->set_method(Core_Gateway::METHOD_HTTP_REDIRECT); |
|
| 52 | + $this->set_has_feedback(true); |
|
| 53 | + $this->set_amount_minimum(1.20); |
|
| 54 | + $this->set_slug(self::SLUG); |
|
| 55 | 55 | |
| 56 | - $this->client = new Client( $config->api_key ); |
|
| 57 | - $this->client->set_mode( $config->mode ); |
|
| 56 | + $this->client = new Client($config->api_key); |
|
| 57 | + $this->client->set_mode($config->mode); |
|
| 58 | 58 | |
| 59 | - if ( 'test' === $config->mode ) { |
|
| 59 | + if ('test' === $config->mode) { |
|
| 60 | 60 | $this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test'; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Actions. |
| 64 | - add_action( 'pronamic_payment_status_update', array( $this, 'move_customer_id_to_wp_user' ), 99, 1 ); |
|
| 64 | + add_action('pronamic_payment_status_update', array($this, 'move_customer_id_to_wp_user'), 99, 1); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $result = $this->client->get_issuers(); |
| 76 | 76 | |
| 77 | - if ( ! $result ) { |
|
| 77 | + if ( ! $result) { |
|
| 78 | 78 | $this->error = $this->client->get_error(); |
| 79 | 79 | |
| 80 | 80 | return $groups; |
@@ -96,51 +96,51 @@ discard block |
||
| 96 | 96 | $payment_methods = array(); |
| 97 | 97 | |
| 98 | 98 | // Set recurring types to get payment methods for. |
| 99 | - $recurring_types = array( null, Recurring::RECURRING, Recurring::FIRST ); |
|
| 99 | + $recurring_types = array(null, Recurring::RECURRING, Recurring::FIRST); |
|
| 100 | 100 | |
| 101 | 101 | $results = array(); |
| 102 | 102 | |
| 103 | - foreach ( $recurring_types as $recurring_type ) { |
|
| 103 | + foreach ($recurring_types as $recurring_type) { |
|
| 104 | 104 | // Get active payment methods for Mollie account. |
| 105 | - $result = $this->client->get_payment_methods( $recurring_type ); |
|
| 105 | + $result = $this->client->get_payment_methods($recurring_type); |
|
| 106 | 106 | |
| 107 | - if ( ! $result ) { |
|
| 107 | + if ( ! $result) { |
|
| 108 | 108 | $this->error = $this->client->get_error(); |
| 109 | 109 | |
| 110 | 110 | break; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ( Recurring::FIRST === $recurring_type ) { |
|
| 114 | - foreach ( $result as $method => $title ) { |
|
| 115 | - unset( $result[ $method ] ); |
|
| 113 | + if (Recurring::FIRST === $recurring_type) { |
|
| 114 | + foreach ($result as $method => $title) { |
|
| 115 | + unset($result[$method]); |
|
| 116 | 116 | |
| 117 | 117 | // Get WordPress payment method for direct debit method. |
| 118 | - $method = Methods::transform_gateway_method( $method ); |
|
| 119 | - $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); |
|
| 118 | + $method = Methods::transform_gateway_method($method); |
|
| 119 | + $payment_method = array_search($method, PaymentMethods::get_recurring_methods(), true); |
|
| 120 | 120 | |
| 121 | - if ( $payment_method ) { |
|
| 122 | - $results[ $payment_method ] = $title; |
|
| 121 | + if ($payment_method) { |
|
| 122 | + $results[$payment_method] = $title; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $results = array_merge( $results, $result ); |
|
| 127 | + $results = array_merge($results, $result); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Transform to WordPress payment methods. |
| 131 | - foreach ( $results as $method => $title ) { |
|
| 132 | - if ( PaymentMethods::is_recurring_method( $method ) ) { |
|
| 131 | + foreach ($results as $method => $title) { |
|
| 132 | + if (PaymentMethods::is_recurring_method($method)) { |
|
| 133 | 133 | $payment_method = $method; |
| 134 | 134 | } else { |
| 135 | - $payment_method = Methods::transform_gateway_method( $method ); |
|
| 135 | + $payment_method = Methods::transform_gateway_method($method); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if ( $payment_method ) { |
|
| 138 | + if ($payment_method) { |
|
| 139 | 139 | $payment_methods[] = $payment_method; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $payment_methods = array_unique( $payment_methods ); |
|
| 143 | + $payment_methods = array_unique($payment_methods); |
|
| 144 | 144 | |
| 145 | 145 | return $payment_methods; |
| 146 | 146 | } |
@@ -174,19 +174,19 @@ discard block |
||
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | 176 | private function get_webhook_url() { |
| 177 | - $url = home_url( '/' ); |
|
| 177 | + $url = home_url('/'); |
|
| 178 | 178 | |
| 179 | - $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
| 179 | + $host = wp_parse_url($url, PHP_URL_HOST); |
|
| 180 | 180 | |
| 181 | - if ( 'localhost' === $host ) { |
|
| 181 | + if ('localhost' === $host) { |
|
| 182 | 182 | // Mollie doesn't allow localhost |
| 183 | 183 | return null; |
| 184 | - } elseif ( '.dev' === substr( $host, -4 ) ) { |
|
| 184 | + } elseif ('.dev' === substr($host, -4)) { |
|
| 185 | 185 | // Mollie doesn't allow the TLD .dev |
| 186 | 186 | return null; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - $url = add_query_arg( 'mollie_webhook', '', $url ); |
|
| 189 | + $url = add_query_arg('mollie_webhook', '', $url); |
|
| 190 | 190 | |
| 191 | 191 | return $url; |
| 192 | 192 | } |
@@ -196,19 +196,19 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @see Pronamic_WP_Pay_Gateway::start() |
| 198 | 198 | */ |
| 199 | - public function start( Payment $payment ) { |
|
| 199 | + public function start(Payment $payment) { |
|
| 200 | 200 | $request = new PaymentRequest(); |
| 201 | 201 | |
| 202 | 202 | $request->amount = $payment->get_amount()->get_amount(); |
| 203 | 203 | $request->description = $payment->get_description(); |
| 204 | 204 | $request->redirect_url = $payment->get_return_url(); |
| 205 | 205 | $request->webhook_url = $this->get_webhook_url(); |
| 206 | - $request->locale = LocaleHelper::transform( $payment->get_language() ); |
|
| 206 | + $request->locale = LocaleHelper::transform($payment->get_language()); |
|
| 207 | 207 | |
| 208 | 208 | // Customer ID. |
| 209 | - $customer_id = $this->get_customer_id_for_payment( $payment ); |
|
| 209 | + $customer_id = $this->get_customer_id_for_payment($payment); |
|
| 210 | 210 | |
| 211 | - if ( ! empty( $customer_id ) ) { |
|
| 211 | + if ( ! empty($customer_id)) { |
|
| 212 | 212 | $request->customer_id = $customer_id; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -218,49 +218,49 @@ discard block |
||
| 218 | 218 | // Subscription. |
| 219 | 219 | $subscription = $payment->get_subscription(); |
| 220 | 220 | |
| 221 | - if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { |
|
| 221 | + if ($subscription && PaymentMethods::is_recurring_method($payment_method)) { |
|
| 222 | 222 | $request->recurring_type = $payment->get_recurring() ? Recurring::RECURRING : Recurring::FIRST; |
| 223 | 223 | |
| 224 | - if ( Recurring::FIRST === $request->recurring_type ) { |
|
| 225 | - $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); |
|
| 224 | + if (Recurring::FIRST === $request->recurring_type) { |
|
| 225 | + $payment_method = PaymentMethods::get_first_payment_method($payment_method); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( Recurring::RECURRING === $request->recurring_type ) { |
|
| 229 | - $payment->set_action_url( $payment->get_return_url() ); |
|
| 228 | + if (Recurring::RECURRING === $request->recurring_type) { |
|
| 229 | + $payment->set_action_url($payment->get_return_url()); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? |
| 234 | - $request->method = Methods::transform( $payment_method, $payment_method ); |
|
| 234 | + $request->method = Methods::transform($payment_method, $payment_method); |
|
| 235 | 235 | |
| 236 | 236 | // Issuer. |
| 237 | - if ( Methods::IDEAL === $request->method ) { |
|
| 237 | + if (Methods::IDEAL === $request->method) { |
|
| 238 | 238 | // If payment method is iDEAL we set the user chosen issuer ID. |
| 239 | 239 | $request->issuer = $payment->get_issuer(); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Create payment. |
| 243 | - $result = $this->client->create_payment( $request ); |
|
| 243 | + $result = $this->client->create_payment($request); |
|
| 244 | 244 | |
| 245 | - if ( ! $result ) { |
|
| 245 | + if ( ! $result) { |
|
| 246 | 246 | $this->error = $this->client->get_error(); |
| 247 | 247 | |
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // Set transaction ID. |
| 252 | - if ( isset( $result->id ) ) { |
|
| 253 | - $payment->set_transaction_id( $result->id ); |
|
| 252 | + if (isset($result->id)) { |
|
| 253 | + $payment->set_transaction_id($result->id); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // Set status |
| 257 | - if ( isset( $result->status ) ) { |
|
| 258 | - $payment->set_status( Statuses::transform( $result->status ) ); |
|
| 257 | + if (isset($result->status)) { |
|
| 258 | + $payment->set_status(Statuses::transform($result->status)); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Set action URL. |
| 262 | - if ( isset( $result->links, $result->links->paymentUrl ) ) { |
|
| 263 | - $payment->set_action_url( $result->links->paymentUrl ); |
|
| 262 | + if (isset($result->links, $result->links->paymentUrl)) { |
|
| 263 | + $payment->set_action_url($result->links->paymentUrl); |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
@@ -269,36 +269,36 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @param Payment $payment |
| 271 | 271 | */ |
| 272 | - public function update_status( Payment $payment ) { |
|
| 273 | - $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); |
|
| 272 | + public function update_status(Payment $payment) { |
|
| 273 | + $mollie_payment = $this->client->get_payment($payment->get_transaction_id()); |
|
| 274 | 274 | |
| 275 | - if ( ! $mollie_payment ) { |
|
| 276 | - $payment->set_status( Core_Statuses::FAILURE ); |
|
| 275 | + if ( ! $mollie_payment) { |
|
| 276 | + $payment->set_status(Core_Statuses::FAILURE); |
|
| 277 | 277 | |
| 278 | 278 | $this->error = $this->client->get_error(); |
| 279 | 279 | |
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $payment->set_status( Statuses::transform( $mollie_payment->status ) ); |
|
| 283 | + $payment->set_status(Statuses::transform($mollie_payment->status)); |
|
| 284 | 284 | |
| 285 | - if ( isset( $mollie_payment->details ) ) { |
|
| 285 | + if (isset($mollie_payment->details)) { |
|
| 286 | 286 | $details = $mollie_payment->details; |
| 287 | 287 | |
| 288 | - if ( isset( $details->consumerName ) ) { |
|
| 289 | - $payment->set_consumer_name( $details->consumerName ); |
|
| 288 | + if (isset($details->consumerName)) { |
|
| 289 | + $payment->set_consumer_name($details->consumerName); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if ( isset( $details->cardHolder ) ) { |
|
| 293 | - $payment->set_consumer_name( $details->cardHolder ); |
|
| 292 | + if (isset($details->cardHolder)) { |
|
| 293 | + $payment->set_consumer_name($details->cardHolder); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( isset( $details->consumerAccount ) ) { |
|
| 297 | - $payment->set_consumer_iban( $details->consumerAccount ); |
|
| 296 | + if (isset($details->consumerAccount)) { |
|
| 297 | + $payment->set_consumer_iban($details->consumerAccount); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( isset( $details->consumerBic ) ) { |
|
| 301 | - $payment->set_consumer_bic( $details->consumerBic ); |
|
| 300 | + if (isset($details->consumerBic)) { |
|
| 301 | + $payment->set_consumer_bic($details->consumerBic); |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | } |
@@ -310,40 +310,40 @@ discard block |
||
| 310 | 310 | * |
| 311 | 311 | * @return bool|string |
| 312 | 312 | */ |
| 313 | - private function get_customer_id_for_payment( Payment $payment ) { |
|
| 313 | + private function get_customer_id_for_payment(Payment $payment) { |
|
| 314 | 314 | // Get Mollie customer ID from user meta. |
| 315 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 315 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 316 | 316 | |
| 317 | - if ( Core_Recurring::FIRST === $payment->recurring_type ) { |
|
| 317 | + if (Core_Recurring::FIRST === $payment->recurring_type) { |
|
| 318 | 318 | // Create new customer if the customer does not exist at Mollie. |
| 319 | - if ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) { |
|
| 320 | - $customer_id = $this->client->create_customer( $payment->get_email(), $payment->get_customer_name() ); |
|
| 319 | + if (empty($customer_id) || ! $this->client->get_customer($customer_id)) { |
|
| 320 | + $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name()); |
|
| 321 | 321 | |
| 322 | - $this->update_wp_user_customer_id( $payment->user_id, $customer_id ); |
|
| 322 | + $this->update_wp_user_customer_id($payment->user_id, $customer_id); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // Temporarily store customer ID in subscription meta for guest users. |
| 326 | - if ( empty( $payment->user_id ) && ! empty( $customer_id ) ) { |
|
| 326 | + if (empty($payment->user_id) && ! empty($customer_id)) { |
|
| 327 | 327 | $subscription = $payment->get_subscription(); |
| 328 | 328 | |
| 329 | - if ( $subscription ) { |
|
| 330 | - $subscription->set_meta( 'mollie_customer_id', $customer_id ); |
|
| 329 | + if ($subscription) { |
|
| 330 | + $subscription->set_meta('mollie_customer_id', $customer_id); |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // Try to move customer ID from subscription meta to user. |
| 336 | - if ( empty( $customer_id ) ) { |
|
| 336 | + if (empty($customer_id)) { |
|
| 337 | 337 | // Move customer ID from subscription meta to user meta. |
| 338 | - $this->move_customer_id_to_wp_user( $payment ); |
|
| 338 | + $this->move_customer_id_to_wp_user($payment); |
|
| 339 | 339 | |
| 340 | 340 | // Get customer ID from user meta, again. |
| 341 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 341 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // Try to get customer ID from subscription meta. |
| 345 | - if ( empty( $customer_id ) && $payment->get_subscription() ) { |
|
| 346 | - $customer_id = $payment->get_subscription()->get_meta( 'mollie_customer_id' ); |
|
| 345 | + if (empty($customer_id) && $payment->get_subscription()) { |
|
| 346 | + $customer_id = $payment->get_subscription()->get_meta('mollie_customer_id'); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | return $customer_id; |
@@ -356,12 +356,12 @@ discard block |
||
| 356 | 356 | * |
| 357 | 357 | * @return string |
| 358 | 358 | */ |
| 359 | - private function get_customer_id_by_wp_user_id( $user_id ) { |
|
| 360 | - if ( empty( $user_id ) ) { |
|
| 359 | + private function get_customer_id_by_wp_user_id($user_id) { |
|
| 360 | + if (empty($user_id)) { |
|
| 361 | 361 | return false; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - return get_user_meta( $user_id, $this->meta_key_customer_id, true ); |
|
| 364 | + return get_user_meta($user_id, $this->meta_key_customer_id, true); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | * |
| 373 | 373 | * @return bool |
| 374 | 374 | */ |
| 375 | - private function update_wp_user_customer_id( $user_id, $customer_id ) { |
|
| 376 | - if ( empty( $user_id ) || empty( $customer_id ) ) { |
|
| 375 | + private function update_wp_user_customer_id($user_id, $customer_id) { |
|
| 376 | + if (empty($user_id) || empty($customer_id)) { |
|
| 377 | 377 | return false; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id ); |
|
| 380 | + update_user_meta($user_id, $this->meta_key_customer_id, $customer_id); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -387,26 +387,26 @@ discard block |
||
| 387 | 387 | * |
| 388 | 388 | * @return void |
| 389 | 389 | */ |
| 390 | - public function move_customer_id_to_wp_user( Payment $payment ) { |
|
| 391 | - if ( $this->config->id !== $payment->config_id ) { |
|
| 390 | + public function move_customer_id_to_wp_user(Payment $payment) { |
|
| 391 | + if ($this->config->id !== $payment->config_id) { |
|
| 392 | 392 | return; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | $subscription = $payment->get_subscription(); |
| 396 | 396 | |
| 397 | - if ( ! $subscription || empty( $subscription->user_id ) ) { |
|
| 397 | + if ( ! $subscription || empty($subscription->user_id)) { |
|
| 398 | 398 | return; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | // Get customer ID from subscription meta. |
| 402 | - $customer_id = $subscription->get_meta( 'mollie_customer_id' ); |
|
| 402 | + $customer_id = $subscription->get_meta('mollie_customer_id'); |
|
| 403 | 403 | |
| 404 | - if ( ! empty( $customer_id ) && ! empty( $subscription->user_id ) ) { |
|
| 404 | + if ( ! empty($customer_id) && ! empty($subscription->user_id)) { |
|
| 405 | 405 | // Set customer ID as user meta. |
| 406 | - $this->update_wp_user_customer_id( $subscription->user_id, $customer_id ); |
|
| 406 | + $this->update_wp_user_customer_id($subscription->user_id, $customer_id); |
|
| 407 | 407 | |
| 408 | 408 | // Delete customer ID from subscription meta. |
| 409 | - $subscription->set_meta( 'mollie_customer_id', null ); |
|
| 409 | + $subscription->set_meta('mollie_customer_id', null); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | } |