Skip to content

Commit

Permalink
Merge pull request #8 from RichardCardGate/master
Browse files Browse the repository at this point in the history
Update travis build.
  • Loading branch information
cardgate authored Jan 20, 2020
2 parents 54be241 + f4222ec commit feea8ef
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 78 deletions.
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false

## Cache composer
cache:
directories:
- $HOME/.composer/cache

install:
- travis_retry composer install --no-interaction
- composer require --dev "phpunit/phpunit"

script:
- composer validate --strict
- vendor/bin/phpunit -c tests/phpunit.xml
11 changes: 6 additions & 5 deletions README.md → README.mdown
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Omnipay: Cardgate
![CardGate](https://cdn.curopayments.net/thumb/200/logos/cardgate.png)

**Cardgate gateway for the Omnipay PHP payment processing library**
# CardGate plugin for [Omnipay](https://github.com/omnipay/omnipay) #

[Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment
processing library for PHP 5.3+. This package implements Cardgate support for Omnipay.
[![Total Downloads](https://img.shields.io/packagist/dt/cardgate/omnipay-cardgate.svg)](https://packagist.org/packages/cardgate/cardgate-omnipay)
[![Latest Version](https://img.shields.io/packagist/v/cardgate/omnipay-cardgate.svg)](https://github.com/cardgate/cardgate-omnipay/releases)
[![Build Status](https://travis-ci.org/cardgate/omnipay-cardgate.svg?branch=master)](https://travis-ci.org/cardgate/cardgate-omnipay)

## Installation

Expand All @@ -13,7 +14,7 @@ to your `composer.json` file:
```json
{
"require": {
"cardgate/omnipay-cardgate": "~2.0"
"cardgate/omnipay-cardgate": "~3.0"
}
}
```
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
}
],
"autoload": {
"psr-4": { "Omnipay\\Cardgate\\" : "src/" }
"psr-4": {
"Omnipay\\Cardgate\\" : "src/"
}
},
"require": {
"omnipay/common": "~2.3"
"omnipay/common": "^3.0.2"
},
"require-dev": {
"omnipay/tests": "~2.0"
"omnipay/tests": "^3"
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.0.x-dev"
}
}
}
23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<php>
<ini name="display_errors" value="stderr" />
<ini name="error_log" value="/dev/null" />
</php>
<testsuites>
<testsuite name="Unit tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
24 changes: 24 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@
abstract class AbstractRequest extends BaseAbstractRequest
{

/**
* User Agent.
*
* This user agent will be sent with each API request.
*
* @var string
*/
protected $userAgent = 'Omnipay';
/**
* Get headers.
*
* @return array
*/
protected function getHeaders()
{
$headers = ['User-Agent' => $this->userAgent,
'Authorization' => 'Basic '.base64_encode($this->getMerchantId().":".$this->getApiKey()),
'Content-type' => 'application/json',
'Accept' => 'application/xml'];
return $headers;
}
/**
* Get live- or testURL.
*/
Expand All @@ -32,6 +53,8 @@ public function getUrl()
}
}

<<<<<<< HEAD
=======
/**
* We need this because the hostname does not match the cert...
*
Expand All @@ -45,6 +68,7 @@ protected function setSslVerification()
$this->httpClient->setSslVerification(); // set to defaults
}

>>>>>>> 54be241d32e04ce8afb9261e2aee7a11ceb1fc66
// ------------ Request specific Getter'n'Setters ------------ //

// ------------ Getter'n'Setters ------------ //
Expand Down
36 changes: 15 additions & 21 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,22 @@ public function getData ()
*/
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' );


$headers = $this->getHeaders();
try {
$httpResponse = $request->send();
} catch ( BadResponseException $e ) {
if ( $this->getTestMode() ) {
throw new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
} else {
throw $e;
}
$httpResponse = $this->httpClient->request(
'GET',
$this->getUrl() . $this->endpoint . $this->getTransactionId(),
$headers);

$this->response = new CompletePurchaseResponse(
$this,
simplexml_load_string( $httpResponse->getBody()->getContents() )
);
} catch (BadResponseException $e){
$this->response = new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
}
return new CompletePurchaseResponse( $this, $httpResponse->xml() );

return $this->response;
}
}
32 changes: 18 additions & 14 deletions src/Message/FetchIssuersRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

namespace Omnipay\Cardgate\Message;


use Guzzle\Http\Exception\BadResponseException;
//use http\Client\Curl\User;


/**
* FetchIssuersRequest class - it fetches Issuers.
Expand All @@ -33,24 +36,25 @@ public function getData() {
* {@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' );


$headers = $this->getHeaders();

try {
$httpResponse = $request->send();
$httpResponse = $this->httpClient->request(
'GET',
$this->getUrl() . $this->endpoint,
$headers);

$this->response = new FetchIssuersResponse(
$this
, simplexml_load_string( $httpResponse->getBody()->getContents() )
);

} catch (BadResponseException $e) {
if ( $this->getTestMode() ) throw new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
throw $e;
$this->response = new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
}

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

return $this->response;
}

}
35 changes: 18 additions & 17 deletions src/Message/FetchPaymentMethodsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,24 @@ public function getData() {
*/
public function sendData( $data ) {

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

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

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

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

$headers = $this->getHeaders();

try {
$httpResponse = $this->httpClient->request(
'GET',
$this->getUrl() . $this->endpoint . $this->getParameter( 'siteId' ),
$headers);

$this->response = new FetchPaymentMethodsResponse(
$this,
simplexml_load_string( $httpResponse->getBody()->getContents() )
);
} catch (BadResponseException $e){
$this->response = new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
}

return $this->response;

}

}
31 changes: 15 additions & 16 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,26 @@ public function getData ()
public function sendData ( $data )
{

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

$jsonData = json_encode( array(
'payment' => $data
) );

$this->httpClient->setBaseUrl( $this->getUrl() . $this->endpoint . $this->getPaymentMethod() . '/payment/' );
$request = $this->httpClient->post( null, null, $jsonData );
$request->setAuth( $this->getMerchantId(), $this->getApiKey() );
$request->setHeader( 'Content-type', 'application/json' );
$request->addHeader( 'Accept', 'application/xml' );

$headers = $this->getHeaders();
try {
$httpResponse = $request->send();
} catch ( BadResponseException $e ) {
$e->getResponse()->getBody(1); // ugly; but else ->xml() will fail
return new PurchaseResponse( $this, $e->getResponse()->xml() );
$httpResponse = $this->httpClient->request(
'POST',
$this->getUrl() . $this->endpoint . $this->getPaymentMethod() . '/payment/',
$headers,
$jsonData );

$this->response = new PurchaseResponse(
$this,
simplexml_load_string( $httpResponse->getBody()->getContents() )
);
} catch (BadResponseException $e){
$this->response = new BadResponseException( "CardGate RESTful API gave : " . $e->getResponse()->getBody( true ) );
}
return new PurchaseResponse( $this, $httpResponse->xml() );

return $this->response;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
*/
namespace Omnipay\Cardgate;

use Omnipay\Tests\GatewayTestCase;
use Omnipay\Omnipay;

use Omnipay\Tests\GatewayTestCase;

define( 'CG_SITEID', '' );
define( 'CG_MERCHANTID', '' );
define( 'CG_APIKEY', '' );
Expand Down

0 comments on commit feea8ef

Please sign in to comment.