Skip to content

Commit

Permalink
make worldpay compatible with omnipay 3.*
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Aug 21, 2017
1 parent be0b5c3 commit 87a2d03
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ to your `composer.json` file:
```json
{
"require": {
"omnipay/worldpay": "~2.0"
"omnipay/worldpay": "~3.0"
}
}
```
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
"psr-4": { "Omnipay\\WorldPay\\" : "src/" }
},
"require": {
"omnipay/common": "~2.0"
"omnipay/common": "~3.0"
},
"require-dev": {
"omnipay/tests": "~2.0"
"omnipay/tests": "~3.0"
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.0.x-dev"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
13 changes: 13 additions & 0 deletions src/JsonGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Omnipay\WorldPay;

use Http\Adapter\Guzzle6\Client;
use Omnipay\Common\AbstractGateway;

/**
Expand Down Expand Up @@ -74,4 +75,16 @@ public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\WorldPay\Message\JsonCaptureRequest', $parameters);
}

protected function getDefaultHttpClient()
{
$guzzleClient = Client::createWithConfig([
'curl.options' => [
CURLOPT_SSLVERSION => 6
]
]);


return new \Omnipay\Common\Http\Client($guzzleClient);
}
}
33 changes: 12 additions & 21 deletions src/Message/JsonAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,27 @@ public function setClientKey($value)
return $this->setParameter('clientKey', $value);
}

/**
* Method required to override for getting the specific request endpoint
*
* @return string
*/
abstract public function getEndpoint();

public function sendRequest($data)
{
$config = $this->httpClient->getConfig();
$curlOptions = $config->get('curl.options');
$curlOptions[CURLOPT_SSLVERSION] = 6;
$config->set('curl.options', $curlOptions);
$this->httpClient->setConfig($config);

// don't throw exceptions for 4xx errors
$this->httpClient->getEventDispatcher()->addListener(
'request.error',
function ($event) {
if ($event['response']->isClientError()) {
$event->stopPropagation();
}
}
);

$httpRequest = $this->httpClient->createRequest(
$this->getHttpMethod(),
$this->getEndpoint(),
null,
[],
json_encode($data)
);

$httpResponse = $httpRequest
->setHeader('Authorization', $this->getServiceKey())
->setHeader('Content-type', 'application/json')
->send();
$httpRequest = $httpRequest
->withHeader('Authorization', $this->getServiceKey())
->withHeader('Content-type', 'application/json');

$httpResponse = $this->httpClient->sendRequest($httpRequest);

return $httpResponse;
}
Expand Down
1 change: 0 additions & 1 deletion src/Message/JsonPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function getData()
$data['deliveryAddress']['telephoneNumber'] = $card->getBillingPhone();

$data['shopperEmailAddress'] = $card->getEmail();

}

$data['shopperIpAddress'] = $this->getClientIp();
Expand Down

0 comments on commit 87a2d03

Please sign in to comment.