예제 #1
0
 /**
  * Updates a seller contact.
  *
  * @param int $seller_id Seller ID.
  * @param int $id        Contact ID.
  *
  * @return void
  */
 public function put_index($seller_id = null, $id = null)
 {
     $contact = $this->get_contact($id);
     $validator = \Validation_Contact::update('seller');
     if (!$validator->run(\Input::put())) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $contact = \Service_Contact::update($contact, $data);
     if (!$contact) {
         throw new HttpServerErrorException();
     }
     $this->response($contact);
 }
예제 #2
0
 /**
  * POST Edit action.
  *
  * @param int $id Contact ID.
  *
  * @return void
  */
 public function post_edit($id = null)
 {
     $this->get_edit($id);
     $validator = Validation_Contact::update();
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $contact = $this->get_contact($id);
     $data = $validator->validated();
     if (!Service_Contact::update($contact, $data)) {
         Session::set_alert('error', 'There was an error updating the contact.');
         return;
     }
     Session::set_alert('success', 'The contact has been updated.');
     Response::redirect('settings/contacts');
 }
예제 #3
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;
 }