Example #1
0
 /**
  * create a card holder account on the stripe system
  *
  * (non-PHPdoc)
  *
  * @see \PhalconRest\Libraries\Payments\Processor::createCustomer()
  */
 public function createCustomer(\PhalconRest\Models\Accounts $account)
 {
     // check that this customer doesn't already exist
     // skip cache to be sure the latest record is pulled
     if ($account->external_id) {
         $customer = $this->findCustomer($account->external_id);
         // match found, no need to create a new customer record
         if ($customer) {
             $this->cachedCustomers[$account->external_id] = $customer;
             return $account->external_id;
         }
     }
     try {
         $result = \Stripe\Customer::create(array("description" => $account->id));
     } catch (\Stripe\Error\Base $e) {
         $this->handleStripeError($e);
     }
     $account->external_id = $result->id;
     if (!$account->save()) {
         throw new HTTPException("Could not save Payment Information for account", 404, array('code' => 1872391762862, 'dev' => 'StripeAdapter->createCustomer failed to save external_id: ' . $result->id), $account->getMessages());
         return false;
     }
     return $result->id;
 }