Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Changes Processor from static to an instantiatable class
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 25, 2016
1 parent 6f056d6 commit ebf3791
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public function purchase(array $params = [])
*/
protected function process(Transaction $transaction)
{
return Processor::process($transaction);
$processor = new Processor();

return $processor->process($transaction);
}

/**
Expand Down
30 changes: 15 additions & 15 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Processor
*
* @var array
*/
protected static $config = [
protected $config = [
'protocol' => 'https',
'host' => 'esqa.moneris.com',
'port' => '443',
Expand All @@ -23,7 +23,7 @@ class Processor
*
* @var string
*/
protected static $error = "<?xml version=\"1.0\"?><response><receipt><ReceiptId>Global Error Receipt</ReceiptId><ReferenceNum>null</ReferenceNum><ResponseCode>null</ResponseCode><ISO>null</ISO> <AuthCode>null</AuthCode><TransTime>null</TransTime><TransDate>null</TransDate><TransType>null</TransType><Complete>false</Complete><Message>null</Message><TransAmount>null</TransAmount><CardType>null</CardType><TransID>null</TransID><TimedOut>null</TimedOut></receipt></response>";
protected $error = "<?xml version=\"1.0\"?><response><receipt><ReceiptId>Global Error Receipt</ReceiptId><ReferenceNum>null</ReferenceNum><ResponseCode>null</ResponseCode><ISO>null</ISO> <AuthCode>null</AuthCode><TransTime>null</TransTime><TransDate>null</TransDate><TransType>null</TransType><Complete>false</Complete><Message>null</Message><TransAmount>null</TransAmount><CardType>null</CardType><TransID>null</TransID><TimedOut>null</TimedOut></receipt></response>";

/**
* Retrieve the API configuration.
Expand All @@ -32,13 +32,13 @@ class Processor
*
* @return array
*/
public static function config(string $environment)
public function config(string $environment)
{
if ($environment === Moneris::ENV_LIVE) {
self::$config['host'] = 'www3.moneris.com';
$this->config['host'] = 'www3.moneris.com';
}

return self::$config;
return $this->config;
}

/**
Expand All @@ -49,7 +49,7 @@ public static function config(string $environment)
*
* @return \CraigPaul\Moneris\Response
*/
public static function process(Transaction $transaction)
public function process(Transaction $transaction)
{
if ($transaction->invalid()) {
$response = new Response($transaction);
Expand All @@ -60,7 +60,7 @@ public static function process(Transaction $transaction)
return $response;
}

$response = self::submit($transaction);
$response = $this->submit($transaction);

return $transaction->validate($response);
}
Expand All @@ -70,9 +70,9 @@ public static function process(Transaction $transaction)
*
* @return \SimpleXMLElement
*/
protected static function error()
protected function error()
{
return simplexml_load_string(self::$error);
return simplexml_load_string($this->error);
}

/**
Expand All @@ -84,7 +84,7 @@ protected static function error()
*
* @return string
*/
protected static function send(array $config, string $url, string $xml)
protected function send(array $config, string $url, string $xml)
{
$curl = curl_init();

Expand All @@ -111,24 +111,24 @@ protected static function send(array $config, string $url, string $xml)
*
* @return \SimpleXMLElement|string
*/
protected static function submit(Transaction $transaction)
protected function submit(Transaction $transaction)
{
$config = self::config($transaction->gateway->environment);
$config = $this->config($transaction->gateway->environment);

$url = $config['protocol'].'://'.$config['host'].':'.$config['port'].$config['url'];

$xml = str_replace(' </', '</', $transaction->toXml());

$response = self::send($config, $url, $xml);
$response = $this->send($config, $url, $xml);

if (!$response) {
return self::error();
return $this->error();
}

$response = @simplexml_load_string($response);

if ($response === false) {
return self::error();
return $this->error();
}

return $response;
Expand Down

0 comments on commit ebf3791

Please sign in to comment.