Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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;
 }