@@ -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; |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function get_issuer_field() { |
| 91 | - if ( PaymentMethods::IDEAL === $this->get_payment_method() ) { |
|
| 91 | + if (PaymentMethods::IDEAL === $this->get_payment_method()) { |
|
| 92 | 92 | return array( |
| 93 | 93 | 'id' => 'pronamic_ideal_issuer_id', |
| 94 | 94 | 'name' => 'pronamic_ideal_issuer_id', |
| 95 | - 'label' => __( 'Choose your bank', 'pronamic_ideal' ), |
|
| 95 | + 'label' => __('Choose your bank', 'pronamic_ideal'), |
|
| 96 | 96 | 'required' => true, |
| 97 | 97 | 'type' => 'select', |
| 98 | 98 | 'choices' => $this->get_transient_issuers(), |
@@ -109,51 +109,51 @@ discard block |
||
| 109 | 109 | $payment_methods = array(); |
| 110 | 110 | |
| 111 | 111 | // Set recurring types to get payment methods for. |
| 112 | - $recurring_types = array( null, Recurring::RECURRING, Recurring::FIRST ); |
|
| 112 | + $recurring_types = array(null, Recurring::RECURRING, Recurring::FIRST); |
|
| 113 | 113 | |
| 114 | 114 | $results = array(); |
| 115 | 115 | |
| 116 | - foreach ( $recurring_types as $recurring_type ) { |
|
| 116 | + foreach ($recurring_types as $recurring_type) { |
|
| 117 | 117 | // Get active payment methods for Mollie account. |
| 118 | - $result = $this->client->get_payment_methods( $recurring_type ); |
|
| 118 | + $result = $this->client->get_payment_methods($recurring_type); |
|
| 119 | 119 | |
| 120 | - if ( ! $result ) { |
|
| 120 | + if ( ! $result) { |
|
| 121 | 121 | $this->error = $this->client->get_error(); |
| 122 | 122 | |
| 123 | 123 | break; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( Recurring::FIRST === $recurring_type ) { |
|
| 127 | - foreach ( $result as $method => $title ) { |
|
| 128 | - unset( $result[ $method ] ); |
|
| 126 | + if (Recurring::FIRST === $recurring_type) { |
|
| 127 | + foreach ($result as $method => $title) { |
|
| 128 | + unset($result[$method]); |
|
| 129 | 129 | |
| 130 | 130 | // Get WordPress payment method for direct debit method. |
| 131 | - $method = Methods::transform_gateway_method( $method ); |
|
| 132 | - $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); |
|
| 131 | + $method = Methods::transform_gateway_method($method); |
|
| 132 | + $payment_method = array_search($method, PaymentMethods::get_recurring_methods(), true); |
|
| 133 | 133 | |
| 134 | - if ( $payment_method ) { |
|
| 135 | - $results[ $payment_method ] = $title; |
|
| 134 | + if ($payment_method) { |
|
| 135 | + $results[$payment_method] = $title; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $results = array_merge( $results, $result ); |
|
| 140 | + $results = array_merge($results, $result); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // Transform to WordPress payment methods. |
| 144 | - foreach ( $results as $method => $title ) { |
|
| 145 | - if ( PaymentMethods::is_recurring_method( $method ) ) { |
|
| 144 | + foreach ($results as $method => $title) { |
|
| 145 | + if (PaymentMethods::is_recurring_method($method)) { |
|
| 146 | 146 | $payment_method = $method; |
| 147 | 147 | } else { |
| 148 | - $payment_method = Methods::transform_gateway_method( $method ); |
|
| 148 | + $payment_method = Methods::transform_gateway_method($method); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ( $payment_method ) { |
|
| 151 | + if ($payment_method) { |
|
| 152 | 152 | $payment_methods[] = $payment_method; |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $payment_methods = array_unique( $payment_methods ); |
|
| 156 | + $payment_methods = array_unique($payment_methods); |
|
| 157 | 157 | |
| 158 | 158 | return $payment_methods; |
| 159 | 159 | } |
@@ -187,19 +187,19 @@ discard block |
||
| 187 | 187 | * @return string |
| 188 | 188 | */ |
| 189 | 189 | private function get_webhook_url() { |
| 190 | - $url = home_url( '/' ); |
|
| 190 | + $url = home_url('/'); |
|
| 191 | 191 | |
| 192 | - $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
| 192 | + $host = wp_parse_url($url, PHP_URL_HOST); |
|
| 193 | 193 | |
| 194 | - if ( 'localhost' === $host ) { |
|
| 194 | + if ('localhost' === $host) { |
|
| 195 | 195 | // Mollie doesn't allow localhost |
| 196 | 196 | return null; |
| 197 | - } elseif ( '.dev' === substr( $host, -4 ) ) { |
|
| 197 | + } elseif ('.dev' === substr($host, -4)) { |
|
| 198 | 198 | // Mollie doesn't allow the TLD .dev |
| 199 | 199 | return null; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - $url = add_query_arg( 'mollie_webhook', '', $url ); |
|
| 202 | + $url = add_query_arg('mollie_webhook', '', $url); |
|
| 203 | 203 | |
| 204 | 204 | return $url; |
| 205 | 205 | } |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @see Pronamic_WP_Pay_Gateway::start() |
| 211 | 211 | */ |
| 212 | - public function start( Payment $payment ) { |
|
| 212 | + public function start(Payment $payment) { |
|
| 213 | 213 | $request = new PaymentRequest(); |
| 214 | 214 | |
| 215 | 215 | $request->amount = $payment->get_amount()->get_amount(); |
| 216 | 216 | $request->description = $payment->get_description(); |
| 217 | 217 | $request->redirect_url = $payment->get_return_url(); |
| 218 | 218 | $request->webhook_url = $this->get_webhook_url(); |
| 219 | - $request->locale = LocaleHelper::transform( $payment->get_language() ); |
|
| 219 | + $request->locale = LocaleHelper::transform($payment->get_language()); |
|
| 220 | 220 | |
| 221 | 221 | // Issuer. |
| 222 | - if ( Methods::IDEAL === $request->method ) { |
|
| 222 | + if (Methods::IDEAL === $request->method) { |
|
| 223 | 223 | // If payment method is iDEAL we set the user chosen issuer ID. |
| 224 | 224 | $request->issuer = $payment->get_issuer(); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | // Customer ID. |
| 228 | - $customer_id = $this->get_customer_id_for_payment( $payment ); |
|
| 228 | + $customer_id = $this->get_customer_id_for_payment($payment); |
|
| 229 | 229 | |
| 230 | - if ( ! empty( $customer_id ) ) { |
|
| 230 | + if ( ! empty($customer_id)) { |
|
| 231 | 231 | $request->customer_id = $customer_id; |
| 232 | 232 | } |
| 233 | 233 | |
@@ -237,43 +237,43 @@ discard block |
||
| 237 | 237 | // Subscription. |
| 238 | 238 | $subscription = $payment->get_subscription(); |
| 239 | 239 | |
| 240 | - if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { |
|
| 240 | + if ($subscription && PaymentMethods::is_recurring_method($payment_method)) { |
|
| 241 | 241 | $request->recurring_type = $payment->get_recurring() ? Recurring::RECURRING : Recurring::FIRST; |
| 242 | 242 | |
| 243 | - if ( Recurring::FIRST === $request->recurring_type ) { |
|
| 244 | - $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); |
|
| 243 | + if (Recurring::FIRST === $request->recurring_type) { |
|
| 244 | + $payment_method = PaymentMethods::get_first_payment_method($payment_method); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( Recurring::RECURRING === $request->recurring_type ) { |
|
| 248 | - $payment->set_action_url( $payment->get_return_url() ); |
|
| 247 | + if (Recurring::RECURRING === $request->recurring_type) { |
|
| 248 | + $payment->set_action_url($payment->get_return_url()); |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? |
| 253 | - $request->method = Methods::transform( $payment_method, $payment_method ); |
|
| 253 | + $request->method = Methods::transform($payment_method, $payment_method); |
|
| 254 | 254 | |
| 255 | 255 | // Create payment. |
| 256 | - $result = $this->client->create_payment( $request ); |
|
| 256 | + $result = $this->client->create_payment($request); |
|
| 257 | 257 | |
| 258 | - if ( ! $result ) { |
|
| 258 | + if ( ! $result) { |
|
| 259 | 259 | $this->error = $this->client->get_error(); |
| 260 | 260 | |
| 261 | 261 | return false; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Set transaction ID. |
| 265 | - if ( isset( $result->id ) ) { |
|
| 266 | - $payment->set_transaction_id( $result->id ); |
|
| 265 | + if (isset($result->id)) { |
|
| 266 | + $payment->set_transaction_id($result->id); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Set status |
| 270 | - if ( isset( $result->status ) ) { |
|
| 271 | - $payment->set_status( Statuses::transform( $result->status ) ); |
|
| 270 | + if (isset($result->status)) { |
|
| 271 | + $payment->set_status(Statuses::transform($result->status)); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Set action URL. |
| 275 | - if ( isset( $result->links, $result->links->paymentUrl ) ) { |
|
| 276 | - $payment->set_action_url( $result->links->paymentUrl ); |
|
| 275 | + if (isset($result->links, $result->links->paymentUrl)) { |
|
| 276 | + $payment->set_action_url($result->links->paymentUrl); |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
@@ -282,36 +282,36 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @param Payment $payment |
| 284 | 284 | */ |
| 285 | - public function update_status( Payment $payment ) { |
|
| 286 | - $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); |
|
| 285 | + public function update_status(Payment $payment) { |
|
| 286 | + $mollie_payment = $this->client->get_payment($payment->get_transaction_id()); |
|
| 287 | 287 | |
| 288 | - if ( ! $mollie_payment ) { |
|
| 289 | - $payment->set_status( Core_Statuses::FAILURE ); |
|
| 288 | + if ( ! $mollie_payment) { |
|
| 289 | + $payment->set_status(Core_Statuses::FAILURE); |
|
| 290 | 290 | |
| 291 | 291 | $this->error = $this->client->get_error(); |
| 292 | 292 | |
| 293 | 293 | return; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - $payment->set_status( Statuses::transform( $mollie_payment->status ) ); |
|
| 296 | + $payment->set_status(Statuses::transform($mollie_payment->status)); |
|
| 297 | 297 | |
| 298 | - if ( isset( $mollie_payment->details ) ) { |
|
| 298 | + if (isset($mollie_payment->details)) { |
|
| 299 | 299 | $details = $mollie_payment->details; |
| 300 | 300 | |
| 301 | - if ( isset( $details->consumerName ) ) { |
|
| 302 | - $payment->set_consumer_name( $details->consumerName ); |
|
| 301 | + if (isset($details->consumerName)) { |
|
| 302 | + $payment->set_consumer_name($details->consumerName); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if ( isset( $details->cardHolder ) ) { |
|
| 306 | - $payment->set_consumer_name( $details->cardHolder ); |
|
| 305 | + if (isset($details->cardHolder)) { |
|
| 306 | + $payment->set_consumer_name($details->cardHolder); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( isset( $details->consumerAccount ) ) { |
|
| 310 | - $payment->set_consumer_iban( $details->consumerAccount ); |
|
| 309 | + if (isset($details->consumerAccount)) { |
|
| 310 | + $payment->set_consumer_iban($details->consumerAccount); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - if ( isset( $details->consumerBic ) ) { |
|
| 314 | - $payment->set_consumer_bic( $details->consumerBic ); |
|
| 313 | + if (isset($details->consumerBic)) { |
|
| 314 | + $payment->set_consumer_bic($details->consumerBic); |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | } |
@@ -323,40 +323,40 @@ discard block |
||
| 323 | 323 | * |
| 324 | 324 | * @return bool|string |
| 325 | 325 | */ |
| 326 | - private function get_customer_id_for_payment( Payment $payment ) { |
|
| 326 | + private function get_customer_id_for_payment(Payment $payment) { |
|
| 327 | 327 | // Get Mollie customer ID from user meta. |
| 328 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 328 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 329 | 329 | |
| 330 | - if ( Core_Recurring::FIRST === $payment->recurring_type ) { |
|
| 330 | + if (Core_Recurring::FIRST === $payment->recurring_type) { |
|
| 331 | 331 | // Create new customer if the customer does not exist at Mollie. |
| 332 | - if ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) { |
|
| 333 | - $customer_id = $this->client->create_customer( $payment->get_email(), $payment->get_customer_name() ); |
|
| 332 | + if (empty($customer_id) || ! $this->client->get_customer($customer_id)) { |
|
| 333 | + $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name()); |
|
| 334 | 334 | |
| 335 | - $this->update_wp_user_customer_id( $payment->user_id, $customer_id ); |
|
| 335 | + $this->update_wp_user_customer_id($payment->user_id, $customer_id); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // Temporarily store customer ID in subscription meta for guest users. |
| 339 | - if ( empty( $payment->user_id ) && ! empty( $customer_id ) ) { |
|
| 339 | + if (empty($payment->user_id) && ! empty($customer_id)) { |
|
| 340 | 340 | $subscription = $payment->get_subscription(); |
| 341 | 341 | |
| 342 | - if ( $subscription ) { |
|
| 343 | - $subscription->set_meta( 'mollie_customer_id', $customer_id ); |
|
| 342 | + if ($subscription) { |
|
| 343 | + $subscription->set_meta('mollie_customer_id', $customer_id); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // Try to move customer ID from subscription meta to user. |
| 349 | - if ( empty( $customer_id ) ) { |
|
| 349 | + if (empty($customer_id)) { |
|
| 350 | 350 | // Move customer ID from subscription meta to user meta. |
| 351 | - $this->move_customer_id_to_wp_user( $payment ); |
|
| 351 | + $this->move_customer_id_to_wp_user($payment); |
|
| 352 | 352 | |
| 353 | 353 | // Get customer ID from user meta, again. |
| 354 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 354 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // Try to get customer ID from subscription meta. |
| 358 | - if ( empty( $customer_id ) && $payment->get_subscription() ) { |
|
| 359 | - $customer_id = $payment->get_subscription()->get_meta( 'mollie_customer_id' ); |
|
| 358 | + if (empty($customer_id) && $payment->get_subscription()) { |
|
| 359 | + $customer_id = $payment->get_subscription()->get_meta('mollie_customer_id'); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | return $customer_id; |
@@ -369,12 +369,12 @@ discard block |
||
| 369 | 369 | * |
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | - private function get_customer_id_by_wp_user_id( $user_id ) { |
|
| 373 | - if ( empty( $user_id ) ) { |
|
| 372 | + private function get_customer_id_by_wp_user_id($user_id) { |
|
| 373 | + if (empty($user_id)) { |
|
| 374 | 374 | return false; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - return get_user_meta( $user_id, $this->meta_key_customer_id, true ); |
|
| 377 | + return get_user_meta($user_id, $this->meta_key_customer_id, true); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -385,12 +385,12 @@ discard block |
||
| 385 | 385 | * |
| 386 | 386 | * @return bool |
| 387 | 387 | */ |
| 388 | - private function update_wp_user_customer_id( $user_id, $customer_id ) { |
|
| 389 | - if ( empty( $user_id ) || empty( $customer_id ) ) { |
|
| 388 | + private function update_wp_user_customer_id($user_id, $customer_id) { |
|
| 389 | + if (empty($user_id) || empty($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,26 +400,26 @@ discard block |
||
| 400 | 400 | * |
| 401 | 401 | * @return void |
| 402 | 402 | */ |
| 403 | - public function move_customer_id_to_wp_user( Payment $payment ) { |
|
| 404 | - if ( $this->config->id !== $payment->config_id ) { |
|
| 403 | + public function move_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 | - if ( ! empty( $customer_id ) && ! empty( $subscription->user_id ) ) { |
|
| 417 | + if ( ! empty($customer_id) && ! empty($subscription->user_id)) { |
|
| 418 | 418 | // Set customer ID as user meta. |
| 419 | - $this->update_wp_user_customer_id( $subscription->user_id, $customer_id ); |
|
| 419 | + $this->update_wp_user_customer_id($subscription->user_id, $customer_id); |
|
| 420 | 420 | |
| 421 | 421 | // Delete customer ID from subscription meta. |
| 422 | - $subscription->set_meta( 'mollie_customer_id', null ); |
|
| 422 | + $subscription->set_meta('mollie_customer_id', null); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |