public function transaction($userId, $planId) { $user = new User($userId); $plan = new Plan($planId); $request = $this->getRequest()->request; $planPeriodId = $request->get('plan_period'); $planPeriod = new Plans_period($planPeriodId); $systemId = $request->get('system'); $system = new Payment_gateways($systemId); $interval = new DateInterval('P' . $planPeriod->period . ucwords($planPeriod->qualifier)); /* @var Core\Service\Subscriber\Subscriber $subscriber */ $subscriber = $this->get('core.subscriber'); $subscriber->setUser($user); if (!($planPeriod->price == 0 && $plan->isTrial())) { $transactionManager = $this->get('core.payment.transactions.manager'); $transaction = $transactionManager->createForSubscription(array('amount' => $planPeriod->price, 'description' => 'subscribe on ' . $plan->name), $user, $system); } else { $subscriber->addTrialSubscription($plan, $interval); if (!$this->ion_auth->logged_in()) { $this->ion_auth->loginForce($user->email, true); } redirect('dashboard'); } $subscriber->addNewSubscription($transaction, $plan, $interval); if (!$this->ion_auth->logged_in()) { $this->ion_auth->loginForce($user->email, true); } redirect('payment/pay/' . $transaction->id . '/' . $planPeriodId); }