Ejemplo n.º 1
0
 /**
  * Subscribe to the plan for the first time.
  *
  * @param  string  $token
  * @param  array   $properties
  * @param  object|null  $customer
  * @return void
  */
 public function create($token, array $properties = [], $customer = null)
 {
     $freshCustomer = false;
     if (!$customer) {
         $customer = $this->createGatewayCustomer($token, $properties);
         $freshCustomer = true;
     } elseif (!is_null($token)) {
         $this->updateCard($token);
     }
     $this->billable->setGatewaySubscription($customer->updateSubscription($this->buildPayload())->id);
     $customer = $this->getGatewayCustomer($customer->id);
     if ($freshCustomer && ($trialEnd = $this->getTrialEndForCustomer($customer))) {
         $this->billable->setTrialEndDate($trialEnd);
     }
     $this->updateLocalGatewayData($customer);
 }