pronamic/wp-pay-core

Calculating periods created is wrong with a subscription phase with an end date

Opened this issue · 1 comments

/**
* Get periods created.
*
* @return int
*/
public function get_periods_created() {
$next_date = $this->subscription->get_next_payment_date();
if ( null === $next_date ) {
return 0;
}
$period = new \DatePeriod(
new \DateTimeImmutable( $this->start_date->format( 'Y-m-d 00:00:00' ) ),
$this->interval,
new \DateTimeImmutable( $next_date->format( 'Y-m-d 00:00:00' ) )
);
return \iterator_count( $period );
}

The next payment date can go far beyond the end date of a subscription phase.

Scherm­afbeelding 2024-06-19 om 12 25 03

Should we add something like this?

if ( null !== $this->end_date ) {
	$next_date = \min( $next_date, $this->end_date );
}

Probably also rename the variable $next_date to $anchor_date or $pointer_date?

CC @rvdsteege

Should we add something like this?

As discussed at HQ, I think that that would be correct to fix the calculation.