From 0523ecaaa21fccb86ca25d4b6226427b82276828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=C3=BCel=20van=20der=20Steege?= Date: Wed, 31 Jul 2024 15:56:39 +0200 Subject: [PATCH 1/2] Set time of subscription next payment to membership time. --- src/SubscriptionUpdater.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SubscriptionUpdater.php b/src/SubscriptionUpdater.php index 883c0c4..2e4d4c7 100644 --- a/src/SubscriptionUpdater.php +++ b/src/SubscriptionUpdater.php @@ -114,7 +114,12 @@ public function update_pronamic_subscription() { if ( false !== $expiration_timestamp ) { $next_payment_date = new DateTimeImmutable( '@' . $expiration_timestamp ); - $next_payment_date = $next_payment_date->setTime( 0, 0, 0 ); + + $next_payment_date = $next_payment_date->setTime( + (int) $initial_phase->get_start_date()->format( 'H' ), + (int) $initial_phase->get_start_date()->format( 'i' ), + (int) $initial_phase->get_start_date()->format( 's' ) + ); } $pronamic_subscription->set_next_payment_date( $next_payment_date ); From 4d9ba5fd619e302e364d8448a9f242c6c83fc065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=C3=BCel=20van=20der=20Steege?= Date: Wed, 31 Jul 2024 16:16:52 +0200 Subject: [PATCH 2/2] Use `$initial_phase_start_date` for membership created date. --- src/SubscriptionUpdater.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/SubscriptionUpdater.php b/src/SubscriptionUpdater.php index 2e4d4c7..bfdf9a7 100644 --- a/src/SubscriptionUpdater.php +++ b/src/SubscriptionUpdater.php @@ -77,9 +77,11 @@ public function update_pronamic_subscription() { $interval_spec = 'P' . $rcp_membership_level->get_trial_duration() . LengthUnit::to_core( $rcp_membership_level->get_trial_duration_unit() ); } + $initial_phase_start_date = new DateTimeImmutable( $rcp_membership->get_created_date( false ) ); + $initial_phase = new SubscriptionPhase( $pronamic_subscription, - new DateTimeImmutable( $rcp_membership->get_created_date( false ) ), + $initial_phase_start_date, new SubscriptionInterval( $interval_spec ), new Money( $rcp_membership->get_initial_amount(), $rcp_membership->get_currency() ) ); @@ -116,9 +118,9 @@ public function update_pronamic_subscription() { $next_payment_date = new DateTimeImmutable( '@' . $expiration_timestamp ); $next_payment_date = $next_payment_date->setTime( - (int) $initial_phase->get_start_date()->format( 'H' ), - (int) $initial_phase->get_start_date()->format( 'i' ), - (int) $initial_phase->get_start_date()->format( 's' ) + (int) $initial_phase_start_date->format( 'H' ), + (int) $initial_phase_start_date->format( 'i' ), + (int) $initial_phase_start_date->format( 's' ) ); }