Skip to content

Commit

Permalink
Remove submodule. Move CheckoutApi to root.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-maalouf-cko committed Mar 2, 2016
1 parent 162330b commit 368291b
Show file tree
Hide file tree
Showing 23 changed files with 3,881 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
.DS_Store
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

73 changes: 73 additions & 0 deletions CheckoutApi/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* CheckoutApi_Api
*
* PHP Version 5.2
* @category Api
* @author Dhiraj Gangoosirdar <dhiraj.gangoosirdar@checkout.com>
* @copyright 2014 Integration team (http://www.checkout.com)
*/

/**
* Class final CheckoutApi_Api.
* This class is responsible in creating instance of payment gateway interface(CheckoutApi_Client_Client).
*
* The simplest usage would be:
* $Api = CheckoutApi_Api::getApi();
*
* This will create an instance a singleton instance of CheckoutApi_Client_Client
* The default gateway is CheckoutApi_Client_ClientGW3.
*
* If you need create instance of other gateways, you can do do those steps:
*
* $Api = CheckoutApi_Api::getApi(array(),'CheckoutApi_Client_Client[GATEWAYNAME]');
*
* If you need initialise some configuration before hand:
*
* $config = array('config1' => 'value1', 'config2' => 'value2');
* $Api = CheckoutApi_Api::getApi($config);
*/

final class CheckoutApi_Api
{
/** @var string $_apiClass The name of the gateway to be used */
private static $_apiClass = 'CheckoutApi_Client_ClientGW3';


/**
* 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);
}

/**
* Helpper static function for setting for $_apiClass.
* @param CheckoutApi_Client_Client $apiClass gateway interface name
*/

public static function setApiClass($apiClass)
{
self::$_apiClass = $apiClass;
}

/**
* Helper static function for retriving value of $_apiClass.
* @return CheckoutApi_Client_Client $_apiClass
*/

public static function getApiClass()
{
return self::$_apiClass;
}
}
179 changes: 179 additions & 0 deletions CheckoutApi/Client/Adapter/Abstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php
/**
* CheckoutApi_Client_Adapter_Abstract
*
* CheckoutApi_Client_Adapter_Abstract An abstract class for CheckoutApi_Client adapters.
* An adapter can be define a method of transmitting message over http protocol
* It encapsulate all basic and core method required by an adpater
*
* @package CheckoutApi
* @category Cleint
* @author Dhiraj Gangoosirdar <dhiraj.gangoosirdar@checkout.com>
* @copyright 2014 Integration team (http://www.checkout.com)
*/
abstract class CheckoutApi_Client_Adapter_Abstract extends CheckoutApi_Lib_Object
{
/** @var string$_uri CheckoutApi_ server identifier */

protected $_uri = null;
/** @var resource|null $_resource CheckoutApi_ The server session handler */
protected $_resource = null;
/** @var mixed $_respond CheckoutApi_ Respond return by the server */
protected $_respond = null;


/**
*
* Constructor for Adapters
* @param array $arguments Array of configuration for constructor
* @throws Exception
*/

public function __construct ( array $arguments = array() )
{
if(isset($arguments['uri']) && $uri = $arguments['uri'] ) {
$this->setUri($uri);
}

if(isset($arguments['config']) && $config = $arguments['config'] ) {

$this->setConfig($arguments['config']);
}

}

/**
* Set/Get attribute wrapper
*
* @param string $method Method being call
* @param array $args Argument being pass
* @return mixed
*/

public function __call($method, $args)
{
switch (substr($method, 0, 3)) {
case 'get' :

$key = substr($method,3);
$key = lcfirst($key);
$data = $this->getConfig($key, isset($args[0]) ? $args[0] : null);

return $data;

case 'set' :

$key =substr($method,3);
$key = lcfirst($key);
$result = $this->setConfig($key, isset($args[0]) ? $args[0] : null);

return $result;


}

//throw new Exception("Invalid method ".get_class($this)."::".$method."(".print_r($args,1).")");

$this->exception("Invalid method ".get_class($this)."::".$method."(".print_r($args,1).")",
debug_backtrace());

return null;
}

/**
* setter for $_uri
* @param string $uri setting the url value
**/

public function setUri($uri)
{

$this->_uri = $uri;
}

/**
* Getter for $_uri
* @return string
**/

public function getUri()
{
return $this->_uri;
}

/**
* Setter for $_resource
* @var resource $resource
**/

public function setResource($resource)
{
$this->_resource = $resource;
}


/**
* Getter for $_resource
*
* @return resource
**/

public function getResource()
{
return $this->_resource;
}

/**
* CheckoutApi_ Setter for respond
* @param mixed $respond responnd obtain by gateway
*
**/

public function setRespond($respond)
{
$this->_respond = $respond;
}

/**
* CheckoutApi_ Getter for respond
*
* @return mixed
*
**/

public function getRespond()
{
return $this->_respond;
}

/**
* Create a connection using the adapter
* @return $this CheckoutApi_Client_Adapter_Abstract
*/
public function connect()
{
return $this;
}

/**
* Close all resource
*/
public function close()
{
$this->setResource(null);
$this->setRespond(null);
}

public function getResourceInfo() {

return array('httpStatus'=>'');
}

/**
* Return request made by the adapter
* @return CheckoutApi_Lib_RespondObj
*/
abstract function request();


}
17 changes: 17 additions & 0 deletions CheckoutApi/Client/Adapter/Constant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* CheckoutApi_Client_Adapter_Constant
* Constant class for Adapter
* @package CheckoutApi
* @category Adapter
* @author Dhiraj Gangoosirdar <dhiraj.gangoosirdar@checkout.com>
* @copyright 2014 Integration team (http://www.checkout.com)
*/
final class CheckoutApi_Client_Adapter_Constant
{
const API_POST = 'POST';
const API_GET = 'GET';
const API_DELETE = 'DELETE';
const API_PUT = 'PUT';
}
Loading

0 comments on commit 368291b

Please sign in to comment.