Ejemplo n.º 1
0
 /**
  *
  * Initialize object
  *
  * @return class
  *
  **/
 public static function init(array $data, array $option = array(), $environment = Environments::STAGING_URL)
 {
     # Instance.
     $self = new self();
     # Validate data.
     $self->validateData($data);
     # Set Enviroment.
     $self->environment = $environment;
     $self->path = Operations::PREAUTHORIZATION_URL;
     # Configure extra data.
     if (isset($option['return_url']) and $option['return_url'] !== "") {
         $data['return_url'] = $option['return_url'];
     } else {
         $data['return_url'] = Config::get('return_url');
     }
     if (isset($option['cancel_url']) and $option['cancel_url'] !== "") {
         $data['cancel_url'] = $option['cancel_url'];
     } else {
         $data['cancel_url'] = Config::get('cancel_url');
     }
     # Attach data.
     foreach ($data as $key => $value) {
         $self->addData($key, $value);
     }
     # Generate token.
     $self->getToken('pre_authorization');
     # Create operation array.
     $self->makeOperationObject();
     return $self;
 }
Ejemplo n.º 2
0
 /**
  *
  * Initialize object
  *
  * @return class
  *
  **/
 public static function init(array $data, $environment = Environments::STAGING_URL)
 {
     # Instance.
     $self = new self();
     # Validate data.
     $self->validateData($data);
     # Set Enviroment.
     $self->environment = $environment;
     $self->path = Operations::PREAUTHORIZATION_URL;
     # Configure extra data.
     $data['return_url'] = Config::get('return_url');
     $data['cancel_url'] = Config::get('cancel_url');
     # Attach data.
     foreach ($data as $key => $value) {
         $self->addData($key, $value);
     }
     # Generate token.
     $self->getToken('single_buy');
     # Create operation array.
     $self->makeOperationObject();
     return $self;
 }
Ejemplo n.º 3
0
 /**
  *
  * Prepare url and post data to Bancard configured enviroment url.
  * If successful sets up redirect url.
  * Raise exception on error.
  *
  * @return bool
  *
  **/
 protected function post()
 {
     $this->url = $this->environment . $this->path;
     $this->response_data = HTTP::post($this->url, $this->json());
     if (!$this->response_data) {
         throw new \RuntimeException("No response data was found.");
     }
     $this->response = $this->response();
     if ($this->response->status == "error") {
         throw new \Exception("[" . $this->response->messages[0]->key . "] " . $this->response->messages[0]->dsc);
     }
     if (!empty($this->response()->process_id)) {
         $this->redirect_to = $this->environment . Config::get("redirect_path") . "?process_id=" . $this->response()->process_id;
     }
     return true;
 }