Skip to content

Commit

Permalink
Merge pull request #16 from wirecard/updateGuzzleRing
Browse files Browse the repository at this point in the history
#15 update StreamHandler for guzzle/ring
  • Loading branch information
rinnhofer authored Jan 17, 2017
2 parents edad692 + 3781959 commit 31886b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion wirecardceecheckoutseamless/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>wirecardceecheckoutseamless</name>
<displayName><![CDATA[Wirecard Checkout Seamless]]></displayName>
<version><![CDATA[1.0.2]]></version>
<version><![CDATA[1.0.3]]></version>
<description><![CDATA[Wirecard Checkout Seamless payment module]]></description>
<author><![CDATA[Wirecard]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class StreamHandler
{
private $options;
private $lastHeaders;

public function __construct(array $options = [])
{
Expand All @@ -30,17 +31,20 @@ public function __invoke(array $request)
try {
// Does not support the expect header.
$request = Core::removeHeader($request, 'Expect');
$stream = $this->createStream($url, $request, $headers);
return $this->createResponse($request, $url, $headers, $stream);
$stream = $this->createStream($url, $request);
return $this->createResponse($request, $url, $stream);
} catch (RingException $e) {
return $this->createErrorResponse($url, $e);
}
}

private function createResponse(array $request, $url, array $hdrs, $stream)
private function createResponse(array $request, $url, $stream)
{
$hdrs = $this->lastHeaders;
$this->lastHeaders = null;
$parts = explode(' ', array_shift($hdrs), 3);
$response = [
'version' => substr($parts[0], 5),
'status' => $parts[1],
'reason' => isset($parts[2]) ? $parts[2] : null,
'headers' => Core::headersFromLines($hdrs),
Expand Down Expand Up @@ -176,11 +180,8 @@ private function createResource(callable $callback)
return $resource;
}

private function createStream(
$url,
array $request,
&$http_response_header
) {
private function createStream($url, array $request)
{
static $methods;
if (!$methods) {
$methods = array_flip(get_class_methods(__CLASS__));
Expand Down Expand Up @@ -215,8 +216,7 @@ private function createStream(
$url,
$request,
$options,
$this->createContext($request, $options, $params),
$http_response_header
$this->createContext($request, $options, $params)
);
}

Expand Down Expand Up @@ -285,13 +285,14 @@ private function add_verify(array $request, &$options, $value, &$params)
}
} elseif ($value === false) {
$options['ssl']['verify_peer'] = false;
$options['ssl']['allow_self_signed'] = true;
return;
} else {
throw new RingException('Invalid verify request option');
}

$options['ssl']['verify_peer'] = true;
$options['ssl']['allow_self_signed'] = true;
$options['ssl']['allow_self_signed'] = false;
}

private function add_cert(array $request, &$options, $value, &$params)
Expand All @@ -310,7 +311,7 @@ private function add_cert(array $request, &$options, $value, &$params)

private function add_progress(array $request, &$options, $value, &$params)
{
$fn = function ($code, $_, $_, $_, $transferred, $total) use ($value) {
$fn = function ($code, $_1, $_2, $_3, $transferred, $total) use ($value) {
if ($code == STREAM_NOTIFY_PROGRESS) {
$value($total, $transferred, null, null);
}
Expand Down Expand Up @@ -394,16 +395,17 @@ private function createStreamResource(
$url,
array $request,
array $options,
$context,
&$http_response_header
$context
) {
return $this->createResource(
function () use ($url, &$http_response_header, $context) {
function () use ($url, $context) {
if (false === strpos($url, 'http')) {
trigger_error("URL is invalid: {$url}", E_USER_WARNING);
return null;
}
return fopen($url, 'r', null, $context);
$resource = fopen($url, 'r', null, $context);
$this->lastHeaders = $http_response_header;
return $resource;
},
$request,
$options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function __construct()
$this->config = $this->config();
$this->name = 'wirecardceecheckoutseamless';
$this->tab = 'payments_gateways';
$this->version = '1.0.2';
$this->version = '1.0.3';
$this->author = 'Wirecard';
$this->controllers = array(
'confirm',
Expand Down

0 comments on commit 31886b6

Please sign in to comment.