Skip to content

Commit

Permalink
No longer use $phase->set_total_periods() for test payment subscrip…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
rvdsteege committed Jun 5, 2024
1 parent 799d690 commit 7d647a6
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Admin/AdminModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,28 +533,32 @@ public function maybe_test_payment() {
$subscription->set_description( $description );
$subscription->set_lines( $payment->get_lines() );

// Phase.
$phase = new SubscriptionPhase(
$subscription,
new DateTimeImmutable(),
new SubscriptionInterval( 'P' . $interval . Util::to_period( $interval_period ) ),
$price
);

// Ends on.
$total_periods = null;

if ( \array_key_exists( 'pronamic_pay_ends_on', $_POST ) ) {
$total_periods = null;

switch ( $_POST['pronamic_pay_ends_on'] ) {
case 'count':
$count = \filter_input( \INPUT_POST, 'pronamic_pay_ends_on_count', \FILTER_VALIDATE_INT );

if ( ! empty( $count ) ) {
$total_periods = $count;
}
$total_periods = (int) \filter_input( \INPUT_POST, 'pronamic_pay_ends_on_count', \FILTER_VALIDATE_INT );

break;
case 'date':
$end_date = \array_key_exists( 'pronamic_pay_ends_on_date', $_POST ) ? \sanitize_text_field( \wp_unslash( $_POST['pronamic_pay_ends_on_date'] ) ) : '';

if ( ! empty( $end_date ) ) {
$interval_spec = 'P' . $interval . Util::to_period( $interval_period );

$period = new \DatePeriod(
new \DateTime(),
new \DateInterval( $interval_spec ),
$phase->get_start_date(),
$phase->get_interval(),
new \DateTime( $end_date )
);

Expand All @@ -563,17 +567,13 @@ public function maybe_test_payment() {

break;
}
}

// Phase.
$phase = new SubscriptionPhase(
$subscription,
new DateTimeImmutable(),
new SubscriptionInterval( 'P' . $interval . Util::to_period( $interval_period ) ),
$price
);
if ( null !== $total_periods ) {
$end_date = $phase->get_start_date()->add( $phase->get_interval()->multiply( $total_periods ) );

$phase->set_total_periods( $total_periods );
$phase->set_end_date( $end_date );
}
}

$subscription->add_phase( $phase );

Expand Down

0 comments on commit 7d647a6

Please sign in to comment.