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

Commit

Permalink
Changes raw curl to guzzle and accepts guzzle through the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 25, 2016
1 parent 707e299 commit 4985650
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

namespace CraigPaul\Moneris;

use GuzzleHttp\Client;

class Processor
{
/**
* @var \GuzzleHttp\Client
*/
protected $client;

/**
* API configuration.
*
Expand All @@ -15,7 +22,7 @@ class Processor
'port' => '443',
'url' => '/gateway2/servlet/MpgRequest',
'api_version' => 'PHP - 2.5.6',
'timeout' => '60',
'timeout' => 60,
];

/**
Expand All @@ -25,6 +32,16 @@ class Processor
*/
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>";

/**
* Create a new Processor instance.
*
* @param \GuzzleHttp\Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}

/**
* Retrieve the API configuration.
*
Expand Down Expand Up @@ -86,22 +103,15 @@ protected function error()
*/
protected function send(array $config, string $url, string $xml)
{
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_TIMEOUT, $config['timeout']);
curl_setopt($curl, CURLOPT_USERAGENT, $config['api_version']);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($curl);

curl_close($curl);

return $response;
$response = $this->client->post($url, [
'body' => $xml,
'headers' => [
'User-Agent' => $config['api_version']
],
'timeout' => $config['timeout']
]);

return $response->getBody()->getContents();
}

/**
Expand Down

0 comments on commit 4985650

Please sign in to comment.