/** * Helper static function to get singleton instance of a gateway interface. * @param array $arguments A set arguments for initialising class constructor. * @param null|string $_apiClass Gateway class name. * @return CheckoutApi_Client_Client An singleton instance of CheckoutApi_Client_Client * @throws Exception */ public static function getApi(array $arguments = array(), $_apiClass = null) { if ($_apiClass) { self::setApiClass($_apiClass); } return CheckoutApi_Lib_Factory::getSingletonInstance(self::getApiClass(), $arguments); }
/** * Build up the request to the gateway * @param string $uri endpoint to be used * @param array $param payload param * @param boolean $state if error occured don't send charge * @return CheckoutApi_Lib_RespondObj * @throws Exception */ public function request($uri, array $param, $state) { /** @var CheckoutApi_Lib_RespondObj $respond */ $respond = CheckoutApi_Lib_Factory::getSingletonInstance('CheckoutApi_Lib_RespondObj'); $this->setConfig($param); if (!isset($param['postedParam'])) { $param['postedParam'] = array(); } $param['rawpostedParam'] = $param['postedParam']; $param['postedParam'] = $this->getParser()->preparePosted($param['postedParam']); $respondArray = null; if ($state) { $headers = $this->initHeader(); $param['headers'] = $headers; /** @var CheckoutApi_Client_Adapter_Abstract $adapter */ $adapter = $this->getAdapter($this->getProcessType(), array('uri' => $uri, 'config' => $param)); if ($adapter) { $adapter->connect(); $respondString = $adapter->request()->getRespond(); $statusResponse = $adapter->getResourceInfo(); $this->getParser()->setResourceInfo($statusResponse); $respond = $this->getParser()->parseToObj($respondString); if ($respond && isset($respond['errors']) && $respond->hasErrors()) { /** @var CheckoutApi_Lib_ExceptionState $exceptionStateObj */ $exceptionStateObj = $respond->getExceptionState(); $errors = $respond->getErrors()->toArray(); $exceptionStateObj->flushState(); foreach ($errors as $error) { $this->throwException($error, $respond->getErrors()->toArray()); } } elseif ($respond && isset($respond['errorCode']) && $respond->hasErrorCode()) { /** @var CheckoutApi_Lib_ExceptionState $exceptionStateObj */ $exceptionStateObj = $respond->getExceptionState(); $this->throwException($respond->getMessage(), $respond->toArray()); } elseif ($respond && $respond->getHttpStatus() != '200') { $this->throwException('Gateway is temporary down', $param); } $adapter->close(); } } return $respond; }
/** * Return an instance of CheckoutApi_Lib_ExceptionState * @return CheckoutApi_Lib_ExceptionState|null * @throws Exception * */ public function getExceptionState() { $classException = "CheckoutApi_Lib_ExceptionState"; $class = null; if (class_exists($classException)) { /** @var CheckoutApi_Lib_ExceptionState $class */ $class = CheckoutApi_Lib_Factory::getSingletonInstance($classException); } return $class; }
/** * create and set a parser * @throws Exception */ public function initParser() { $parserType = CheckoutApi_Client_Constant::PARSER_CLASS_GROUP . $this->getRespondType(); $parserObj = CheckoutApi_Lib_Factory::getSingletonInstance($parserType); $this->setParser($parserObj); }