Skip to content

Commit

Permalink
Merge pull request #45 from crucialwebstudio/develop
Browse files Browse the repository at this point in the history
Merge branch 'develop'
  • Loading branch information
lhkhang authored Mar 29, 2024
2 parents 1e28a5c + d722aad commit 7d01b76
Show file tree
Hide file tree
Showing 41 changed files with 341 additions and 267 deletions.
16 changes: 10 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@
"issues": "https://github.com/chargely/chargify-sdk-php/issues"
},
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.0"
"php": ">=8.1.0",
"guzzlehttp/guzzle": "^7.8.0",
"guzzlehttp/psr7": "^2.5.1",
"guzzlehttp/promises": "^2.0.1"
},
"require-dev": {
"phpunit/phpunit": "4.*",
"fabpot/php-cs-fixer": "1.11",
"monolog/monolog": "1.17.2"
"phpunit/phpunit": "8.5.*",
"monolog/monolog": "^1.21",
"friendsofphp/php-cs-fixer": "^3.9"
},
"autoload": {
"psr-4": {
"Crucial\\Service\\": "src/Crucial/Service"
"Crucial\\Service\\": "src/Crucial/Service",
"Test\\Helpers\\": "tests/phpunit/helpers",
"Test\\Crucial\\": "tests/phpunit/lib/Crucial"
}
}
}
6 changes: 3 additions & 3 deletions docs/source/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Overview
Requirements
============

#. PHP >= 5.5.0
#. PHP >= 8.1.0

.. _installation:

Expand Down Expand Up @@ -103,8 +103,8 @@ Guidelines
Any code you submit will be released under that license. For substantial
contributions, we may ask you to sign a `Contributor License Agreement (CLA) <https://github.com/chargely/chargify-sdk-php/blob/master/CLA.txt>`_.

#. The SDK has a minimum PHP version requirement of PHP 5.5. Pull requests must
not require a PHP version greater than PHP 5.5 unless the feature is only
#. The SDK has a minimum PHP version requirement of PHP 8.1. Pull requests must
not require a PHP version greater than PHP 8.1 unless the feature is only
utilized conditionally.

#. We follow all of the relevant PSR recommendations from the `PHP Framework Interop Group <http://php-fig.org>`_.
Expand Down
15 changes: 12 additions & 3 deletions src/Crucial/Service/Chargify.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\HandlerStack;
use Crucial\Service\Chargify\Exception\BadMethodCallException;
use Crucial\Service\Chargify\Exception\InvalidArgumentException;
use Crucial\Service\Chargify\Adjustment;
use Crucial\Service\Chargify\Charge;
use Crucial\Service\Chargify\Component;
Expand All @@ -43,7 +44,7 @@ class Chargify
/**
* Version
*/
const VERSION = '0.1.1';
public const VERSION = '1.0.0';

/**
* Guzzle http client
Expand Down Expand Up @@ -126,10 +127,18 @@ public function __construct($config)
$this->timeout = $config['timeout'];
}

$httpHandler = isset($config['GuzzleHttp\Client']['handler']) ? $config['GuzzleHttp\Client']['handler'] : null;

if (empty($httpHandler)) {
$httpHandler = HandlerStack::create();
}
if (! $httpHandler instanceof HandlerStack) {
throw new InvalidArgumentException("config['GuzzleHttp\Client']['handler'] is not an instance of ".HandlerStack::class);
}

$this->httpClient = new Client([
'base_uri' => 'https://' . $this->hostname . '/',
'handler' => HandlerStack::create(),
'handler' => $httpHandler,
'timeout' => $this->timeout,
'allow_redirects' => false,
'auth' => [$this->apiKey, $this->password],
Expand Down Expand Up @@ -189,7 +198,7 @@ public function request($path, $method, $rawData = null, $params = [])
}

if (!empty($rawData)) {
$options['body'] = Psr7\stream_for($rawData);
$options['body'] = Psr7\Utils::streamFor($rawData);
}

try {
Expand Down
34 changes: 17 additions & 17 deletions src/Crucial/Service/Chargify/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function setParam($param, $value)
*/
public function getParam($paramName)
{
return !empty($this->_params[$paramName]) ? $this->_params[$paramName] : NULL;
return !empty($this->_params[$paramName]) ? $this->_params[$paramName] : null;
}

/**
Expand Down Expand Up @@ -222,7 +222,7 @@ public function getResponseArray($response)
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if (is_null($offset)) {
$this->_data[] = $value;
Expand All @@ -238,7 +238,7 @@ public function offsetSet($offset, $value)
*
* @return bool
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->_data[$offset]);
}
Expand All @@ -248,7 +248,7 @@ public function offsetExists($offset)
*
* @param mixed $offset
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->_data[$offset]);
}
Expand All @@ -258,11 +258,11 @@ public function offsetUnset($offset)
*
* @param mixed $offset
*
* @return bool
* @return mixed
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return isset($this->_data[$offset]) ? $this->_data[$offset] : NULL;
return isset($this->_data[$offset]) ? $this->_data[$offset] : null;
}

/**
Expand All @@ -274,7 +274,7 @@ public function offsetGet($offset)
*
* @return void
*/
public function rewind()
public function rewind(): void
{
reset($this->_data);
}
Expand All @@ -284,7 +284,7 @@ public function rewind()
*
* @return mixed
*/
public function current()
public function current(): mixed
{
return current($this->_data);
}
Expand All @@ -294,29 +294,29 @@ public function current()
*
* @return mixed
*/
public function key()
public function key(): mixed
{
return key($this->_data);
}

/**
* For \Iterator interface
*
* @return mixed
* @return void
*/
public function next()
public function next(): void
{
return next($this->_data);
next($this->_data);
}

/**
* For \Iterator interface
*
* @return bool
*/
public function valid()
public function valid(): bool
{
return $this->current() !== FALSE;
return $this->current() !== false;
}

/**
Expand All @@ -328,8 +328,8 @@ public function valid()
*
* @return int
*/
public function count()
public function count(): int
{
return count($this->_data);
}
}
}
14 changes: 7 additions & 7 deletions src/Crucial/Service/Chargify/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

class Adjustment extends AbstractEntity
{

/**
* (either 'amount' or 'amount_in_cents' is required) If you use this
* parameter, you should pass a dollar amount represented as a string. For
Expand All @@ -30,7 +29,7 @@ class Adjustment extends AbstractEntity
*
* @return Adjustment
*/
public function setAmount($amount)
public function setAmount($amount): Adjustment
{
$this->setParam('amount', $amount);

Expand All @@ -49,7 +48,7 @@ public function setAmount($amount)
*
* @return Adjustment
*/
public function setAmountInCents($amountInCents)
public function setAmountInCents($amountInCents): Adjustment
{
$this->setParam('amount_in_cents', $amountInCents);

Expand All @@ -64,7 +63,7 @@ public function setAmountInCents($amountInCents)
*
* @return Adjustment
*/
public function setMemo($memo)
public function setMemo($memo): Adjustment
{
$this->setParam('memo', $memo);

Expand All @@ -81,7 +80,7 @@ public function setMemo($memo)
*
* @return Adjustment
*/
public function setAdjustmentMethod($method)
public function setAdjustmentMethod($method): Adjustment
{
$this->setParam('adjustment_method', $method);

Expand All @@ -100,8 +99,9 @@ public function setAdjustmentMethod($method)
* @see Adjustment::setAmountInCents()
* @see Adjustment::setMemo()
* @see Adjustment::setAdjustmentMethod()
*
*/
public function create($subscriptionId)
public function create($subscriptionId): Adjustment
{
$service = $this->getService();
$rawData = $this->getRawData(array('adjustment' => $this->getParams()));
Expand All @@ -116,4 +116,4 @@ public function create($subscriptionId)

return $this;
}
}
}
11 changes: 5 additions & 6 deletions src/Crucial/Service/Chargify/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

class Charge extends AbstractEntity
{

/**
* (either 'amount' or 'amount_in_cents' is required) If you use this
* parameter, you should pass a dollar amount represented as a string. For
Expand All @@ -29,7 +28,7 @@ class Charge extends AbstractEntity
*
* @return Charge
*/
public function setAmount($amount)
public function setAmount($amount): Charge
{
$this->setParam('amount', $amount);

Expand All @@ -47,7 +46,7 @@ public function setAmount($amount)
*
* @return Charge
*/
public function setAmountInCents($amountInCents)
public function setAmountInCents($amountInCents): Charge
{
$this->setParam('amount_in_cents', $amountInCents);

Expand All @@ -62,7 +61,7 @@ public function setAmountInCents($amountInCents)
*
* @return Charge
*/
public function setMemo($memo)
public function setMemo($memo): Charge
{
$this->setParam('memo', $memo);

Expand All @@ -81,7 +80,7 @@ public function setMemo($memo)
* @see Charge::setAmountInCents()
* @see Charge::setMemo()
*/
public function create($subscriptionId)
public function create($subscriptionId): Charge
{
$service = $this->getService();
$rawData = $this->getRawData(array('charge' => $this->getParams()));
Expand All @@ -96,4 +95,4 @@ public function create($subscriptionId)

return $this;
}
}
}
Loading

0 comments on commit 7d01b76

Please sign in to comment.