Beispiel #1
0
 /**
  * POST Create action.
  *
  * @param int $customer_id Customer ID.
  *
  * @return void
  */
 public function post_create($customer_id = null)
 {
     $this->get_create($customer_id);
     $gateway = $this->get_gateway();
     $validator = Validation_Customer_Paymentmethod::create($gateway);
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $data = $validator->validated();
     $customer = $this->get_customer($customer_id);
     if (!Service_Customer_Paymentmethod::create($customer, $gateway, $data)) {
         Session::set_alert('error', 'There was an error adding the customer payment method.');
         return;
     }
     Session::set_alert('success', 'The customer payment method has been added.');
     Response::redirect($customer->link('paymentmethods'));
 }
Beispiel #2
0
 /**
  * Creates a payment method.
  *
  * @param int $customer_id Customer ID.
  *
  * @return void
  */
 public function post_index($customer_id = null)
 {
     $customer = $this->get_customer($customer_id);
     $gateway_args = array('seller' => \Seller::active());
     if ($seller_gateway_id = \Input::post('seller_gateway_id')) {
         $gateway_args['id'] = $seller_gateway_id;
     }
     $gateway = \Service_Gateway::find_one($gateway_args);
     $validator = \Validation_Customer_Paymentmethod::create($gateway);
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $payment_method = \Service_Customer_Paymentmethod::create($customer, $gateway, $data);
     if (!$payment_method) {
         throw new HttpServerErrorException();
     }
     $this->response($payment_method);
 }
Beispiel #3
0
 /**
  * Generates customers.
  *
  * @return void
  */
 protected static function customers()
 {
     $balances = array(0, 5, 10, 12.5, 24.3);
     $first_names = array('Daniel', 'Steve', 'Elon', 'Bill', 'Stephan', 'Olivia', 'Keithia', 'Caroline', 'Porschia', 'Marie');
     $last_names = array('Sposito', 'Manos', 'Myers', 'Jenkins', 'Gates', 'Jobs', 'Musk', 'Wyrick', 'Natalie', 'Stevens');
     $streets = array('Wisteria Ln', 'Pebble Creek Blvd', 'Bakerstreet Dr', 'Miranda Point', 'Infinite Loop');
     $cities = array('Oklahoma City', 'Phoenix', 'Palo Alto', 'Saigon', 'Caracas');
     $states = array('OK', 'NY', 'CA', 'WA', 'FL');
     $countries = array('US', 'VN', 'VE');
     $customers = array();
     for ($i = 1; $i <= self::TOTAL_CUSTOMERS; $i++) {
         $first_name = $first_names[array_rand($first_names)];
         $last_name = $last_names[array_rand($last_names)];
         // Random created_at between the begin date and now.
         $date = date("Y-m-d H:i:s", mt_rand(self::BEGIN_DATETIME, time()));
         $customers[] = array('balance' => $balances[array_rand($balances)], 'contact' => array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $first_name . '.' . $last_name . mt_rand(1, 100) . '@gmail.com', 'address' => mt_rand(1, 5000) . ' ' . $streets[array_rand($streets)], 'city' => $cities[array_rand($cities)], 'state' => $states[array_rand($states)], 'zip' => mt_rand(10000, 99999), 'country' => $countries[array_rand($countries)]), 'status' => mt_rand(1, 10) <= 8 ? 'active' : 'deleted', 'created_at' => $date);
     }
     foreach ($customers as $data) {
         $seller = self::$sellers[array_rand(self::$sellers)];
         $customer = \Service_Customer::create($seller, $data);
         // Create a payment method for the faux customer.
         $payment_method = \Service_Customer_Paymentmethod::create($customer, self::$gateway, array('contact' => $data['contact'], 'account' => array('provider' => 'Volcano', 'number' => '6011000000000012', 'expiration_month' => '12', 'expiration_year' => '5')));
         // Subscribe a random number of customers to a product option.
         if ($customer && mt_rand(1, 10) >= 5) {
             $option = self::$product_options[$seller->id][array_rand(self::$product_options[$seller->id])];
             $order = \Service_Customer_Order::create($customer, array($option->id => 'My ' . \Str::random('alpha', 5)), null, array('created_at' => $customer->created_at));
             // Reset the order's updated_at.
             self::updateUpdatedAt($order);
         }
         // Reset the models' updated_at.
         self::updateUpdatedAt($customer);
         foreach ($customer->products as $product) {
             self::updateUpdatedAt($product);
         }
     }
     \Cli::write('Customer Simulation Complete', 'green');
 }