/** * Add a subscription to a plan * * @param \Kairos\SubscriptionBundle\Model\SubscriptionInterface $subscription * @return \Kairos\SubscriptionBundle\Model\PlanInterface */ public function addSubscription(\Kairos\SubscriptionBundle\Model\SubscriptionInterface $subscription) { $subscription->setPlan($this); $this->subscriptions[] = $subscription; return $this; }
/** * @param SubscriptionInterface $subscription * @param array $options * @return array */ public function serializeSubscription(SubscriptionInterface $subscription, $options = array()) { $result = array(); if ($subscription->getPlan() && $subscription->getPlan()->getSubscriptionPlanId()) { $result['planId'] = $subscription->getPlan()->getSubscriptionPlanId(); } if ($subscription->getCustomer() && count($subscription->getCustomer()->getCreditCards()) > 0) { $cards = $subscription->getCustomer()->getCreditCards(); //In case there is no default card, take the first $result['paymentMethodToken'] = $cards->first()->getToken(); //set default credit card as default foreach ($cards as $card) { if ($card->isDefault()) { $result['paymentMethodToken'] = $card->getToken(); } } } if (count($options) > 0) { $result['options'] = $options; } return $result; }
/** * Set subscription * * @param $subscription * @return $this */ public function setSubscription(\Kairos\SubscriptionBundle\Model\SubscriptionInterface $subscription) { $this->subscription = $subscription; $subscription->setCustomer($this); return $this; }