From ebf37919546fe08bccbafebd7d22abcaa3cdd4a9 Mon Sep 17 00:00:00 2001 From: Craig Paul Date: Tue, 25 Oct 2016 07:44:40 -0600 Subject: [PATCH] Changes Processor from static to an instantiatable class --- src/Gateway.php | 4 +++- src/Processor.php | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index e6fbeeb..7aa6c3f 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -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); } /** diff --git a/src/Processor.php b/src/Processor.php index ac3c896..948a1b3 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -9,7 +9,7 @@ class Processor * * @var array */ - protected static $config = [ + protected $config = [ 'protocol' => 'https', 'host' => 'esqa.moneris.com', 'port' => '443', @@ -23,7 +23,7 @@ class Processor * * @var string */ - protected static $error = "Global Error Receiptnullnullnull nullnullnullnullfalsenullnullnullnullnull"; + protected $error = "Global Error Receiptnullnullnull nullnullnullnullfalsenullnullnullnullnull"; /** * Retrieve the API configuration. @@ -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; } /** @@ -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); @@ -60,7 +60,7 @@ public static function process(Transaction $transaction) return $response; } - $response = self::submit($transaction); + $response = $this->submit($transaction); return $transaction->validate($response); } @@ -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); } /** @@ -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(); @@ -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(' 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;