Skip to content

Commit

Permalink
Allow partial periods in subscription phase period creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Jun 5, 2024
1 parent b0a6a19 commit 28d7ed5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Subscriptions/SubscriptionPhase.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private function add_interval( $date, $times = 1 ) {
*
* @param DateTimeImmutable $start_date Start date.
* @return SubscriptionPeriod|null
* @throws \Exception Throws exception on invalid date period.
*/
public function get_period( DateTimeImmutable $start_date = null ) {
if ( null === $start_date ) {
Expand All @@ -487,7 +488,11 @@ public function get_period( DateTimeImmutable $start_date = null ) {
$end_date = $this->add_interval( $start_date );

if ( null !== $this->end_date && $end_date > $this->end_date ) {
return null;
$end_date = $this->end_date;

if ( $start_date > $end_date ) {
throw new \Exception( 'The start date of a subscription period cannot be later than the end date.' );
}
}

$period = new SubscriptionPeriod( $this, $start_date, $end_date, $this->get_amount() );
Expand Down

0 comments on commit 28d7ed5

Please sign in to comment.