Skip to content

Commit

Permalink
Add travis ci
Browse files Browse the repository at this point in the history
  • Loading branch information
abdala committed Mar 19, 2020
1 parent 1d807f6 commit 85d8600
Show file tree
Hide file tree
Showing 23 changed files with 308 additions and 318 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: php

php:
- 7.2
- 7.3
- 7.4

before_script:
- composer selfupdate
- composer install --prefer-dist

notifications:
email: false
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"omnipay/common": "^3.0"
},
"require-dev": {
"omnipay/tests": "^3.0"
"omnipay/tests": "^3.0",
"doctrine/coding-standard": "^7.0",
"phpstan/phpstan": "^0.12.17"
}
}
42 changes: 20 additions & 22 deletions src/Gateway.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro;

use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Message\ResponseInterface;

/**
* PagSeguro Gateway
*
* @link https://pagseguro.uol.com.br/v2/guia-de-integracao/index.html
*
* @method \Omnipay\Common\Message\ResponseInterface authorize(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface completeAuthorize(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface capture(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface refund(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface void(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface createCard(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface updateCard(array $options = array())
* @method \Omnipay\Common\Message\ResponseInterface deleteCard(array $options = array())
* @method ResponseInterface authorize(array $options = [])
* @method ResponseInterface completeAuthorize(array $options = [])
* @method ResponseInterface capture(array $options = [])
* @method ResponseInterface refund(array $options = [])
* @method ResponseInterface void(array $options = [])
* @method ResponseInterface createCard(array $options = [])
* @method ResponseInterface updateCard(array $options = [])
* @method ResponseInterface deleteCard(array $options = [])
*/

class Gateway extends AbstractGateway
{
const version = "2";
public const version = '2';

public function getName()
{
Expand All @@ -33,7 +36,7 @@ public function getDefaultParameters()
return [
'email' => '',
'token' => '',
'sandbox' => false
'sandbox' => false,
];
}

Expand Down Expand Up @@ -67,38 +70,33 @@ public function setSandbox($value)
return $this->setParameter('sandbox', $value);
}

public function purchase(array $parameters = array())
public function purchase(array $parameters = [])
{
return $this->createRequest('Omnipay\\PagSeguro\\Message\\PurchaseRequest', $parameters);
}

public function refund(array $parameters = array())
public function refund(array $parameters = [])
{
return $this->createRequest('Omnipay\\PagSeguro\\Message\\RefundRequest', $parameters);
}

public function completePurchase(array $parameters = array())
public function completePurchase(array $parameters = [])
{
return $this->createRequest('Omnipay\\PagSeguro\\Message\\CompletePurchaseRequest', $parameters);
}

/**
* @return Message\FindTransactionRequest
*/
public function findTransaction(array $parameters = array())
public function findTransaction(array $parameters = []) : Message\FindTransactionRequest
{
return $this->createRequest('Omnipay\\PagSeguro\\Message\\FindTransactionRequest', $parameters);
}

/**
* @return Message\TransactionSearchRequest
*/
public function transactionSearch(array $parameters = array())
public function transactionSearch(array $parameters = []) : Message\TransactionSearchRequest
{
return $this->createRequest('Omnipay\\PagSeguro\\Message\\TransactionSearchRequest', $parameters);
}

public function fetchNotification (array $parameters = array()) {
public function fetchNotification(array $parameters = [])
{
return $this->createRequest('Omnipay\\PagSeguro\\Message\\FetchNotificationRequest', $parameters);
}
}
4 changes: 3 additions & 1 deletion src/Item.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro;

use Omnipay\Common\Item as BaseItem;
Expand All @@ -15,4 +17,4 @@ public function setWeight($value)
{
return $this->setParameter('weight', $value);
}
}
}
59 changes: 26 additions & 33 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use function http_build_query;
use function json_decode;
use function json_encode;
use function simplexml_load_string;
use function sprintf;
use function trim;
use const LIBXML_NOCDATA;

abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
protected $endpoint = 'https://ws.pagseguro.uol.com.br/v2';
protected $endpoint = 'https://ws.pagseguro.uol.com.br/v2';
protected $sandboxEndpoint = 'https://ws.sandbox.pagseguro.uol.com.br/v2';
protected $resource = '';
protected $resource = '';

abstract protected function createResponse($data) : void;

public function getEmail()
{
Expand Down Expand Up @@ -44,7 +56,7 @@ public function getData()

return [
'email' => $this->getEmail(),
'token' => $this->getToken()
'token' => $this->getToken(),
];
}

Expand All @@ -65,45 +77,26 @@ public function getHeaders()

public function sendData($data)
{
$url = sprintf('%s/%s?%s',
$this->getEndpoint(),
trim($this->getResource(), '/'),
http_build_query($data, '', '&')
);


$url = sprintf(
'%s/%s?%s',
$this->getEndpoint(),
trim($this->getResource(), '/'),
http_build_query($data, '', '&')
);

$httpResponse = $this->httpClient->request($this->getHttpMethod(), $url, $this->getHeaders());
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);

return $this->createResponse($this->xml2array($xml));
}

protected function xml2array($xml)
public function getEndpoint()
{
$response = [];

if (! $xml) {
return $response;
}

foreach ($xml as $element) {
$tag = $element->getName();
$e = get_object_vars($element);

if (!empty($e)) {
$response[$tag] = $element instanceof SimpleXMLElement ? xml2array($element) : $e;
continue;
}

$response[$tag] = trim($element);
}

return $response;
return $this->getSandbox() ? $this->sandboxEndpoint : $this->endpoint;
}

public function getEndpoint()
protected function xml2array($xml)
{
return $this->getSandbox() ? $this->sandboxEndpoint : $this->endpoint;
return json_decode(json_encode($xml), true);
}
}
22 changes: 16 additions & 6 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use function http_build_query;
use function simplexml_load_string;
use function sprintf;
use const LIBXML_NOCDATA;

class CompletePurchaseRequest extends AbstractRequest
{
protected $resource = "transactions";
protected $resource = 'transactions';

public function getNotificationCode()
{
Expand All @@ -28,13 +35,16 @@ public function getHttpMethod()

public function sendData($data)
{
$url = sprintf('%s/%s/%s?%s', $this->getEndpoint(),
$this->getResource(),
$this->getNotificationCode(),
http_build_query($data, '', '&'));
$url = sprintf(
'%s/%s/%s?%s',
$this->getEndpoint(),
$this->getResource(),
$this->getNotificationCode(),
http_build_query($data, '', '&')
);

$httpResponse = $this->httpClient->request($this->getHttpMethod(), $url);
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);

return $this->createResponse($this->xml2array($xml));
}
Expand Down
2 changes: 2 additions & 0 deletions src/Message/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use Omnipay\Common\Message\AbstractResponse;
Expand Down
24 changes: 17 additions & 7 deletions src/Message/FetchNotificationRequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use function http_build_query;
use function simplexml_load_string;
use function sprintf;
use const LIBXML_NOCDATA;
/*
* PagSeguro Fetch Notification Request
*
Expand All @@ -10,9 +17,9 @@

class FetchNotificationRequest extends AbstractRequest
{
protected $endpoint = 'https://ws.pagseguro.uol.com.br/v3';
protected $endpoint = 'https://ws.pagseguro.uol.com.br/v3';
protected $sandboxEndpoint = 'https://ws.sandbox.pagseguro.uol.com.br/v3';
protected $resource = "transactions/notifications";
protected $resource = 'transactions/notifications';

public function getNotificationCode()
{
Expand All @@ -33,13 +40,16 @@ public function sendData($data)
{
$this->validate('notificationCode');

$url = sprintf('%s/%s/%s?%s', $this->getEndpoint(),
$this->getResource(),
$this->getNotificationCode(),
http_build_query($data, '', '&'));
$url = sprintf(
'%s/%s/%s?%s',
$this->getEndpoint(),
$this->getResource(),
$this->getNotificationCode(),
http_build_query($data, '', '&')
);

$httpResponse = $this->httpClient->request($this->getHttpMethod(), $url, $this->getHeaders());
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);

return $this->createResponse($this->xml2array($xml));
}
Expand Down
2 changes: 2 additions & 0 deletions src/Message/FetchNotificationResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use Omnipay\Common\Message\AbstractResponse;
Expand Down
22 changes: 16 additions & 6 deletions src/Message/FindTransactionRequest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use function http_build_query;
use function simplexml_load_string;
use function sprintf;
use const LIBXML_NOCDATA;

class FindTransactionRequest extends AbstractRequest
{
protected $resource = "transactions";
protected $resource = 'transactions';

public function getTransactionID()
{
Expand All @@ -28,13 +35,16 @@ public function getHttpMethod()

public function sendData($data)
{
$url = sprintf('%s/%s/%s?%s', $this->getEndpoint(),
$this->getResource(),
$this->getTransactionID(),
http_build_query($data, '', '&'));
$url = sprintf(
'%s/%s/%s?%s',
$this->getEndpoint(),
$this->getResource(),
$this->getTransactionID(),
http_build_query($data, '', '&')
);

$httpResponse = $this->httpClient->request($this->getHttpMethod(), $url);
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);
$xml = simplexml_load_string($httpResponse->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);

return $this->createResponse($this->xml2array($xml));
}
Expand Down
2 changes: 2 additions & 0 deletions src/Message/FindTransactionResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Omnipay\PagSeguro\Message;

use Omnipay\Common\Message\AbstractResponse;
Expand Down
Loading

0 comments on commit 85d8600

Please sign in to comment.