Skip to content

Commit

Permalink
Add support for Laravel 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdesign committed Aug 31, 2018
1 parent d97b907 commit 0c24489
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 118 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: php
php:
- 7.0
- 7.1
- 7.2

env:
matrix:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `sebdesign/laravel-viva-payments` will be documented in this file

## 3.1.0 - 2018-07-31

- Add support for Laravel 5.7

## 3.0.1 - 2018-06-01

- Use TLSv1 cipher list if cURL doesn't use NSS
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"require": {
"php": ">=7.0",
"guzzlehttp/guzzle": "~6.0",
"illuminate/config": "~5.5",
"illuminate/routing": "~5.5",
"illuminate/support": "~5.5"
"illuminate/config": "5.5.*|5.6.*|5.7.*",
"illuminate/routing": "5.5.*|5.6.*|5.7.*",
"illuminate/support": "5.5.*|5.6.*|5.7.*"
},
"require-dev": {
"orchestra/testbench": "~3.5",
"phpunit/phpunit": "^6.2"
"orchestra/testbench": "3.5.*|3.6.*|3.7.*",
"phpunit/phpunit": "6.*|7.*"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
Expand Down
25 changes: 15 additions & 10 deletions src/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ public function __construct(Client $client)
* Get a token for the credit card.
*
* @param string $name The cardholder's name
* @param mixed $number The credit card number
* @param string $number The credit card number
* @param int $cvc The CVC number
* @param int $month The expiration month
* @param int $year The expiration year
* @return string
*/
public function token($name, $number, $cvc, $month, $year)
{
public function token(
string $name,
string $number,
int $cvc,
int $month,
int $year
) : string {
$token = $this->client->post(self::ENDPOINT, [
\GuzzleHttp\RequestOptions::FORM_PARAMS => [
'CardHolderName' => $name,
Expand All @@ -53,10 +58,10 @@ public function token($name, $number, $cvc, $month, $year)
/**
* Strip non-numeric characters.
*
* @param mixed $number The credit card number
* @return int
* @param string $number The credit card number
* @return string
*/
protected function normalizeNumber($number)
protected function normalizeNumber(string $number) : string
{
return preg_replace('/\D/', '', $number);
}
Expand All @@ -66,7 +71,7 @@ protected function normalizeNumber($number)
*
* @return string
*/
protected function getKey()
protected function getKey() : string
{
return config('services.viva.public_key');
}
Expand All @@ -78,18 +83,18 @@ protected function getKey()
* @param int $year
* @return string
*/
protected function getExpirationDate($month, $year)
protected function getExpirationDate(int $month, int $year) : string
{
return Carbon::createFromDate($year, $month, 15)->toDateString();
}

/**
* Check for installments support.
*
* @param mixed $number The credit card number
* @param string $number The credit card number
* @return int
*/
public function installments($number)
public function installments(string $number)
{
$response = $this->client->get(self::ENDPOINT.'/installments', [
\GuzzleHttp\RequestOptions::HEADERS => [
Expand Down
30 changes: 16 additions & 14 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Sebdesign\VivaPayments;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Client as GuzzleClient;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

class Client
{
Expand All @@ -18,16 +19,17 @@ class Client
const PRODUCTION_URL = 'https://www.vivapayments.com';

/**
* @var \GuzzleHttp\ClientInterface
* @var \GuzzleHttp\Client
*/
protected $client;

/**
* Constructor.
*
* @param \GuzzleHttp\ClientInterface $client
* @param \GuzzleHttp\Client $client
* @return void
*/
public function __construct(ClientInterface $client)
public function __construct(GuzzleClient $client)
{
$this->client = $client;
}
Expand All @@ -39,7 +41,7 @@ public function __construct(ClientInterface $client)
* @param array $options
* @return object
*/
public function get($url, array $options = [])
public function get(string $url, array $options = [])
{
$response = $this->client->get($url, $options);

Expand All @@ -53,7 +55,7 @@ public function get($url, array $options = [])
* @param array $options
* @return object
*/
public function post($url, array $options = [])
public function post(string $url, array $options = [])
{
$response = $this->client->post($url, $options);

Expand All @@ -67,7 +69,7 @@ public function post($url, array $options = [])
* @param array $options
* @return object
*/
public function patch($url, array $options = [])
public function patch(string $url, array $options = [])
{
$response = $this->client->patch($url, $options);

Expand All @@ -81,7 +83,7 @@ public function patch($url, array $options = [])
* @param array $options
* @return object
*/
public function delete($url, array $options = [])
public function delete(string $url, array $options = [])
{
$response = $this->client->delete($url, $options);

Expand All @@ -91,12 +93,12 @@ public function delete($url, array $options = [])
/**
* Get the response body.
*
* @param \GuzzleHttp\Psr7\Response $response
* @return mixed
* @param \Psr\Http\Message\ResponseInterface $response
* @return object
*
* @throws \Sebdesign\VivaPayments\VivaException
*/
protected function getBody(Response $response)
protected function getBody(ResponseInterface $response)
{
$body = json_decode($response->getBody(), false, 512, JSON_BIGINT_AS_STRING);

Expand All @@ -110,9 +112,9 @@ protected function getBody(Response $response)
/**
* Get the URL.
*
* @return \GuzzleHttp\Psr7\Uri
* @return \Psr\Http\Message\UriInterface
*/
public function getUrl()
public function getUrl() : UriInterface
{
return $this->client->getConfig('base_uri');
}
Expand Down
10 changes: 6 additions & 4 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(Client $client)
* @param array $parameters optional parameters (Full list available here: https://github.com/VivaPayments/API/wiki/Optional-Parameters)
* @return int
*/
public function create($amount, array $parameters = [])
public function create(int $amount, array $parameters = [])
{
$response = $this->client->post(self::ENDPOINT, [
\GuzzleHttp\RequestOptions::FORM_PARAMS => array_merge(['Amount' => $amount], $parameters),
Expand All @@ -60,7 +60,7 @@ public function get($orderCode)
*
* @param int $orderCode The unique Payment Order ID.
* @param array $parameters
* @return null
* @return object
*/
public function update($orderCode, array $parameters)
{
Expand All @@ -83,13 +83,15 @@ public function cancel($orderCode)
/**
* Get the checkout URL for an order.
*
* @param int $orderCode The unique Payment Order ID.
* @param $orderCode The unique Payment Order ID.
* @return \GuzzleHttp\Psr7\Uri
*/
public function getCheckoutUrl($orderCode)
{
return Uri::withQueryValue(
$this->client->getUrl()->withPath('web/checkout'), 'ref', $orderCode
$this->client->getUrl()->withPath('web/checkout'),
'ref',
$orderCode
);
}
}
8 changes: 4 additions & 4 deletions src/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function __construct(Client $client)
* @param string $url The primary domain of your site WITH protocol scheme (http/https)
* @param string $fail The relative path url your client will end up to, after a failed transaction
* @param string $success The relative path url your client will end up to, after a successful transaction
* @return null
* @return object
*/
public function create($name, $code, $url, $fail, $success)
public function create(string $name, string $code, $url, string $fail, string $success)
{
$uri = new Uri($url);

Expand All @@ -56,7 +56,7 @@ public function create($name, $code, $url, $fail, $success)
* @param \Psr\Http\Message\UriInterface $uri
* @return string
*/
protected function getDomain(UriInterface $uri)
protected function getDomain(UriInterface $uri) : string
{
return $uri->getHost();
}
Expand All @@ -67,7 +67,7 @@ protected function getDomain(UriInterface $uri)
* @param \Psr\Http\Message\UriInterface $uri
* @return bool
*/
protected function isSecure(UriInterface $uri)
protected function isSecure(UriInterface $uri) : bool
{
return strtolower($uri->getScheme()) === 'https';
}
Expand Down
24 changes: 12 additions & 12 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ public function create(array $parameters)
* @param array $parameters
* @return object
*/
public function createRecurring($id, $amount, array $parameters = [])
public function createRecurring(string $id, int $amount, array $parameters = [])
{
return $this->client->post(self::ENDPOINT.$id, [
\GuzzleHttp\RequestOptions::FORM_PARAMS => array_merge(['Amount' => $amount], $parameters),
]);
}

/**
* Get the transactions for an order code, a transaction id, or a date.
* Get the transactions for an id.
*
* @param mixed $id
* @param string $id
* @return array
*/
public function get($id)
public function get(string $id) : array
{
$response = $this->client->get(self::ENDPOINT.$id);

Expand All @@ -154,7 +154,7 @@ public function get($id)
* @param int $ordercode
* @return array
*/
public function getByOrder($ordercode)
public function getByOrder($ordercode) : array
{
$response = $this->client->get(self::ENDPOINT, [
\GuzzleHttp\RequestOptions::QUERY => compact('ordercode'),
Expand All @@ -169,7 +169,7 @@ public function getByOrder($ordercode)
* @param \DateTimeInterface|string $date
* @return array
*/
public function getByDate($date)
public function getByDate($date) : array
{
$date = $this->formatDate($date);

Expand All @@ -183,10 +183,10 @@ public function getByDate($date)
/**
* Get the transactions that were cleared on a given date.
*
* @param \DateTimeInterface|string $date
* @param \DateTimeInterface|string $clearancedate
* @return array
*/
public function getByClearanceDate($clearancedate)
public function getByClearanceDate($clearancedate) : array
{
$clearancedate = $this->formatDate($clearancedate);

Expand All @@ -203,7 +203,7 @@ public function getByClearanceDate($clearancedate)
* @param \DateTimeInterface|string $date
* @return string
*/
protected function formatDate($date)
protected function formatDate($date) : string
{
if ($date instanceof \DateTimeInterface) {
return $date->format('Y-m-d');
Expand All @@ -220,7 +220,7 @@ protected function formatDate($date)
* @param string|null $actionUser
* @return object
*/
public function cancel($id, $amount, $actionUser = null)
public function cancel(string $id, int $amount, $actionUser = null)
{
$query = ['Amount' => $amount];
$actionUser = $actionUser ? ['ActionUser' => $actionUser] : [];
Expand All @@ -231,11 +231,11 @@ public function cancel($id, $amount, $actionUser = null)
}

/**
* Get the public key as query string.
* Get the public key.
*
* @return string
*/
protected function getKey()
protected function getKey() : string
{
return config('services.viva.public_key');
}
Expand Down
3 changes: 2 additions & 1 deletion src/VivaPaymentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class VivaPaymentsServiceProvider extends ServiceProvider
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../config/services.php', 'services'
__DIR__.'/../config/services.php',
'services'
);

$this->app->singleton(Client::class, function ($app) {
Expand Down
Loading

0 comments on commit 0c24489

Please sign in to comment.