Пример #1
0
 /**
  * Creates a seller contact.
  *
  * @param int $seller_id Seller ID.
  *
  * @return void
  */
 public function post_index($seller_id = null)
 {
     $validator = \Validation_Contact::create('seller');
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $contact = \Service_Contact::create($data);
     if (!$contact) {
         throw new HttpServerErrorException();
     }
     if (!\Service_Contact::link($contact, \Seller::active(), \Arr::get($data, 'primary', false))) {
         throw new HttpServerErrorException();
     }
     $this->response($contact);
 }
Пример #2
0
 /**
  * Creates a new payment method.
  *
  * @param Model_Customer $customer The customer the payment method belongs to.
  * @param array          $data   Optional data.
  *
  * @return Model_Customer_Paymentmethod
  */
 public static function create(Model_Customer $customer, Model_Gateway $gateway, array $data = array())
 {
     if (!($account = Arr::get($data, 'account'))) {
         return false;
     }
     if (!($contact = Arr::get($data, 'contact'))) {
         return false;
     }
     // Find or create the payment method's contact.
     if (is_numeric($contact)) {
         $contact = Service_Contact::find_one($contact);
     } elseif (is_array($contact)) {
         $contact = Service_Contact::create($contact);
     }
     if (!$contact) {
         return false;
     }
     $payment_method = Model_Customer_Paymentmethod::forge();
     $payment_method->customer = $customer;
     $payment_method->contact = $contact;
     $payment_method->gateway = $gateway;
     $payment_method->provider = Arr::get($data, 'account.provider');
     $payment_method->account = '****' . substr(Arr::get($data, 'account.number'), -4);
     $gateway_instance = Gateway::instance($gateway, $customer);
     if ($gateway_instance) {
         $gateway_payment_method_id = $gateway_instance->paymentmethod()->create(array('account' => $account, 'contact' => $contact));
         if (!$gateway_payment_method_id) {
             return false;
         }
         $gateway_payment_method = $gateway_instance->paymentmethod($gateway_payment_method_id);
         $payment_method->external_id = $gateway_payment_method->data('id');
     }
     try {
         $payment_method->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     // Set as primary if customer has none.
     $primary = self::primary($customer);
     if (Arr::get($data, 'primary') || empty($primary)) {
         self::set_primary($payment_method);
     }
     Service_Event::trigger('customer.paymentmethod.create', $payment_method->customer->seller, $payment_method->to_array());
     return $payment_method;
 }
Пример #3
0
 /**
  * Creates a new seller.
  *
  * @param string $name The name of the seller.
  * @param array  $data Optional data.
  *
  * @return Model_Seller
  */
 public static function create($name, array $data = array())
 {
     if (!($contact_data = Arr::get($data, 'contact'))) {
         return false;
     }
     $seller = Model_Seller::forge();
     $seller->name = $name;
     $seller->populate($data);
     try {
         $seller->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     $contact = Service_Contact::create($contact_data);
     if (!$contact || !Service_Contact::link($contact, $seller, true)) {
         return false;
     }
     return $seller;
 }
Пример #4
0
 /**
  * Creates a new customer.
  *
  * @param Model_Seller  $seller The seller the customer belongs to.
  * @param array         $data   Optional data.
  *
  * @return Model_Customer
  */
 public static function create(Model_Seller $seller, array $data = array())
 {
     if (!($contact_data = Arr::get($data, 'contact'))) {
         return false;
     }
     $customer = Model_Customer::forge();
     $customer->seller = $seller;
     $customer->populate($data);
     try {
         $customer->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     $contact = Service_Contact::create($contact_data);
     if (!$contact || !Service_Contact::link($contact, $customer, true)) {
         return false;
     }
     Service_Event::trigger('customer.create', $customer->seller, $customer->to_array());
     return $customer;
 }
Пример #5
0
 /**
  * POST create action.
  * 
  * @return void
  */
 public function post_create()
 {
     $this->get_create();
     $contact = new Model_Contact();
     $contact->populate(Input::post());
     $validator = Validation_Contact::create('seller');
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $data = $validator->validated();
     $data['first_name'] = '';
     $data['last_name'] = '';
     if (!($new_contact = Service_Contact::create($data))) {
         Session::set_alert('error', 'There was an error creating the contact.');
         return;
     }
     Service_Contact::link($new_contact, Seller::active());
     Session::set_alert('success', 'The contact has been created.');
     Response::redirect('settings/contacts');
 }