 wp-pay-gateways    /
                    mollie
                      wp-pay-gateways    /
                    mollie
                
                            | 1 | <?php | ||||||
| 2 | /** | ||||||
| 3 | * Mollie gateway. | ||||||
| 4 | * | ||||||
| 5 | * @author Pronamic <[email protected]> | ||||||
| 6 | * @copyright 2005-2019 Pronamic | ||||||
| 7 | * @license GPL-3.0-or-later | ||||||
| 8 | * @package Pronamic\WordPress\Pay | ||||||
| 9 | */ | ||||||
| 10 | |||||||
| 11 | namespace Pronamic\WordPress\Pay\Gateways\Mollie; | ||||||
| 12 | |||||||
| 13 | use DateInterval; | ||||||
| 14 | use Pronamic\WordPress\DateTime\DateTime; | ||||||
| 15 | use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; | ||||||
| 16 | use Pronamic\WordPress\Pay\Core\PaymentMethods; | ||||||
| 17 | use Pronamic\WordPress\Pay\Core\Recurring as Core_Recurring; | ||||||
| 18 | use Pronamic\WordPress\Pay\Core\Statuses as Core_Statuses; | ||||||
| 19 | use Pronamic\WordPress\Pay\Payments\Payment; | ||||||
| 20 | |||||||
| 21 | /** | ||||||
| 22 | * Title: Mollie | ||||||
| 23 | * Description: | ||||||
| 24 | * Copyright: 2005-2019 Pronamic | ||||||
| 25 | * Company: Pronamic | ||||||
| 26 | * | ||||||
| 27 | * @author Remco Tolsma | ||||||
| 28 | * @version 2.1.0 | ||||||
| 29 | * @since 1.1.0 | ||||||
| 30 | */ | ||||||
| 31 | class Gateway extends Core_Gateway { | ||||||
| 32 | /** | ||||||
| 33 | * Client. | ||||||
| 34 | * | ||||||
| 35 | * @var Client | ||||||
| 36 | */ | ||||||
| 37 | protected $client; | ||||||
| 38 | |||||||
| 39 | /** | ||||||
| 40 | * Meta key for customer ID. | ||||||
| 41 | * | ||||||
| 42 | * @var string | ||||||
| 43 | */ | ||||||
| 44 | private $meta_key_customer_id = '_pronamic_pay_mollie_customer_id'; | ||||||
| 45 | |||||||
| 46 | /** | ||||||
| 47 | * Constructs and initializes an Mollie gateway | ||||||
| 48 | * | ||||||
| 49 | * @param Config $config Config. | ||||||
| 50 | */ | ||||||
| 51 | 	public function __construct( Config $config ) { | ||||||
| 52 | parent::__construct( $config ); | ||||||
| 53 | |||||||
| 54 | $this->set_method( self::METHOD_HTTP_REDIRECT ); | ||||||
| 55 | |||||||
| 56 | 40 | // Supported features. | |||||
| 57 | 40 | $this->supports = array( | |||||
| 58 | 'payment_status_request', | ||||||
| 59 | 40 | 'recurring_direct_debit', | |||||
| 60 | 'recurring_credit_card', | ||||||
| 61 | 'recurring', | ||||||
| 62 | ); | ||||||
| 63 | |||||||
| 64 | // Client. | ||||||
| 65 | $this->client = new Client( $config->api_key ); | ||||||
| 66 | 40 | $this->client->set_mode( $config->mode ); | |||||
| 67 | 40 | ||||||
| 68 | // Mollie customer ID meta key. | ||||||
| 69 | 40 | 		if ( self::MODE_TEST === $config->mode ) { | |||||
| 70 | 40 | $this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test'; | |||||
| 71 | } | ||||||
| 72 | 40 | ||||||
| 73 | 40 | // Actions. | |||||
| 74 | add_action( 'pronamic_payment_status_update', array( $this, 'copy_customer_id_to_wp_user' ), 99, 1 ); | ||||||
| 75 | |||||||
| 76 | add_filter( 'pronamic_pay_subscription_next_payment_delivery_date', array( $this, 'next_payment_delivery_date' ), 10, 2 ); | ||||||
| 77 | 40 | } | |||||
| 78 | 40 | ||||||
| 79 | /** | ||||||
| 80 | * Get issuers | ||||||
| 81 | * | ||||||
| 82 | * @see Pronamic_WP_Pay_Gateway::get_issuers() | ||||||
| 83 | */ | ||||||
| 84 | 	public function get_issuers() { | ||||||
| 85 | 3 | $groups = array(); | |||||
| 86 | 3 | ||||||
| 87 | $result = $this->client->get_issuers(); | ||||||
| 88 | 3 | ||||||
| 89 | 		if ( ! $result ) { | ||||||
| 90 | 3 | $this->error = $this->client->get_error(); | |||||
| 91 | 3 | ||||||
| 92 | return $groups; | ||||||
| 93 | 3 | } | |||||
| 94 | |||||||
| 95 | $groups[] = array( | ||||||
| 96 | 'options' => $result, | ||||||
| 97 | ); | ||||||
| 98 | |||||||
| 99 | return $groups; | ||||||
| 100 | } | ||||||
| 101 | |||||||
| 102 | /** | ||||||
| 103 | * Get available payment methods. | ||||||
| 104 | * | ||||||
| 105 | * @see Core_Gateway::get_available_payment_methods() | ||||||
| 106 | */ | ||||||
| 107 | 	public function get_available_payment_methods() { | ||||||
| 108 | 2 | $payment_methods = array(); | |||||
| 109 | 2 | ||||||
| 110 | // Set sequence types to get payment methods for. | ||||||
| 111 | $sequence_types = array( Sequence::ONE_OFF, Sequence::RECURRING, Sequence::FIRST ); | ||||||
| 112 | 2 | ||||||
| 113 | $results = array(); | ||||||
| 114 | 2 | ||||||
| 115 | 		foreach ( $sequence_types as $sequence_type ) { | ||||||
| 116 | 2 | // Get active payment methods for Mollie account. | |||||
| 117 | $result = $this->client->get_payment_methods( $sequence_type ); | ||||||
| 118 | 2 | ||||||
| 119 | 			if ( ! $result ) { | ||||||
| 120 | 2 | $this->error = $this->client->get_error(); | |||||
| 121 | 2 | ||||||
| 122 | break; | ||||||
| 123 | 2 | } | |||||
| 124 | |||||||
| 125 | 			if ( Sequence::FIRST === $sequence_type ) { | ||||||
| 126 | 				foreach ( $result as $method => $title ) { | ||||||
| 127 | unset( $result[ $method ] ); | ||||||
| 128 | |||||||
| 129 | // Get WordPress payment method for direct debit method. | ||||||
| 130 | $method = Methods::transform_gateway_method( $method ); | ||||||
| 131 | $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); | ||||||
| 132 | |||||||
| 133 | 					if ( $payment_method ) { | ||||||
| 134 | $results[ $payment_method ] = $title; | ||||||
| 135 | } | ||||||
| 136 | } | ||||||
| 137 | } | ||||||
| 138 | |||||||
| 139 | $results = array_merge( $results, $result ); | ||||||
| 140 | } | ||||||
| 141 | |||||||
| 142 | // Transform to WordPress payment methods. | ||||||
| 143 | 		foreach ( $results as $method => $title ) { | ||||||
| 144 | 2 | 			if ( PaymentMethods::is_recurring_method( $method ) ) { | |||||
| 145 | $payment_method = $method; | ||||||
| 146 | 			} else { | ||||||
| 147 | $payment_method = Methods::transform_gateway_method( $method ); | ||||||
| 148 | } | ||||||
| 149 | |||||||
| 150 | 			if ( $payment_method ) { | ||||||
| 151 | $payment_methods[] = $payment_method; | ||||||
| 152 | } | ||||||
| 153 | } | ||||||
| 154 | |||||||
| 155 | $payment_methods = array_unique( $payment_methods ); | ||||||
| 156 | 2 | ||||||
| 157 | return $payment_methods; | ||||||
| 158 | 2 | } | |||||
| 159 | |||||||
| 160 | /** | ||||||
| 161 | * Get supported payment methods | ||||||
| 162 | * | ||||||
| 163 | * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() | ||||||
| 164 | */ | ||||||
| 165 | 	public function get_supported_payment_methods() { | ||||||
| 166 | 2 | return array( | |||||
| 167 | PaymentMethods::BANCONTACT, | ||||||
| 168 | 2 | PaymentMethods::BANK_TRANSFER, | |||||
| 169 | PaymentMethods::BELFIUS, | ||||||
| 170 | PaymentMethods::BITCOIN, | ||||||
| 171 | PaymentMethods::CREDIT_CARD, | ||||||
| 172 | PaymentMethods::DIRECT_DEBIT, | ||||||
| 173 | PaymentMethods::DIRECT_DEBIT_BANCONTACT, | ||||||
| 174 | PaymentMethods::DIRECT_DEBIT_IDEAL, | ||||||
| 175 | PaymentMethods::DIRECT_DEBIT_SOFORT, | ||||||
| 176 | PaymentMethods::EPS, | ||||||
| 177 | PaymentMethods::GIROPAY, | ||||||
| 178 | PaymentMethods::IDEAL, | ||||||
| 179 | PaymentMethods::KBC, | ||||||
| 180 | PaymentMethods::PAYPAL, | ||||||
| 181 | PaymentMethods::SOFORT, | ||||||
| 182 | ); | ||||||
| 183 | } | ||||||
| 184 | |||||||
| 185 | /** | ||||||
| 186 | * Get webhook URL for Mollie. | ||||||
| 187 | * | ||||||
| 188 | * @return string | ||||||
| 189 | 4 | */ | |||||
| 190 | 4 | 	public function get_webhook_url() { | |||||
| 191 | $url = home_url( '/' ); | ||||||
| 192 | 4 | ||||||
| 193 | $host = wp_parse_url( $url, PHP_URL_HOST ); | ||||||
| 194 | 4 | ||||||
| 195 | 		if ( is_array( $host ) ) { | ||||||
| 196 | // Parsing failure. | ||||||
| 197 | $host = ''; | ||||||
| 198 | } | ||||||
| 199 | 4 | ||||||
| 200 | 		if ( 'localhost' === $host ) { | ||||||
| 201 | 1 | // Mollie doesn't allow localhost. | |||||
| 202 | 3 | return null; | |||||
| 203 | 		} elseif ( '.dev' === substr( $host, -4 ) ) { | ||||||
| 204 | 1 | // Mollie doesn't allow the .dev TLD. | |||||
| 205 | 2 | return null; | |||||
| 206 | 		} elseif ( '.local' === substr( $host, -6 ) ) { | ||||||
| 207 | 1 | // Mollie doesn't allow the .local TLD. | |||||
| 208 | 1 | return null; | |||||
| 209 | 		} elseif ( '.test' === substr( $host, -5 ) ) { | ||||||
| 210 | // Mollie doesn't allow the .test TLD. | ||||||
| 211 | return null; | ||||||
| 212 | } | ||||||
| 213 | 1 | ||||||
| 214 | $url = add_query_arg( 'mollie_webhook', '', $url ); | ||||||
| 215 | 1 | ||||||
| 216 | return $url; | ||||||
| 217 | } | ||||||
| 218 | |||||||
| 219 | /** | ||||||
| 220 | * Start | ||||||
| 221 | * | ||||||
| 222 | * @see Pronamic_WP_Pay_Gateway::start() | ||||||
| 223 | * | ||||||
| 224 | * @param Payment $payment Payment. | ||||||
| 225 | */ | ||||||
| 226 | 	public function start( Payment $payment ) { | ||||||
| 227 | $request = new PaymentRequest(); | ||||||
| 228 | $request->amount = AmountTransformer::transform( $payment->get_total_amount() ); | ||||||
| 229 | $request->description = $payment->get_description(); | ||||||
| 230 | $request->redirect_url = $payment->get_return_url(); | ||||||
| 231 | $request->webhook_url = $this->get_webhook_url(); | ||||||
| 232 | |||||||
| 233 | // Locale. | ||||||
| 234 | 		if ( null !== $payment->get_customer() ) { | ||||||
| 235 | $request->locale = LocaleHelper::transform( $payment->get_customer()->get_locale() ); | ||||||
| 236 | } | ||||||
| 237 | |||||||
| 238 | // Customer ID. | ||||||
| 239 | $customer_id = $this->get_customer_id_for_payment( $payment ); | ||||||
| 240 | |||||||
| 241 | 		if ( is_string( $customer_id ) && ! empty( $customer_id ) ) { | ||||||
| 242 | $request->customer_id = $customer_id; | ||||||
| 243 | } | ||||||
| 244 | |||||||
| 245 | // Payment method. | ||||||
| 246 | $payment_method = $payment->get_method(); | ||||||
| 247 | |||||||
| 248 | // Subscription. | ||||||
| 249 | $subscription = $payment->get_subscription(); | ||||||
| 250 | |||||||
| 251 | 		if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { | ||||||
| 252 | $request->sequence_type = $payment->get_recurring() ? Sequence::RECURRING : Sequence::FIRST; | ||||||
| 253 | |||||||
| 254 | 			if ( Sequence::FIRST === $request->sequence_type ) { | ||||||
| 255 | $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); | ||||||
| 256 | } | ||||||
| 257 | |||||||
| 258 | 			if ( Sequence::RECURRING === $request->sequence_type ) { | ||||||
| 259 | $payment->set_action_url( $payment->get_return_url() ); | ||||||
| 260 | } | ||||||
| 261 | } | ||||||
| 262 | |||||||
| 263 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? | ||||||
| 264 | $request->method = Methods::transform( $payment_method, $payment_method ); | ||||||
| 265 | |||||||
| 266 | // Issuer. | ||||||
| 267 | 		if ( Methods::IDEAL === $request->method ) { | ||||||
| 268 | $request->issuer = $payment->get_issuer(); | ||||||
| 269 | } | ||||||
| 270 | |||||||
| 271 | // Create payment. | ||||||
| 272 | $result = $this->client->create_payment( $request ); | ||||||
| 273 | |||||||
| 274 | 		if ( ! $result ) { | ||||||
| 275 | $this->error = $this->client->get_error(); | ||||||
| 276 | |||||||
| 277 | return; | ||||||
| 278 | } | ||||||
| 279 | |||||||
| 280 | // Set transaction ID. | ||||||
| 281 | 		if ( isset( $result->id ) ) { | ||||||
| 282 | $payment->set_transaction_id( $result->id ); | ||||||
| 283 | } | ||||||
| 284 | |||||||
| 285 | // Set status. | ||||||
| 286 | 		if ( isset( $result->status ) ) { | ||||||
| 287 | $payment->set_status( Statuses::transform( $result->status ) ); | ||||||
| 288 | } | ||||||
| 289 | |||||||
| 290 | // Set action URL. | ||||||
| 291 | 		if ( isset( $result->_links->checkout->href ) ) { | ||||||
| 292 | $payment->set_action_url( $result->_links->checkout->href ); | ||||||
| 293 | } | ||||||
| 294 | } | ||||||
| 295 | |||||||
| 296 | /** | ||||||
| 297 | * Update status of the specified payment | ||||||
| 298 | * | ||||||
| 299 | * @param Payment $payment Payment. | ||||||
| 300 | * | ||||||
| 301 | * @return void | ||||||
| 302 | */ | ||||||
| 303 | 	public function update_status( Payment $payment ) { | ||||||
| 304 | $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); | ||||||
| 305 | |||||||
| 306 | 		if ( ! $mollie_payment ) { | ||||||
| 307 | $payment->set_status( Core_Statuses::FAILURE ); | ||||||
| 308 | |||||||
| 309 | $this->error = $this->client->get_error(); | ||||||
| 310 | |||||||
| 311 | return; | ||||||
| 312 | } | ||||||
| 313 | |||||||
| 314 | $payment->set_status( Statuses::transform( $mollie_payment->status ) ); | ||||||
| 315 | |||||||
| 316 | 		if ( isset( $mollie_payment->details ) ) { | ||||||
| 317 | $details = $mollie_payment->details; | ||||||
| 318 | |||||||
| 319 | /* | ||||||
| 320 | * @codingStandardsIgnoreStart | ||||||
| 321 | * | ||||||
| 322 | * Ignore coding standards because of sniff WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar | ||||||
| 323 | */ | ||||||
| 324 | 			if ( isset( $details->consumerName ) ) { | ||||||
| 325 | $payment->set_consumer_name( $details->consumerName ); | ||||||
| 326 | } | ||||||
| 327 | |||||||
| 328 | 			if ( isset( $details->cardHolder ) ) { | ||||||
| 329 | $payment->set_consumer_name( $details->cardHolder ); | ||||||
| 330 | } | ||||||
| 331 | |||||||
| 332 | 			if ( isset( $details->consumerAccount ) ) { | ||||||
| 333 | $payment->set_consumer_iban( $details->consumerAccount ); | ||||||
| 334 | } | ||||||
| 335 | |||||||
| 336 | 			if ( isset( $details->consumerBic ) ) { | ||||||
| 337 | $payment->set_consumer_bic( $details->consumerBic ); | ||||||
| 338 | } | ||||||
| 339 | // @codingStandardsIgnoreEnd | ||||||
| 340 | } | ||||||
| 341 | } | ||||||
| 342 | |||||||
| 343 | /** | ||||||
| 344 | * Get Mollie customer ID for payment. | ||||||
| 345 | * | ||||||
| 346 | * @param Payment $payment Payment. | ||||||
| 347 | * | ||||||
| 348 | * @return bool|string | ||||||
| 349 | 11 | */ | |||||
| 350 | 	public function get_customer_id_for_payment( Payment $payment ) { | ||||||
| 351 | 11 | // Get WordPress user ID from payment customer. | |||||
| 352 | $user_id = ( null === $payment->get_customer() ? null : $payment->get_customer()->get_user_id() ); | ||||||
| 353 | |||||||
| 354 | 11 | // Get Mollie customer ID from user meta. | |||||
| 355 | $customer_id = $this->get_customer_id_by_wp_user_id( $user_id ); | ||||||
| 356 | 11 | ||||||
| 357 | $subscription = $payment->get_subscription(); | ||||||
| 358 | |||||||
| 359 | 11 | // Get customer ID from subscription meta. | |||||
| 360 | 11 | 		if ( $subscription ) { | |||||
| 361 | $subscription_customer_id = $subscription->get_meta( 'mollie_customer_id' ); | ||||||
| 362 | |||||||
| 363 | 11 | // Try to get (legacy) customer ID from first payment. | |||||
| 364 | 7 | 			if ( empty( $subscription_customer_id ) && $subscription->get_first_payment() ) { | |||||
| 365 | $first_payment = $subscription->get_first_payment(); | ||||||
| 366 | 7 | ||||||
| 367 | $subscription_customer_id = $first_payment->get_meta( 'mollie_customer_id' ); | ||||||
| 368 | } | ||||||
| 369 | 11 | ||||||
| 370 | 5 | 			if ( ! empty( $subscription_customer_id ) ) { | |||||
| 371 | $customer_id = $subscription_customer_id; | ||||||
| 372 | } | ||||||
| 373 | } | ||||||
| 374 | |||||||
| 375 | 11 | // Create new customer if the customer does not exist at Mollie. | |||||
| 376 | 		if ( ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) && Core_Recurring::RECURRING !== $payment->recurring_type ) { | ||||||
| 377 | $customer_name = null; | ||||||
| 378 | |||||||
| 379 | 			if ( null !== $payment->get_customer() && null !== $payment->get_customer()->get_name() ) { | ||||||
| 380 | $customer_name = strval( $payment->get_customer()->get_name() ); | ||||||
| 381 | } | ||||||
| 382 | |||||||
| 383 | $customer_id = $this->client->create_customer( $payment->get_email(), $customer_name ); | ||||||
| 384 | |||||||
| 385 | $this->update_wp_user_customer_id( $user_id, $customer_id ); | ||||||
| 386 | } | ||||||
| 387 | |||||||
| 388 | 11 | // Store customer ID in subscription meta. | |||||
| 389 | 		if ( $subscription && empty( $subscription_customer_id ) && ! empty( $customer_id ) ) { | ||||||
| 390 | $subscription->set_meta( 'mollie_customer_id', $customer_id ); | ||||||
| 391 | } | ||||||
| 392 | |||||||
| 393 | 11 | // Copy customer ID from subscription to user meta. | |||||
| 394 | $this->copy_customer_id_to_wp_user( $payment ); | ||||||
| 395 | 11 | ||||||
| 396 | return $customer_id; | ||||||
| 397 | } | ||||||
| 398 | |||||||
| 399 | /** | ||||||
| 400 | * Get Mollie customer ID by the specified WordPress user ID. | ||||||
| 401 | * | ||||||
| 402 | * @param int $user_id WordPress user ID. | ||||||
| 403 | * | ||||||
| 404 | * @return string|bool | ||||||
| 405 | 28 | */ | |||||
| 406 | 28 | 	public function get_customer_id_by_wp_user_id( $user_id ) { | |||||
| 407 | 11 | 		if ( empty( $user_id ) ) { | |||||
| 408 | return false; | ||||||
| 409 | } | ||||||
| 410 | 17 | ||||||
| 411 | return get_user_meta( $user_id, $this->meta_key_customer_id, true ); | ||||||
| 412 | } | ||||||
| 413 | |||||||
| 414 | /** | ||||||
| 415 | * Update Mollie customer ID meta for WordPress user. | ||||||
| 416 | * | ||||||
| 417 | * @param int $user_id WordPress user ID. | ||||||
| 418 | * @param string $customer_id Mollie Customer ID. | ||||||
| 419 | * | ||||||
| 420 | * @return bool | ||||||
| 421 | */ | ||||||
| 422 | 	private function update_wp_user_customer_id( $user_id, $customer_id ) { | ||||||
| 423 | 		if ( empty( $user_id ) || is_bool( $user_id ) ) { | ||||||
| 424 | return false; | ||||||
| 425 | } | ||||||
| 426 | |||||||
| 427 | 		if ( ! is_string( $customer_id ) || empty( $customer_id ) || 1 === strlen( $customer_id ) ) { | ||||||
| 428 | return false; | ||||||
| 429 | } | ||||||
| 430 | |||||||
| 431 | update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id ); | ||||||
| 432 | } | ||||||
| 433 | |||||||
| 434 | /** | ||||||
| 435 | * Copy Mollie customer ID from subscription meta to WordPress user meta. | ||||||
| 436 | * | ||||||
| 437 | * @param Payment $payment Payment. | ||||||
| 438 | * | ||||||
| 439 | * @return void | ||||||
| 440 | 28 | */ | |||||
| 441 | 28 | 	public function copy_customer_id_to_wp_user( Payment $payment ) { | |||||
| 442 | 1 | 		if ( $this->config->id !== $payment->config_id ) { | |||||
| 443 | return; | ||||||
| 444 | } | ||||||
| 445 | 27 | ||||||
| 446 | $subscription = $payment->get_subscription(); | ||||||
| 447 | 27 | ||||||
| 448 | 27 | 		if ( ! $subscription || empty( $subscription->user_id ) ) { | |||||
| 449 | return; | ||||||
| 450 | } | ||||||
| 451 | |||||||
| 452 | // Get customer ID from subscription meta. | ||||||
| 453 | $customer_id = $subscription->get_meta( 'mollie_customer_id' ); | ||||||
| 454 | |||||||
| 455 | $user_customer_id = $this->get_customer_id_by_wp_user_id( $subscription->user_id ); | ||||||
| 0 ignored issues–
                            show             Bug
    
    
    
        introduced 
                            by  
  Loading history... | |||||||
| 456 | |||||||
| 457 | 		if ( empty( $user_customer_id ) ) { | ||||||
| 458 | // Set customer ID as user meta. | ||||||
| 459 | $this->update_wp_user_customer_id( $subscription->user_id, $customer_id ); | ||||||
| 0 ignored issues–
                            show It seems like  $customer_idcan also be of typefalse; however, parameter$customer_idofPronamic\WordPress\Pay\G...e_wp_user_customer_id()does only seem to acceptstring, maybe add an additional type check?
                                                                                                                                                                                           (
                                     Ignorable by Annotation
                                ) If this is a false-positive, you can also ignore this issue in your code via the  
  Loading history... It seems like  $subscription->user_idcan also be of typestring; however, parameter$user_idofPronamic\WordPress\Pay\G...e_wp_user_customer_id()does only seem to acceptinteger, maybe add an additional type check?
                                                                                                                                                                                           (
                                     Ignorable by Annotation
                                ) If this is a false-positive, you can also ignore this issue in your code via the  
  Loading history... | |||||||
| 460 | } | ||||||
| 461 | } | ||||||
| 462 | |||||||
| 463 | /** | ||||||
| 464 | * Next payment delivery date. | ||||||
| 465 | * | ||||||
| 466 | * @param \DateTime $next_payment_delivery_date Next payment delivery date. | ||||||
| 467 | * @param Payment $payment Payment. | ||||||
| 468 | * | ||||||
| 469 | * @return \DateTime | ||||||
| 470 | */ | ||||||
| 471 | 	public function next_payment_delivery_date( \DateTime $next_payment_delivery_date, Payment $payment ) { | ||||||
| 472 | // Check gateway. | ||||||
| 473 | $gateway_id = get_post_meta( $payment->get_config_id(), '_pronamic_gateway_id', true ); | ||||||
| 474 | |||||||
| 475 | 		if ( 'mollie' !== $gateway_id ) { | ||||||
| 476 | return $next_payment_delivery_date; | ||||||
| 477 | } | ||||||
| 478 | |||||||
| 479 | // Check direct debit payment method. | ||||||
| 480 | 		if ( ! PaymentMethods::is_direct_debit_method( $payment->get_method() ) ) { | ||||||
| 481 | return $next_payment_delivery_date; | ||||||
| 482 | } | ||||||
| 483 | |||||||
| 484 | // Textual representation of the day of the week, Sunday through Saturday. | ||||||
| 485 | $day_of_week = $next_payment_delivery_date->format( 'l' ); | ||||||
| 486 | |||||||
| 487 | 		switch ( $day_of_week ) { | ||||||
| 488 | case 'Monday': | ||||||
| 489 | $next_payment_delivery_date->sub( new DateInterval( 'P3D' ) ); | ||||||
| 490 | break; | ||||||
| 491 | |||||||
| 492 | case 'Saturday': | ||||||
| 493 | $next_payment_delivery_date->sub( new DateInterval( 'P2D' ) ); | ||||||
| 494 | break; | ||||||
| 495 | |||||||
| 496 | case 'Sunday': | ||||||
| 497 | $next_payment_delivery_date->sub( new DateInterval( 'P3D' ) ); | ||||||
| 498 | break; | ||||||
| 499 | |||||||
| 500 | default: | ||||||
| 501 | $next_payment_delivery_date->sub( new DateInterval( 'P1D' ) ); | ||||||
| 502 | break; | ||||||
| 503 | } | ||||||
| 504 | |||||||
| 505 | $next_payment_delivery_date->setTime( 0, 0, 0 ); | ||||||
| 506 | |||||||
| 507 | return $next_payment_delivery_date; | ||||||
| 508 | } | ||||||
| 509 | } | ||||||
| 510 | 
