Esempio n. 1
0
 /**
  * Get Stripe customer ID for the user
  * @return string|boolean
  */
 public function getCustomerId()
 {
     $customer_id = $this->user->getPrivateSetting('stripe_customer_id');
     if (!$customer_id) {
         $stripe = new StripeClient();
         // Try other customer IDs stored on this user
         $customer_ids = $this->user->stripe_customer_id;
         if ($customer_ids) {
             if (!is_array($customer_ids)) {
                 $customer_ids = array($customer_ids);
             }
             foreach ($customer_ids as $customer_id) {
                 $account = $stripe->getCustomer($customer_id);
                 if ($account) {
                     break;
                 }
             }
         }
         if (!$account) {
             $account = $stripe->createCustomer($this->user);
         }
         $customer_id = $account->id;
         $this->user->setPrivateSetting('stripe_customer_id', $customer_id);
     }
     return $customer_id;
 }