@@ -137,13 +137,13 @@ discard block |
||
| 137 | 137 | * |
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | - public static function transform( $payment_method, $default = null ) { |
|
| 141 | - if ( ! is_scalar( $payment_method ) ) { |
|
| 140 | + public static function transform($payment_method, $default = null) { |
|
| 141 | + if ( ! is_scalar($payment_method)) { |
|
| 142 | 142 | return null; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if ( isset( self::$map[ $payment_method ] ) ) { |
|
| 146 | - return self::$map[ $payment_method ]; |
|
| 145 | + if (isset(self::$map[$payment_method])) { |
|
| 146 | + return self::$map[$payment_method]; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $default; |
@@ -158,14 +158,14 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - public static function transform_gateway_method( $method ) { |
|
| 162 | - if ( ! is_scalar( $method ) ) { |
|
| 161 | + public static function transform_gateway_method($method) { |
|
| 162 | + if ( ! is_scalar($method)) { |
|
| 163 | 163 | return null; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $payment_method = array_search( $method, self::$map, true ); |
|
| 166 | + $payment_method = array_search($method, self::$map, true); |
|
| 167 | 167 | |
| 168 | - if ( ! $payment_method ) { |
|
| 168 | + if ( ! $payment_method) { |
|
| 169 | 169 | return null; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | * Settings constructor. |
| 20 | 20 | */ |
| 21 | 21 | public function __construct() { |
| 22 | - add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) ); |
|
| 23 | - add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) ); |
|
| 22 | + add_filter('pronamic_pay_gateway_sections', array($this, 'sections')); |
|
| 23 | + add_filter('pronamic_pay_gateway_fields', array($this, 'fields')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -30,19 +30,19 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return array |
| 32 | 32 | */ |
| 33 | - public function sections( array $sections ) { |
|
| 33 | + public function sections(array $sections) { |
|
| 34 | 34 | // General. |
| 35 | 35 | $sections['mollie'] = array( |
| 36 | - 'title' => __( 'Mollie', 'pronamic_ideal' ), |
|
| 37 | - 'methods' => array( 'mollie' ), |
|
| 38 | - 'description' => __( 'Account details are provided by the payment provider after registration. These settings need to match with the payment provider dashboard.', 'pronamic_ideal' ), |
|
| 36 | + 'title' => __('Mollie', 'pronamic_ideal'), |
|
| 37 | + 'methods' => array('mollie'), |
|
| 38 | + 'description' => __('Account details are provided by the payment provider after registration. These settings need to match with the payment provider dashboard.', 'pronamic_ideal'), |
|
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | // Transaction feedback. |
| 42 | 42 | $sections['mollie_feedback'] = array( |
| 43 | - 'title' => __( 'Transaction feedback', 'pronamic_ideal' ), |
|
| 44 | - 'methods' => array( 'mollie' ), |
|
| 45 | - 'description' => __( 'Payment status updates will be processed without any additional configuration. The <em>Webhook URL</em> is being used to receive the status updates.', 'pronamic_ideal' ), |
|
| 43 | + 'title' => __('Transaction feedback', 'pronamic_ideal'), |
|
| 44 | + 'methods' => array('mollie'), |
|
| 45 | + 'description' => __('Payment status updates will be processed without any additional configuration. The <em>Webhook URL</em> is being used to receive the status updates.', 'pronamic_ideal'), |
|
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | return $sections; |
@@ -55,40 +55,40 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | - public function fields( array $fields ) { |
|
| 58 | + public function fields(array $fields) { |
|
| 59 | 59 | // API Key. |
| 60 | 60 | $fields[] = array( |
| 61 | 61 | 'filter' => FILTER_SANITIZE_STRING, |
| 62 | 62 | 'section' => 'mollie', |
| 63 | 63 | 'meta_key' => '_pronamic_gateway_mollie_api_key', |
| 64 | - 'title' => _x( 'API Key', 'mollie', 'pronamic_ideal' ), |
|
| 64 | + 'title' => _x('API Key', 'mollie', 'pronamic_ideal'), |
|
| 65 | 65 | 'type' => 'text', |
| 66 | - 'classes' => array( 'regular-text', 'code' ), |
|
| 67 | - 'methods' => array( 'mollie' ), |
|
| 68 | - 'tooltip' => __( 'API key as mentioned in the payment provider dashboard', 'pronamic_ideal' ), |
|
| 66 | + 'classes' => array('regular-text', 'code'), |
|
| 67 | + 'methods' => array('mollie'), |
|
| 68 | + 'tooltip' => __('API key as mentioned in the payment provider dashboard', 'pronamic_ideal'), |
|
| 69 | 69 | ); |
| 70 | 70 | |
| 71 | 71 | // Transaction feedback. |
| 72 | 72 | $fields[] = array( |
| 73 | 73 | 'section' => 'mollie', |
| 74 | - 'title' => __( 'Transaction feedback', 'pronamic_ideal' ), |
|
| 74 | + 'title' => __('Transaction feedback', 'pronamic_ideal'), |
|
| 75 | 75 | 'type' => 'description', |
| 76 | 76 | 'html' => sprintf( |
| 77 | 77 | '<span class="dashicons dashicons-yes"></span> %s', |
| 78 | - __( 'Payment status updates will be processed without any additional configuration.', 'pronamic_ideal' ) |
|
| 78 | + __('Payment status updates will be processed without any additional configuration.', 'pronamic_ideal') |
|
| 79 | 79 | ), |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | // Webhook. |
| 83 | 83 | $fields[] = array( |
| 84 | 84 | 'section' => 'mollie_feedback', |
| 85 | - 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
|
| 85 | + 'title' => __('Webhook URL', 'pronamic_ideal'), |
|
| 86 | 86 | 'type' => 'text', |
| 87 | - 'classes' => array( 'large-text', 'code' ), |
|
| 88 | - 'value' => add_query_arg( 'mollie_webhook', '', home_url( '/' ) ), |
|
| 87 | + 'classes' => array('large-text', 'code'), |
|
| 88 | + 'value' => add_query_arg('mollie_webhook', '', home_url('/')), |
|
| 89 | 89 | 'readonly' => true, |
| 90 | - 'methods' => array( 'mollie' ), |
|
| 91 | - 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
|
| 90 | + 'methods' => array('mollie'), |
|
| 91 | + 'tooltip' => __('The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal'), |
|
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | 94 | return $fields; |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param Config $config |
| 39 | 39 | */ |
| 40 | - public function __construct( Config $config ) { |
|
| 41 | - parent::__construct( $config ); |
|
| 40 | + public function __construct(Config $config) { |
|
| 41 | + parent::__construct($config); |
|
| 42 | 42 | |
| 43 | 43 | $this->supports = array( |
| 44 | 44 | 'payment_status_request', |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | 'recurring', |
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - $this->set_method( Core_Gateway::METHOD_HTTP_REDIRECT ); |
|
| 51 | - $this->set_has_feedback( true ); |
|
| 52 | - $this->set_amount_minimum( 1.20 ); |
|
| 53 | - $this->set_slug( self::SLUG ); |
|
| 50 | + $this->set_method(Core_Gateway::METHOD_HTTP_REDIRECT); |
|
| 51 | + $this->set_has_feedback(true); |
|
| 52 | + $this->set_amount_minimum(1.20); |
|
| 53 | + $this->set_slug(self::SLUG); |
|
| 54 | 54 | |
| 55 | - $this->client = new Client( $config->api_key ); |
|
| 56 | - $this->client->set_mode( $config->mode ); |
|
| 55 | + $this->client = new Client($config->api_key); |
|
| 56 | + $this->client->set_mode($config->mode); |
|
| 57 | 57 | |
| 58 | - if ( 'test' === $config->mode ) { |
|
| 58 | + if ('test' === $config->mode) { |
|
| 59 | 59 | $this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test'; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $result = $this->client->get_issuers(); |
| 72 | 72 | |
| 73 | - if ( ! $result ) { |
|
| 73 | + if ( ! $result) { |
|
| 74 | 74 | $this->error = $this->client->get_error(); |
| 75 | 75 | |
| 76 | 76 | return $groups; |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | public function get_issuer_field() { |
| 87 | - if ( PaymentMethods::IDEAL === $this->get_payment_method() ) { |
|
| 87 | + if (PaymentMethods::IDEAL === $this->get_payment_method()) { |
|
| 88 | 88 | return array( |
| 89 | 89 | 'id' => 'pronamic_ideal_issuer_id', |
| 90 | 90 | 'name' => 'pronamic_ideal_issuer_id', |
| 91 | - 'label' => __( 'Choose your bank', 'pronamic_ideal' ), |
|
| 91 | + 'label' => __('Choose your bank', 'pronamic_ideal'), |
|
| 92 | 92 | 'required' => true, |
| 93 | 93 | 'type' => 'select', |
| 94 | 94 | 'choices' => $this->get_transient_issuers(), |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | * @param int $user_id |
| 103 | 103 | * @return string |
| 104 | 104 | */ |
| 105 | - private function get_customer_id_by_wp_user_id( $user_id ) { |
|
| 106 | - if ( empty( $user_id ) ) { |
|
| 105 | + private function get_customer_id_by_wp_user_id($user_id) { |
|
| 106 | + if (empty($user_id)) { |
|
| 107 | 107 | return false; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return get_user_meta( $user_id, $this->meta_key_customer_id, true ); |
|
| 110 | + return get_user_meta($user_id, $this->meta_key_customer_id, true); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - private function update_wp_user_customer_id( $user_id, $customer_id ) { |
|
| 114 | - if ( empty( $user_id ) || empty( $customer_id ) ) { |
|
| 113 | + private function update_wp_user_customer_id($user_id, $customer_id) { |
|
| 114 | + if (empty($user_id) || empty($customer_id)) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id ); |
|
| 118 | + update_user_meta($user_id, $this->meta_key_customer_id, $customer_id); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @see Pronamic_WP_Pay_Gateway::has_valid_mandate() |
| 125 | 125 | */ |
| 126 | - public function has_valid_mandate( $payment_method = '' ) { |
|
| 127 | - return $this->client->has_valid_mandate( $this->get_customer_id_by_wp_user_id( get_current_user_id() ), $payment_method ); |
|
| 126 | + public function has_valid_mandate($payment_method = '') { |
|
| 127 | + return $this->client->has_valid_mandate($this->get_customer_id_by_wp_user_id(get_current_user_id()), $payment_method); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @see Pronamic_WP_Pay_Gateway::has_valid_mandate() |
| 134 | 134 | */ |
| 135 | - public function get_first_valid_mandate_datetime( $payment_method = '' ) { |
|
| 136 | - return $this->client->get_first_valid_mandate_datetime( $this->get_customer_id_by_wp_user_id( get_current_user_id() ), $payment_method ); |
|
| 135 | + public function get_first_valid_mandate_datetime($payment_method = '') { |
|
| 136 | + return $this->client->get_first_valid_mandate_datetime($this->get_customer_id_by_wp_user_id(get_current_user_id()), $payment_method); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -145,51 +145,51 @@ discard block |
||
| 145 | 145 | $payment_methods = array(); |
| 146 | 146 | |
| 147 | 147 | // Set recurring types to get payment methods for. |
| 148 | - $recurring_types = array( null, 'recurring', 'first' ); |
|
| 148 | + $recurring_types = array(null, 'recurring', 'first'); |
|
| 149 | 149 | |
| 150 | 150 | $results = array(); |
| 151 | 151 | |
| 152 | - foreach ( $recurring_types as $recurring_type ) { |
|
| 152 | + foreach ($recurring_types as $recurring_type) { |
|
| 153 | 153 | // Get active payment methods for Mollie account. |
| 154 | - $result = $this->client->get_payment_methods( $recurring_type ); |
|
| 154 | + $result = $this->client->get_payment_methods($recurring_type); |
|
| 155 | 155 | |
| 156 | - if ( ! $result ) { |
|
| 156 | + if ( ! $result) { |
|
| 157 | 157 | $this->error = $this->client->get_error(); |
| 158 | 158 | |
| 159 | 159 | break; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if ( 'first' === $recurring_type ) { |
|
| 163 | - foreach ( $result as $method => $title ) { |
|
| 164 | - unset( $result[ $method ] ); |
|
| 162 | + if ('first' === $recurring_type) { |
|
| 163 | + foreach ($result as $method => $title) { |
|
| 164 | + unset($result[$method]); |
|
| 165 | 165 | |
| 166 | 166 | // Get WordPress payment method for direct debit method. |
| 167 | - $method = Methods::transform_gateway_method( $method ); |
|
| 168 | - $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); |
|
| 167 | + $method = Methods::transform_gateway_method($method); |
|
| 168 | + $payment_method = array_search($method, PaymentMethods::get_recurring_methods(), true); |
|
| 169 | 169 | |
| 170 | - if ( $payment_method ) { |
|
| 171 | - $results[ $payment_method ] = $title; |
|
| 170 | + if ($payment_method) { |
|
| 171 | + $results[$payment_method] = $title; |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $results = array_merge( $results, $result ); |
|
| 176 | + $results = array_merge($results, $result); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Transform to WordPress payment methods. |
| 180 | - foreach ( $results as $method => $title ) { |
|
| 181 | - if ( PaymentMethods::is_recurring_method( $method ) ) { |
|
| 180 | + foreach ($results as $method => $title) { |
|
| 181 | + if (PaymentMethods::is_recurring_method($method)) { |
|
| 182 | 182 | $payment_method = $method; |
| 183 | 183 | } else { |
| 184 | - $payment_method = Methods::transform_gateway_method( $method ); |
|
| 184 | + $payment_method = Methods::transform_gateway_method($method); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( $payment_method ) { |
|
| 187 | + if ($payment_method) { |
|
| 188 | 188 | $payment_methods[] = $payment_method; |
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $payment_methods = array_unique( $payment_methods ); |
|
| 192 | + $payment_methods = array_unique($payment_methods); |
|
| 193 | 193 | |
| 194 | 194 | return $payment_methods; |
| 195 | 195 | } |
@@ -223,19 +223,19 @@ discard block |
||
| 223 | 223 | * @return string |
| 224 | 224 | */ |
| 225 | 225 | private function get_webhook_url() { |
| 226 | - $url = home_url( '/' ); |
|
| 226 | + $url = home_url('/'); |
|
| 227 | 227 | |
| 228 | - $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
| 228 | + $host = wp_parse_url($url, PHP_URL_HOST); |
|
| 229 | 229 | |
| 230 | - if ( 'localhost' === $host ) { |
|
| 230 | + if ('localhost' === $host) { |
|
| 231 | 231 | // Mollie doesn't allow localhost |
| 232 | 232 | return null; |
| 233 | - } elseif ( '.dev' === substr( $host, -4 ) ) { |
|
| 233 | + } elseif ('.dev' === substr($host, -4)) { |
|
| 234 | 234 | // Mollie doesn't allow the TLD .dev |
| 235 | 235 | return null; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - $url = add_query_arg( 'mollie_webhook', '', $url ); |
|
| 238 | + $url = add_query_arg('mollie_webhook', '', $url); |
|
| 239 | 239 | |
| 240 | 240 | return $url; |
| 241 | 241 | } |
@@ -245,35 +245,35 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @see Pronamic_WP_Pay_Gateway::start() |
| 247 | 247 | */ |
| 248 | - public function start( Payment $payment ) { |
|
| 248 | + public function start(Payment $payment) { |
|
| 249 | 249 | $request = new PaymentRequest(); |
| 250 | 250 | |
| 251 | 251 | $request->amount = $payment->get_amount(); |
| 252 | 252 | $request->description = $payment->get_description(); |
| 253 | 253 | $request->redirect_url = $payment->get_return_url(); |
| 254 | 254 | $request->webhook_url = $this->get_webhook_url(); |
| 255 | - $request->locale = LocaleHelper::transform( $payment->get_language() ); |
|
| 255 | + $request->locale = LocaleHelper::transform($payment->get_language()); |
|
| 256 | 256 | |
| 257 | 257 | // Issuer. |
| 258 | - if ( Methods::IDEAL === $request->method ) { |
|
| 258 | + if (Methods::IDEAL === $request->method) { |
|
| 259 | 259 | // If payment method is iDEAL we set the user chosen issuer ID. |
| 260 | 260 | $request->issuer = $payment->get_issuer(); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Customer ID. |
| 264 | - if ( ! empty( $payment->user_id ) ) { |
|
| 265 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
| 264 | + if ( ! empty($payment->user_id)) { |
|
| 265 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
| 266 | 266 | |
| 267 | 267 | // Create new customer if the customer does not exists at Mollie. |
| 268 | - if ( ! $this->client->get_customer( $customer_id ) ) { |
|
| 269 | - $customer_id = $this->client->create_customer( $payment->get_email(), $payment->get_customer_name() ); |
|
| 268 | + if ( ! $this->client->get_customer($customer_id)) { |
|
| 269 | + $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name()); |
|
| 270 | 270 | |
| 271 | - if ( ! empty( $customer_id ) ) { |
|
| 272 | - $this->update_wp_user_customer_id( $payment->user_id, $customer_id ); |
|
| 271 | + if ( ! empty($customer_id)) { |
|
| 272 | + $this->update_wp_user_customer_id($payment->user_id, $customer_id); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if ( ! empty( $customer_id ) ) { |
|
| 276 | + if ( ! empty($customer_id)) { |
|
| 277 | 277 | $request->customer_id = $customer_id; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -284,43 +284,43 @@ discard block |
||
| 284 | 284 | // Subscription. |
| 285 | 285 | $subscription = $payment->get_subscription(); |
| 286 | 286 | |
| 287 | - if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { |
|
| 287 | + if ($subscription && PaymentMethods::is_recurring_method($payment_method)) { |
|
| 288 | 288 | $request->recurring_type = $payment->get_recurring() ? Recurring::RECURRING : Recurring::FIRST; |
| 289 | 289 | |
| 290 | - if ( Recurring::FIRST === $request->recurring_type ) { |
|
| 291 | - $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); |
|
| 290 | + if (Recurring::FIRST === $request->recurring_type) { |
|
| 291 | + $payment_method = PaymentMethods::get_first_payment_method($payment_method); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( Recurring::RECURRING === $request->recurring_type ) { |
|
| 295 | - $payment->set_action_url( $payment->get_return_url() ); |
|
| 294 | + if (Recurring::RECURRING === $request->recurring_type) { |
|
| 295 | + $payment->set_action_url($payment->get_return_url()); |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? |
| 300 | - $request->method = Methods::transform( $payment_method, $payment_method ); |
|
| 300 | + $request->method = Methods::transform($payment_method, $payment_method); |
|
| 301 | 301 | |
| 302 | 302 | // Create payment. |
| 303 | - $result = $this->client->create_payment( $request ); |
|
| 303 | + $result = $this->client->create_payment($request); |
|
| 304 | 304 | |
| 305 | - if ( ! $result ) { |
|
| 305 | + if ( ! $result) { |
|
| 306 | 306 | $this->error = $this->client->get_error(); |
| 307 | 307 | |
| 308 | 308 | return false; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Set transaction ID. |
| 312 | - if ( isset( $result->id ) ) { |
|
| 313 | - $payment->set_transaction_id( $result->id ); |
|
| 312 | + if (isset($result->id)) { |
|
| 313 | + $payment->set_transaction_id($result->id); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // Set status |
| 317 | - if ( isset( $result->status ) ) { |
|
| 318 | - $payment->set_status( Statuses::transform( $result->status ) ); |
|
| 317 | + if (isset($result->status)) { |
|
| 318 | + $payment->set_status(Statuses::transform($result->status)); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | // Set action URL. |
| 322 | - if ( isset( $result->links, $result->links->paymentUrl ) ) { |
|
| 323 | - $payment->set_action_url( $result->links->paymentUrl ); |
|
| 322 | + if (isset($result->links, $result->links->paymentUrl)) { |
|
| 323 | + $payment->set_action_url($result->links->paymentUrl); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
@@ -329,36 +329,36 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @param Payment $payment |
| 331 | 331 | */ |
| 332 | - public function update_status( Payment $payment ) { |
|
| 333 | - $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); |
|
| 332 | + public function update_status(Payment $payment) { |
|
| 333 | + $mollie_payment = $this->client->get_payment($payment->get_transaction_id()); |
|
| 334 | 334 | |
| 335 | - if ( ! $mollie_payment ) { |
|
| 336 | - $payment->set_status( Core_Statuses::FAILURE ); |
|
| 335 | + if ( ! $mollie_payment) { |
|
| 336 | + $payment->set_status(Core_Statuses::FAILURE); |
|
| 337 | 337 | |
| 338 | 338 | $this->error = $this->client->get_error(); |
| 339 | 339 | |
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - $payment->set_status( Statuses::transform( $mollie_payment->status ) ); |
|
| 343 | + $payment->set_status(Statuses::transform($mollie_payment->status)); |
|
| 344 | 344 | |
| 345 | - if ( isset( $mollie_payment->details ) ) { |
|
| 345 | + if (isset($mollie_payment->details)) { |
|
| 346 | 346 | $details = $mollie_payment->details; |
| 347 | 347 | |
| 348 | - if ( isset( $details->consumerName ) ) { |
|
| 349 | - $payment->set_consumer_name( $details->consumerName ); |
|
| 348 | + if (isset($details->consumerName)) { |
|
| 349 | + $payment->set_consumer_name($details->consumerName); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - if ( isset( $details->cardHolder ) ) { |
|
| 353 | - $payment->set_consumer_name( $details->cardHolder ); |
|
| 352 | + if (isset($details->cardHolder)) { |
|
| 353 | + $payment->set_consumer_name($details->cardHolder); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if ( isset( $details->consumerAccount ) ) { |
|
| 357 | - $payment->set_consumer_iban( $details->consumerAccount ); |
|
| 356 | + if (isset($details->consumerAccount)) { |
|
| 357 | + $payment->set_consumer_iban($details->consumerAccount); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( isset( $details->consumerBic ) ) { |
|
| 361 | - $payment->set_consumer_bic( $details->consumerBic ); |
|
| 360 | + if (isset($details->consumerBic)) { |
|
| 361 | + $payment->set_consumer_bic($details->consumerBic); |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @param string $api_key |
| 52 | 52 | */ |
| 53 | - public function __construct( $api_key ) { |
|
| 53 | + public function __construct($api_key) { |
|
| 54 | 54 | $this->api_key = $api_key; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @since 1.1.9 |
| 61 | 61 | * @param string $mode |
| 62 | 62 | */ |
| 63 | - public function set_mode( $mode ) { |
|
| 63 | + public function set_mode($mode) { |
|
| 64 | 64 | $this->mode = $mode; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -83,39 +83,39 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return bool|object |
| 85 | 85 | */ |
| 86 | - private function send_request( $end_point, $method = 'GET', array $data = array(), $expected_response_code = 200 ) { |
|
| 86 | + private function send_request($end_point, $method = 'GET', array $data = array(), $expected_response_code = 200) { |
|
| 87 | 87 | // Request |
| 88 | 88 | $url = self::API_URL . $end_point; |
| 89 | 89 | |
| 90 | - $response = wp_remote_request( $url, array( |
|
| 90 | + $response = wp_remote_request($url, array( |
|
| 91 | 91 | 'method' => $method, |
| 92 | 92 | 'headers' => array( |
| 93 | 93 | 'Authorization' => 'Bearer ' . $this->api_key, |
| 94 | 94 | ), |
| 95 | 95 | 'body' => $data, |
| 96 | - ) ); |
|
| 96 | + )); |
|
| 97 | 97 | |
| 98 | 98 | // Response code |
| 99 | - $response_code = wp_remote_retrieve_response_code( $response ); |
|
| 99 | + $response_code = wp_remote_retrieve_response_code($response); |
|
| 100 | 100 | |
| 101 | - if ( $expected_response_code != $response_code ) { // WPCS: loose comparison ok. |
|
| 102 | - $this->error = new WP_Error( 'mollie_error', 'Unexpected response code.' ); |
|
| 101 | + if ($expected_response_code != $response_code) { // WPCS: loose comparison ok. |
|
| 102 | + $this->error = new WP_Error('mollie_error', 'Unexpected response code.'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Body |
| 106 | - $body = wp_remote_retrieve_body( $response ); |
|
| 106 | + $body = wp_remote_retrieve_body($response); |
|
| 107 | 107 | |
| 108 | - $data = json_decode( $body ); |
|
| 108 | + $data = json_decode($body); |
|
| 109 | 109 | |
| 110 | - if ( ! is_object( $data ) ) { |
|
| 111 | - $this->error = new WP_Error( 'mollie_error', 'Could not parse response.' ); |
|
| 110 | + if ( ! is_object($data)) { |
|
| 111 | + $this->error = new WP_Error('mollie_error', 'Could not parse response.'); |
|
| 112 | 112 | |
| 113 | 113 | return false; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Mollie error |
| 117 | - if ( isset( $data->error, $data->error->message ) ) { |
|
| 118 | - $this->error = new \WP_Error( 'mollie_error', $data->error->message, $data->error ); |
|
| 117 | + if (isset($data->error, $data->error->message)) { |
|
| 118 | + $this->error = new \WP_Error('mollie_error', $data->error->message, $data->error); |
|
| 119 | 119 | |
| 120 | 120 | return false; |
| 121 | 121 | } |
@@ -123,20 +123,20 @@ discard block |
||
| 123 | 123 | return $data; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function create_payment( PaymentRequest $request ) { |
|
| 127 | - return $this->send_request( 'payments/', 'POST', $request->get_array(), 201 ); |
|
| 126 | + public function create_payment(PaymentRequest $request) { |
|
| 127 | + return $this->send_request('payments/', 'POST', $request->get_array(), 201); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | public function get_payments() { |
| 131 | - return $this->send_request( 'payments/', 'GET' ); |
|
| 131 | + return $this->send_request('payments/', 'GET'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - public function get_payment( $payment_id ) { |
|
| 135 | - if ( empty( $payment_id ) ) { |
|
| 134 | + public function get_payment($payment_id) { |
|
| 135 | + if (empty($payment_id)) { |
|
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - return $this->send_request( 'payments/' . $payment_id, 'GET' ); |
|
| 139 | + return $this->send_request('payments/' . $payment_id, 'GET'); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -145,21 +145,21 @@ discard block |
||
| 145 | 145 | * @return array |
| 146 | 146 | */ |
| 147 | 147 | public function get_issuers() { |
| 148 | - $response = $this->send_request( 'issuers/', 'GET' ); |
|
| 148 | + $response = $this->send_request('issuers/', 'GET'); |
|
| 149 | 149 | |
| 150 | - if ( false === $response ) { |
|
| 150 | + if (false === $response) { |
|
| 151 | 151 | return false; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | $issuers = array(); |
| 155 | 155 | |
| 156 | - if ( isset( $response->data ) ) { |
|
| 157 | - foreach ( $response->data as $issuer ) { |
|
| 158 | - if ( Methods::IDEAL === $issuer->method ) { |
|
| 159 | - $id = Security::filter( $issuer->id ); |
|
| 160 | - $name = Security::filter( $issuer->name ); |
|
| 156 | + if (isset($response->data)) { |
|
| 157 | + foreach ($response->data as $issuer) { |
|
| 158 | + if (Methods::IDEAL === $issuer->method) { |
|
| 159 | + $id = Security::filter($issuer->id); |
|
| 160 | + $name = Security::filter($issuer->name); |
|
| 161 | 161 | |
| 162 | - $issuers[ $id ] = $name; |
|
| 162 | + $issuers[$id] = $name; |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -174,27 +174,27 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return array |
| 176 | 176 | */ |
| 177 | - public function get_payment_methods( $recurring_type = '' ) { |
|
| 177 | + public function get_payment_methods($recurring_type = '') { |
|
| 178 | 178 | $data = array(); |
| 179 | 179 | |
| 180 | - if ( '' !== $recurring_type ) { |
|
| 180 | + if ('' !== $recurring_type) { |
|
| 181 | 181 | $data['recurringType'] = $recurring_type; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $response = $this->send_request( 'methods/', 'GET', $data ); |
|
| 184 | + $response = $this->send_request('methods/', 'GET', $data); |
|
| 185 | 185 | |
| 186 | - if ( false === $response ) { |
|
| 186 | + if (false === $response) { |
|
| 187 | 187 | return false; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $payment_methods = array(); |
| 191 | 191 | |
| 192 | - if ( isset( $response->data ) ) { |
|
| 193 | - foreach ( $response->data as $payment_method ) { |
|
| 194 | - $id = Security::filter( $payment_method->id ); |
|
| 195 | - $name = Security::filter( $payment_method->description ); |
|
| 192 | + if (isset($response->data)) { |
|
| 193 | + foreach ($response->data as $payment_method) { |
|
| 194 | + $id = Security::filter($payment_method->id); |
|
| 195 | + $name = Security::filter($payment_method->description); |
|
| 196 | 196 | |
| 197 | - $payment_methods[ $id ] = $name; |
|
| 197 | + $payment_methods[$id] = $name; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return array|bool |
| 213 | 213 | */ |
| 214 | - public function create_customer( $email, $name ) { |
|
| 215 | - if ( empty( $email ) || empty( $name ) ) { |
|
| 214 | + public function create_customer($email, $name) { |
|
| 215 | + if (empty($email) || empty($name)) { |
|
| 216 | 216 | return false; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - $response = $this->send_request( 'customers/', 'POST', array( |
|
| 219 | + $response = $this->send_request('customers/', 'POST', array( |
|
| 220 | 220 | 'name' => $name, |
| 221 | 221 | 'email' => $email, |
| 222 | - ), 201 ); |
|
| 222 | + ), 201); |
|
| 223 | 223 | |
| 224 | - if ( false === $response ) { |
|
| 224 | + if (false === $response) { |
|
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( ! isset( $response->id ) ) { |
|
| 228 | + if ( ! isset($response->id)) { |
|
| 229 | 229 | return false; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -241,18 +241,18 @@ discard block |
||
| 241 | 241 | * |
| 242 | 242 | * @return array |
| 243 | 243 | */ |
| 244 | - public function get_customer( $customer_id ) { |
|
| 245 | - if ( empty( $customer_id ) ) { |
|
| 244 | + public function get_customer($customer_id) { |
|
| 245 | + if (empty($customer_id)) { |
|
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $response = $this->send_request( 'customers/' . $customer_id, 'GET', array(), 200 ); |
|
| 249 | + $response = $this->send_request('customers/' . $customer_id, 'GET', array(), 200); |
|
| 250 | 250 | |
| 251 | - if ( false === $response ) { |
|
| 251 | + if (false === $response) { |
|
| 252 | 252 | return false; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if ( is_wp_error( $this->error ) ) { |
|
| 255 | + if (is_wp_error($this->error)) { |
|
| 256 | 256 | return false; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -266,12 +266,12 @@ discard block |
||
| 266 | 266 | * |
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | - public function get_mandates( $customer_id ) { |
|
| 270 | - if ( '' === $customer_id ) { |
|
| 269 | + public function get_mandates($customer_id) { |
|
| 270 | + if ('' === $customer_id) { |
|
| 271 | 271 | return false; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - return $this->send_request( 'customers/' . $customer_id . '/mandates?count=250', 'GET' ); |
|
| 274 | + return $this->send_request('customers/' . $customer_id . '/mandates?count=250', 'GET'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -281,21 +281,21 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @return boolean |
| 283 | 283 | */ |
| 284 | - public function has_valid_mandate( $customer_id, $payment_method = null ) { |
|
| 285 | - $mandates = $this->get_mandates( $customer_id ); |
|
| 284 | + public function has_valid_mandate($customer_id, $payment_method = null) { |
|
| 285 | + $mandates = $this->get_mandates($customer_id); |
|
| 286 | 286 | |
| 287 | - if ( ! $mandates ) { |
|
| 287 | + if ( ! $mandates) { |
|
| 288 | 288 | return false; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $mollie_method = Methods::transform( $payment_method ); |
|
| 291 | + $mollie_method = Methods::transform($payment_method); |
|
| 292 | 292 | |
| 293 | - foreach ( $mandates->data as $mandate ) { |
|
| 294 | - if ( $mollie_method !== $mandate->method ) { |
|
| 293 | + foreach ($mandates->data as $mandate) { |
|
| 294 | + if ($mollie_method !== $mandate->method) { |
|
| 295 | 295 | continue; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( 'valid' === $mandate->status ) { |
|
| 298 | + if ('valid' === $mandate->status) { |
|
| 299 | 299 | return true; |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -310,43 +310,43 @@ discard block |
||
| 310 | 310 | * |
| 311 | 311 | * @return string |
| 312 | 312 | */ |
| 313 | - public function get_first_valid_mandate_datetime( $customer_id, $payment_method = null ) { |
|
| 314 | - $mandates = $this->get_mandates( $customer_id ); |
|
| 313 | + public function get_first_valid_mandate_datetime($customer_id, $payment_method = null) { |
|
| 314 | + $mandates = $this->get_mandates($customer_id); |
|
| 315 | 315 | |
| 316 | - if ( ! $mandates ) { |
|
| 316 | + if ( ! $mandates) { |
|
| 317 | 317 | return null; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - $mollie_method = Methods::transform( $payment_method ); |
|
| 320 | + $mollie_method = Methods::transform($payment_method); |
|
| 321 | 321 | |
| 322 | - foreach ( $mandates->data as $mandate ) { |
|
| 323 | - if ( $mollie_method !== $mandate->method ) { |
|
| 322 | + foreach ($mandates->data as $mandate) { |
|
| 323 | + if ($mollie_method !== $mandate->method) { |
|
| 324 | 324 | continue; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if ( 'valid' !== $mandate->status ) { |
|
| 327 | + if ('valid' !== $mandate->status) { |
|
| 328 | 328 | continue; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if ( ! isset( $valid_mandates ) ) { |
|
| 331 | + if ( ! isset($valid_mandates)) { |
|
| 332 | 332 | $valid_mandates = array(); |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - $valid_mandates[ $mandate->createdDatetime ] = $mandate; |
|
| 335 | + $valid_mandates[$mandate->createdDatetime] = $mandate; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( isset( $valid_mandates ) ) { |
|
| 339 | - ksort( $valid_mandates ); |
|
| 338 | + if (isset($valid_mandates)) { |
|
| 339 | + ksort($valid_mandates); |
|
| 340 | 340 | |
| 341 | - $mandate = array_shift( $valid_mandates ); |
|
| 341 | + $mandate = array_shift($valid_mandates); |
|
| 342 | 342 | |
| 343 | - $created = new \DateTime( $mandate->createdDatetime ); |
|
| 343 | + $created = new \DateTime($mandate->createdDatetime); |
|
| 344 | 344 | |
| 345 | 345 | return sprintf( |
| 346 | 346 | /* translators: 1: date, 2: time */ |
| 347 | - __( '%1$s at %2$s', 'pronamic_ideal' ), |
|
| 348 | - date_i18n( get_option( 'date_format' ), $created->getTimestamp() ), |
|
| 349 | - date_i18n( get_option( 'time_format' ), $created->getTimestamp() ) |
|
| 347 | + __('%1$s at %2$s', 'pronamic_ideal'), |
|
| 348 | + date_i18n(get_option('date_format'), $created->getTimestamp()), |
|
| 349 | + date_i18n(get_option('time_format'), $created->getTimestamp()) |
|
| 350 | 350 | ); |
| 351 | 351 | } |
| 352 | 352 | |