/** * 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); }
public function getInstance() { global $module_params; $methodType = $module_params['param05']; if (!$this->_instance) { switch ($methodType) { case 'yes': $this->_instance = CheckoutApi_Lib_Factory::getInstance('model_methods_creditcardpci'); break; default: $this->_instance = CheckoutApi_Lib_Factory::getInstance('model_methods_creditcard'); break; } } return $this->_instance; }
function getInstance($methodType = null) { global $sql_tbl; $payment_cc_data = cko_config(); if (!$methodType) { $methodType = $payment_cc_data['param05']; switch ($methodType) { case 'yes': $instance = CheckoutApi_Lib_Factory::getInstance('model_methods_creditcardpci'); break; default: $instance = CheckoutApi_Lib_Factory::getInstance('model_methods_creditcard'); break; } } return $instance; }
/** * Convert a json to a CheckoutApi_Lib_RespondObj object * @param JSON $parser * @return CheckoutApi_Lib_RespondObj|null * @throws Exception */ public function parseToObj($parser) { /** @var CheckoutApi_Lib_RespondObj $respondObj */ $respondObj = CheckoutApi_Lib_Factory::getInstance('CheckoutApi_Lib_RespondObj'); if ($parser && is_string($parser)) { $encoding = mb_detect_encoding($parser); if ($encoding == "ASCII") { $parser = iconv('ASCII', 'UTF-8', $parser); } else { $parser = mb_convert_encoding($parser, "UTF-8", $encoding); } $jsonObj = json_decode($parser, true); $jsonObj['rawOutput'] = $parser; $respondObj->setConfig($jsonObj); } $respondObj->setConfig($this->getResourceInfo()); return $respondObj; }
/** * 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); }