Exemple #1
0
 /**
  * Creates a new customer transaction.
  *
  * @param Model_Customer_Paymentmethod $payment_method The payment method.
  * @param string                       $amount         The amount to transact.
  * @param array                        $data           Optional data.
  *
  * @return Model_Customer_Transaction
  */
 public static function create(Model_Customer_Paymentmethod $payment_method, $amount, array $data = array())
 {
     $gateway_instance = Gateway::instance($payment_method->gateway, $payment_method->customer);
     if ($gateway_instance) {
         $external_id = $gateway_instance->transaction()->create(array('payment_method' => $payment_method, 'amount' => $amount));
         if (!$external_id) {
             return false;
         }
     } else {
         $external_id = null;
     }
     $transaction = Model_Customer_Transaction::forge();
     $transaction->customer = $payment_method->customer;
     $transaction->gateway = $payment_method->gateway;
     $transaction->external_id = $external_id;
     $transaction->type = $payment_method->gateway->type;
     $transaction->provider = $payment_method->provider;
     $transaction->account = $payment_method->account;
     $transaction->amount = $amount;
     try {
         $transaction->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('customer.transaction.create', $transaction->customer->seller, $transaction->to_array());
     return $transaction;
 }
Exemple #2
0
 /**
  * Seeds the database with initial data.
  *
  * @return void
  */
 public static function seed()
 {
     \Config::load('events', true);
     $events = \Config::get('events');
     foreach ($events as $event) {
         \Service_Event::create($event);
     }
     \Cli::write('Database Seeding Complete', 'green');
 }
Exemple #3
0
 /**
  * Updates a product meta option.
  *
  * @param Model_Product_Meta_Option $option The product meta option to update.
  * @param array                     $data   The data to use to update the product meta option.
  *
  * @return Model_Product_Meta_Option
  */
 public static function update(Model_Product_Meta_Option $option, array $data = array())
 {
     $option->populate($data);
     try {
         $option->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('product.meta.option.update', $option->meta->product->seller, $option->to_array());
     return $option;
 }
Exemple #4
0
 /**
  * Creates a seller callback.
  *
  * @param int $seller_id Seller ID.
  *
  * @return void
  */
 public function post_index($seller_id = null)
 {
     $validator = \Validation_Seller_Callback::create();
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $event = \Service_Event::find_one(array('name' => $data['event']));
     $callback = \Service_Seller_Callback::create(\Seller::active(), $event, $data['url']);
     if (!$callback) {
         throw new HttpServerErrorException();
     }
     $this->response($callback);
 }
Exemple #5
0
 /**
  * Creates a new statistic.
  *
  * @param Model_Seller $seller The seller the statistic belongs to.
  * @param string       $type   The type of statistic (customer, product, etc).
  * @param Date         $date   Date.
  * @param string       $name   Name.
  * @param string       $value  Value.
  *
  * @return Model_Statistic
  */
 public static function create(Model_Seller $seller, $type, Date $date, $name, $value)
 {
     $statistic = Model_Statistic::forge();
     $statistic->seller = $seller;
     $statistic->type = $type;
     $statistic->name = $name;
     $statistic->value = $value;
     $statistic->date = $date->format('mysql_date');
     try {
         $statistic->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('statistic.create', $statistic->seller, $statistic->to_array());
     return $statistic;
 }
Exemple #6
0
 /**
  * Updates a seller callback.
  *
  * @param Model_Seller_Callback $callback The seller callback to update.
  * @param array                 $data     The data to use to update the seller callback.
  *
  * @return Model_Seller_Callback
  */
 public static function update(Model_Seller_Callback $callback, array $data = array())
 {
     if ($event_name = Arr::get($data, 'event')) {
         $event = \Service_Event::find_one(array('name' => $event_name));
         if (!$event) {
             return false;
         }
         $callback->event = $event;
     }
     $callback->populate($data);
     try {
         $callback->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     return $callback;
 }
Exemple #7
0
 /**
  * Creates a new validation instance for seller callback update.
  *
  * @return Validation
  */
 public static function update()
 {
     $validator = Validation::forge('callback');
     $input = Input::param();
     if (array_key_exists('event', $input)) {
         $validator->add('event', 'Event Name')->add_rule('trim')->add_rule('required')->add_rule(array('invalid_event_name' => function ($event_name) {
             $event = Service_Event::find_one(array('name' => $event_name));
             if (!$event) {
                 return false;
             }
             return true;
         }));
     }
     if (array_key_exists('url', $input)) {
         $validator->add('url', 'Callback URL')->add_rule('trim')->add_rule('valid_url')->add_rule('required');
     }
     return $validator;
 }
Exemple #8
0
 /**
  * Updates a customer order.
  *
  * @param Model_Customer_Order $order The order to update.
  * @param array                $data  The data to use to update the order.
  *
  * @return Model_Customer_Order
  */
 public static function update(Model_Customer_Order $order, array $data = array())
 {
     $order->populate($data);
     try {
         $order->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('customer.order.update', $order->customer->seller, $order->to_array());
     return $order;
 }
Exemple #9
0
 /**
  * Deletes a product option.
  *
  * @param Model_Product_Option $option The product option to delete.
  *
  * @return bool
  */
 public static function delete(Model_Product_Option $option)
 {
     $option->status = 'deleted';
     try {
         $option->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('product.option.delete', $option->product->seller, $option->to_array());
     return true;
 }
Exemple #10
0
 /**
  * GET Edit action.
  *
  * @param int $id Seller callback ID.
  *
  * @return void
  */
 public function get_edit($id = null)
 {
     $this->view->callback = $this->get_callback($id);
     $this->view->events = Service_Event::find();
 }
Exemple #11
0
 /**
  * Deletes a payment method.
  *
  * @param Model_Customer_Paymentmethod $payment_method The payment method to delete.
  *
  * @return bool
  */
 public static function delete(Model_Customer_Paymentmethod $payment_method)
 {
     // A primary payment method cannot be deleted.
     if ($payment_method->primary()) {
         return false;
     }
     $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;
         }
         if (!$gateway_payment_method->delete()) {
             return false;
         }
     }
     $payment_method->status = 'deleted';
     try {
         $payment_method->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('customer.paymentmethod.delete', $payment_method->customer->seller, $payment_method->to_array());
     return true;
 }
Exemple #12
0
 /**
  * Deletes a customer.
  *
  * @param Model_Customer $customer The customer to delete.
  *
  * @return bool
  */
 public static function delete(Model_Customer $customer)
 {
     $customer->status = 'deleted';
     try {
         $customer->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('customer.delete', $customer->seller, $customer->to_array());
     return true;
 }