You are here

protected function SubscriptionTypeBase::adjustBillingPeriod in Commerce Recurring Framework 8

Adjusts the billing period to reflect the subscription start/end dates.

Parameters

\Drupal\commerce_recurring\BillingPeriod $billing_period: The billing period.

\Drupal\commerce_recurring\Entity\SubscriptionInterface $subscription: The subscription.

Return value

\Drupal\commerce_recurring\BillingPeriod The adjusted billing period.

2 calls to SubscriptionTypeBase::adjustBillingPeriod()
SubscriptionTypeBase::collectCharges in src/Plugin/Commerce/SubscriptionType/SubscriptionTypeBase.php
Collects charges for a subscription's billing period.
SubscriptionTypeBase::collectTrialCharges in src/Plugin/Commerce/SubscriptionType/SubscriptionTypeBase.php
Collects charges for a subscription's trial period.

File

src/Plugin/Commerce/SubscriptionType/SubscriptionTypeBase.php, line 190

Class

SubscriptionTypeBase
Defines the subscription base class.

Namespace

Drupal\commerce_recurring\Plugin\Commerce\SubscriptionType

Code

protected function adjustBillingPeriod(BillingPeriod $billing_period, SubscriptionInterface $subscription) {
  $subscription_start_date = $subscription
    ->getStartDate();
  $subscription_end_date = $subscription
    ->getEndDate();
  $start_date = $billing_period
    ->getStartDate();
  $end_date = $billing_period
    ->getEndDate();
  if ($billing_period
    ->contains($subscription_start_date)) {

    // The subscription started after the billing period (E.g: customer
    // subscribed on Mar 10th for a Mar 1st - Apr 1st period).
    $start_date = $subscription_start_date;
  }
  if ($subscription_end_date && $billing_period
    ->contains($subscription_end_date)) {

    // The subscription ended before the end of the billing period.
    $end_date = $subscription_end_date;
  }
  return new BillingPeriod($start_date, $end_date);
}