Exemple #1
0
 public function contactAction()
 {
     $service = new Service_Contact();
     if ($data = $this->_request->getPost()) {
         $service->send($data);
     }
     $this->view->message = $service->getMessage();
     $this->view->form = $service->getForm();
 }
 /**
  * GET Create action.
  *
  * @param int $customer_id Customer ID.
  *
  * @return void
  */
 public function get_create($customer_id = null)
 {
     $customer = $this->get_customer($customer_id);
     $this->view->customer = $customer;
     $this->view->contact = Service_Contact::primary($customer);
     $this->view->gateway = $this->get_gateway();
 }
Exemple #3
0
 /**
  * Attempts to get a contact from a given ID.
  *
  * @param int $id Contact ID.
  *
  * @return Model_Contact
  */
 protected function get_contact($customer_id, $id)
 {
     $customer = $this->get_customer($customer_id);
     if ($customer->seller != Seller::active()) {
         throw new HttpNotFoundException();
     }
     $contact = Service_Contact::find_one($id);
     if (!$contact || $contact != Service_Contact::primary($customer)) {
         throw new HttpNotFoundException();
     }
     return $contact;
 }
Exemple #4
0
 /**
  * Primary contact helper function.
  *
  * @param string|array $properties One or more contact properties to return.
  *
  * @return string
  */
 public function contact($properties = null)
 {
     $contact = Service_Contact::primary($this);
     if (!$contact) {
         return false;
     }
     if ($properties) {
         $data = array();
         $properties = (array) $properties;
         foreach ($properties as $property) {
             $data[] = $contact->{$property};
         }
         return implode(' ', $data);
     }
     return $contact;
 }
Exemple #5
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;
 }
 /**
  * Validates contact data.
  *
  * @param array  $data   Contact data to validate.
  * @param string $type   Contact type.
  * @param string $action Type of contact validation (create or update).
  *
  * @return bool
  */
 public function _validation_contact($data, $type = 'customer', $action = 'create')
 {
     // Allow an existing contact ID to be used for payment methods.
     if ($type == 'paymentmethod' && is_numeric($data)) {
         if (Service_Contact::find_one($data)) {
             return true;
         } else {
             return false;
         }
     }
     $data = !is_array($data) ? (array) $data : $data;
     if (!in_array($action, array('create', 'update'))) {
         return false;
     }
     $validator = Validation_Contact::$action($type);
     if (!$validator->run($data)) {
         $this->set_message('contact', array_keys($validator->errors));
         return false;
     }
     return true;
 }
Exemple #7
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;
 }
Exemple #8
0
 /**
  * Attempts to get a contact from a given ID.
  *
  * @param int $id Contact ID.
  *
  * @return Model_Contact
  */
 protected function get_contact($id)
 {
     $contact = Service_Contact::find_one($id);
     if (!$contact || !in_array($contact, Seller::active()->contacts)) {
         throw new HttpNotFoundException();
     }
     return $contact;
 }
 /**
  * Updates a payment method.
  *
  * @param Model_Customer_Paymentmethod $payment_method The payment method to update.
  * @param array                        $data           The data to use to update the payment method.
  *
  * @return Model_Customer_Paymentmethod
  */
 public static function update(Model_Customer_Paymentmethod $payment_method, array $data = array())
 {
     if (!($account = Arr::get($data, 'account'))) {
         return false;
     }
     if (!($contact = Arr::get($data, 'contact'))) {
         return false;
     }
     if (is_numeric($contact)) {
         $contact = Service_Contact::find_one($contact);
         if (!$contact) {
             return false;
         }
         $data['contact'] = $contact;
     }
     $gateway = $payment_method->gateway;
     $customer = $payment_method->customer;
     $gateway_instance = Gateway::instance($gateway, $customer);
     if ($gateway_instance) {
         $gateway_payment_method = $gateway_instance->paymentmethod($payment_method->external_id);
         if (!$gateway_payment_method) {
             return false;
         }
         $updated = $gateway_payment_method->update($data);
         if (!$updated) {
             return false;
         }
         $gateway_payment_method = $gateway_instance->paymentmethod($payment_method->external_id);
         $payment_method->account = $gateway_payment_method->data('account');
     }
     // Update the model.
     $payment_method->provider = Arr::get($account, 'provider');
     if ($contact instanceof Model_Contact) {
         $payment_method->contact = $contact;
     } else {
         Service_Contact::update($payment_method->contact, $contact);
     }
     try {
         $payment_method->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     if (Arr::get($data, 'primary')) {
         self::set_primary($payment_method);
     }
     Service_Event::trigger('customer.paymentmethod.update', $payment_method->customer->seller, $payment_method->to_array());
     return $payment_method;
 }
Exemple #10
0
 /**
  * Attempts to get a contact from a given ID.
  *
  * @param int $id Contact ID.
  *
  * @return \Model_Contact
  */
 protected function get_contact($id)
 {
     if (!$id) {
         throw new HttpNotFoundException();
     }
     $contact = \Service_Contact::find_one($id);
     if (!$contact || !\Arr::key_exists(\Seller::active()->contacts, $contact->id)) {
         throw new HttpNotFoundException();
     }
     return $contact;
 }
Exemple #11
0
 /**
  * Attempts to get a contact from a given ID.
  *
  * @param int             $id       Contact ID.
  * @param \Model_Customer $customer Customer the contact should belong to.
  *
  * @return \Model_Contact
  */
 protected function get_contact($id, \Model_Customer $customer)
 {
     if (!$id) {
         throw new HttpNotFoundException();
     }
     $contact = \Service_Contact::find_one($id);
     if (!$contact || !\Arr::key_exists($customer->contacts, $contact->id)) {
         throw new HttpNotFoundException();
     }
     return $contact;
 }