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
 /**
  * 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 #3
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 #4
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 #5
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;
 }
 /**
  * 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 #7
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;
 }