Esempio n. 1
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);
 }
Esempio n. 2
0
 /**
  * Attempts to get a seller's primary gateway.
  *
  * @return Model_Gateway
  */
 public function get_gateway()
 {
     $gateway = Service_Gateway::find_one(array('seller' => Seller::active()));
     if (!$gateway) {
         throw new HttpNotFoundException();
     }
     return $gateway;
 }
Esempio n. 3
0
 /**
  * Attempts to get a gateway from a given ID.
  *
  * @param int $id Gateway ID.
  *
  * @return \Model_Gateway
  */
 protected function get_gateway($id)
 {
     if (!$id) {
         throw new HttpNotFoundException();
     }
     $gateway = \Service_Gateway::find_one(array('id' => $id, 'seller' => \Seller::active()));
     if (!$gateway) {
         throw new HttpNotFoundException();
     }
     return $gateway;
 }