public function generateNext(BillingAgreementInterface $billingAgreement)
    {
        $billingPeriodStart = null;
        $billingPeriodEnd = null;
        $billingRequest = null;

        $nextBillingPeriod = $this->getNextBillingPeriod($billingAgreement);

        if (null !== $nextBillingPeriod) {

            list($billingPeriodStart, $billingPeriodEnd) = $nextBillingPeriod;

            $billingRequest = $this->billingManager->generateBillingRequest($billingAgreement);
            $billingRequest->setPeriodStart($billingPeriodStart);
            $billingRequest->setPeriodEnd($billingPeriodEnd);

            //Determine when the billing request needs to be paid
            if ($this->config['billing_request_payment_phase'] == 'end') {
                $plannedBillingDate = $billingPeriodEnd->add(new \DateInterval('P1D'));  //Add one day
            } else if ($this->config['billing_request_payment_phase'] == 'start') {
                $plannedBillingDate = $billingPeriodStart;
            } else {
                throw new \Exception('billing_request_payment_phase option "' .  $this->config['billing_request_payment_phase'] . '" is unknown');
            }
            $billingRequest->setPlannedBillingDate($plannedBillingDate);

            //After we've created a billing request we need to update the billed-to date of the billing agreement
            $billingAgreement->setBilledToDate($billingPeriodEnd);
        }

        return $billingRequest;
    }
public function generateNext(BillingAgreementInterface $billingAgreement)
    {
        $billingPeriodStart = null;
        $billingPeriodEnd = null;
        $billingRequest = null;

        $nextBillingPeriod = $this->getNextBillingPeriod($billingAgreement);

        if (null !== $nextBillingPeriod) {

            list($billingPeriodStart, $billingPeriodEnd) = $nextBillingPeriod;

            $billingRequest = $this->billingManager->generateBillingRequest($billingAgreement);
            $billingRequest->setPeriodStart($billingPeriodStart);
            $billingRequest->setPeriodEnd($billingPeriodEnd);

            //Determine when the billing request needs to be paid
            if ($this->config['billing_request_payment_phase'] == 'end') {
                $plannedBillingDate = $billingPeriodEnd->add(new \DateInterval('P1D'));  //Add one day
            } else if ($this->config['billing_request_payment_phase'] == 'start') {
                $plannedBillingDate = $billingPeriodStart;
            } else {
                throw new \Exception('billing_request_payment_phase option "' .  $this->config['billing_request_payment_phase'] . '" is unknown');
            }
            $billingRequest->setPlannedBillingDate($plannedBillingDate);

            //After we've created a billing request we need to update the billed-to date of the billing agreement
            $billingAgreement->setBilledToDate($billingPeriodEnd);
        }

        return $billingRequest;
    }
public function generateNext ( BillingAgreementInterface $ billingAgreement ) { $ billingPeriodStart = null ; $ billingPeriodEnd = null ; $ billingRequest = null ; $ nextBillingPeriod = $ this -> getNextBillingPeriod ( $ billingAgreement ) ; if ( null !== $ nextBillingPeriod ) { list ( $ billingPeriodStart , $ billingPeriodEnd ) = $ nextBillingPeriod ; $ billingRequest = $ this -> billingManager -> generateBillingRequest ( $ billingAgreement ) ; $ billingRequest -> setPeriodStart ( $ billingPeriodStart ) ; $ billingRequest -> setPeriodEnd ( $ billingPeriodEnd ) ; //Determine when the billing request needs to be paid if ( $ this -> config [ 'billing_request_payment_phase' ] == 'end' ) { $ plannedBillingDate = $ billingPeriodEnd -> add ( new \ DateInterval ( 'P1D' ) ) ; //Add one day } else if ( $ this -> config [ 'billing_request_payment_phase' ] == 'start' ) { $ plannedBillingDate = $ billingPeriodStart ; } else { throw new \ Exception ( 'billing_request_payment_phase option "' . $ this -> config [ 'billing_request_payment_phase' ] . '" is unknown' ) ; } $ billingRequest -> setPlannedBillingDate ( $ plannedBillingDate ) ; //After we've created a billing request we need to update the billed-to date of the billing agreement $ billingAgreement -> setBilledToDate ( $ billingPeriodEnd ) ; } return $ billingRequest ; }
Generate the next billing request for provided billing agreement

@param BillingAgreementInterface $billingAgreement
@return mixed
Generate the next billing request for provided billing agreement