Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/vendor
.env
.env.backup
.DS_Store
composer.lock
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
"psr-4": { "Omnipay\\Cardgate\\" : "src/" }
},
"require": {
"omnipay/common": "~2.3"
"league/omnipay": "^3.0"
},
"require-dev": {
"omnipay/tests": "~2.0"
"omnipay/tests": "^3.1",
"squizlabs/php_codesniffer": "^3.4",
"phpunit/phpunit": "^6.0"
},
"extra": {
"branch-alias": {
Expand Down
41 changes: 10 additions & 31 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public function getName ()
*/
public function getDefaultParameters ()
{
return array(
'merchantId' => '',
'language' => 'nl',
'apiKey' => '',
'siteId' => '',
'notifyUrl' => '',
'returnUrl' => '',
'cancelUrl' => '',
'testMode' => false
);
return [
'merchantId' => '',
'language' => 'nl',
'apiKey' => '',
'siteId' => '',
'notifyUrl' => '',
'returnUrl' => '',
'cancelUrl' => '',
'testMode' => false
];
}

// ------------ Getter'n'Setters ------------ //
Expand Down Expand Up @@ -201,27 +201,6 @@ public function setLanguage ( $value )
return $this->setParameter( 'language', $value );
}

/**
*
* @return string
*/
/*
* public function getPaymentMethod()
* {
* return $this->getParameter( 'paymentMethod' );
* }
*/
/**
*
* @param string $value
* @return \Omnipay\Cardgate\Gateway
*/
/*
* public function setPaymentMethod( $value )
* {
* return $this->setParameter( 'paymentMethod', $value );
* }
*/

// ------------ Requests ------------ //

Expand Down
19 changes: 1 addition & 18 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,7 @@ abstract class AbstractRequest extends BaseAbstractRequest
*/
public function getUrl()
{
if ($this->getTestMode()) {
return 'https://secure-staging.curopayments.net';
} else {
return 'https://secure.curopayments.net';
}
}

/**
* We need this because the hostname does not match the cert...
*
* @param bool $bTestmode_
*/
protected function setSslVerification()
{
if ($this->getTestMode())
$this->httpClient->setSslVerification(false, false, 0); // disable ssl cert check
else
$this->httpClient->setSslVerification(); // set to defaults
return $this->getTestMode() ? 'https://secure-staging.curopayments.net' :'https://secure.curopayments.net';
}

// ------------ Request specific Getter'n'Setters ------------ //
Expand Down
20 changes: 8 additions & 12 deletions src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* https://github.com/cardgate/
*
*/

namespace Omnipay\Cardgate\Message;

use Omnipay\Common\Message\AbstractResponse as BaseAbstractResponse;
Expand All @@ -29,7 +28,8 @@ abstract class AbstractResponse extends BaseAbstractResponse {
/**
* {@inheritdoc}
*/
public function __construct( RequestInterface $request, $data ) {
public function __construct( RequestInterface $request, $data )
{
parent::__construct( $request, $data );
if ( isset( $this->data->error ) ) {
$this->code = ( string ) $this->data->error->code;
Expand All @@ -40,21 +40,17 @@ public function __construct( RequestInterface $request, $data ) {
/**
* {@inheritdoc}
*/
public function getMessage() {
if ( !$this->isSuccessful() ) {
return $this->data;
}
return null;
public function getMessage()
{
return $this->isSuccessful() ? null : $this->data;
}

/**
* {@inheritdoc}
*/
public function getCode() {
if ( !$this->isSuccessful() ) {
return $this->code;
}
return null;
public function getCode()
{
return $this->isSuccessful() ? null : $this->code;
}

}
47 changes: 25 additions & 22 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
*/
namespace Omnipay\Cardgate\Message;

use Guzzle\Http\Exception\BadResponseException;
use Exception;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\ResponseInterface;

/**
* CompletePurchaseRequest class - It requests information about the
Expand All @@ -20,7 +23,6 @@
*/
class CompletePurchaseRequest extends PurchaseRequest
{

protected $endpoint = '/rest/v1/transactions/';

/**
Expand All @@ -29,37 +31,38 @@ class CompletePurchaseRequest extends PurchaseRequest
public function getData ()
{
$this->validate( 'transactionId' );
return array(
'id' => $this->getTransactionId()
);
return [
'id' => $this->getTransactionId()
];
}

/**
* {@inheritdoc}
*/
public function sendData ( $data )
{

// Test-API SSL cert issue
$this->setSslVerification();

$this->httpClient->setBaseUrl( $this->getUrl() . $this->endpoint . $this->getTransactionId() );
$request = $this->httpClient->get( null, null, array(
'transaction' => $data
) );

$request->setAuth( $this->getMerchantId(), $this->getApiKey() );
$request->addHeader( 'Accept', 'application/xml' );

{
try {
$response = $this->httpClient->request('GET', ($this->getUrl() . $this->endpoint . $this->getTransactionId()), [
'Accept' => 'application/xml',
'Content-Type' => 'application/json',
'Authorization' => 'Basic '. base64_encode($this->getMerchantId() . ':' . $this->getApiKey()),
], http_build_query($data));

$httpResponse = simplexml_load_string($response->getBody()->getContents());

$httpResponse = $request->send();
} catch ( BadResponseException $e ) {
} catch (Exception $e) {

if ( $this->getTestMode() ) {
throw new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
} else {
throw new InvalidResponseException(
'CardGate RESTful API gave : ' . $e->getMessage(),
$e->getCode()
);
}
else {
throw $e;
}
}
}

return new CompletePurchaseResponse( $this, $httpResponse->xml() );
}
Expand Down
16 changes: 4 additions & 12 deletions src/Message/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
class CompletePurchaseResponse extends PurchaseResponse
{

/**
* {@inheritdoc}
*/
Expand All @@ -35,31 +34,24 @@ public function getMessage ()
$status = $this->getStatus();
if ( ! is_null( $status ) ) {
return $status;
} elseif ( ! is_null( $this->code ) ) {
return $this->data;
}
return null;
return ( !is_null( $this->code ) ) ? $this->data : null;

}

/**
* {@inheritdoc}
*/
public function getStatus ()
{
if ( isset( $this->data->transaction->status ) ) {
return ( string ) $this->data->transaction->status;
}
return null;
return ( isset( $this->data->transaction->status ) ) ? ( string ) $this->data->transaction->status : null;
}

/**
* {@inheritdoc}
*/
public function getTransactionId ()
{
if ( isset( $this->data->transaction->transaction_id ) ) {
return ( string ) $this->data->transaction->transaction_id;
}
return false;
return ( isset( $this->data->transaction->transaction_id ) ) ? ( string ) $this->data->transaction->transaction_id : false;
}
}
54 changes: 30 additions & 24 deletions src/Message/FetchIssuersRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,60 @@
/*
* CardGate driver for Omnipay PHP payment processing library
* https://www.cardgate.com/
*
*
* Latest driver release:
* https://github.com/cardgate/
*
*
*/

namespace Omnipay\Cardgate\Message;

use Guzzle\Http\Exception\BadResponseException;
use Exception;
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Common\Message\ResponseInterface;

/**
* FetchIssuersRequest class - it fetches Issuers.
*
*
* @author Martin Schipper [email protected]
*/
class FetchIssuersRequest extends AbstractRequest {

protected $endpoint = '/rest/v1/ideal/issuers/';
class FetchIssuersRequest extends AbstractRequest
{
protected $endpoint = '/rest/v1/curo/ideal/issuers/';

/**
* {@inheritdoc}
*/
public function getData() {
public function getData()
{
return array();
}

/**
* {@inheritdoc}
*/
public function sendData( $data ) {

// Test-API SSL cert issue
$this->setSslVerification();

$request = $this->httpClient->get( $this->getUrl() . $this->endpoint );
$request->setAuth( $this->getMerchantId(), $this->getApiKey() );
$request->setHeader( 'Content-type', 'application/json' );
$request->addHeader( 'Accept', 'application/xml' );

public function sendData($data = null)
{
try {
$httpResponse = $request->send();
} catch (BadResponseException $e) {
if ( $this->getTestMode() ) throw new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
throw $e;

$response = $this->httpClient->request('GET', ($this->getUrl() . $this->endpoint), [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . base64_encode($this->getMerchantId() . ':' . $this->getApiKey()),
]);

$httpResponse = json_decode($response->getBody()->getContents(), true);

} catch (Exception $e) {
if ($this->getTestMode()) {
throw new InvalidResponseException('CardGate RESTful API gave : ' . $e->getMessage(), $e->getCode());
} else {
throw $e;
}
}
return $this->response = new FetchIssuersResponse ($this, $httpResponse);

return $this->response = new FetchIssuersResponse ($this, $httpResponse->xml() );

}

}
4 changes: 2 additions & 2 deletions src/Message/FetchIssuersResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*
* @author Martin Schipper [email protected]
*/
class FetchIssuersResponse extends BaseAbstractResponse implements FetchIssuersResponseInterface {

class FetchIssuersResponse extends BaseAbstractResponse implements FetchIssuersResponseInterface
{
/**
* {@inheritdoc}
*/
Expand Down
Loading