Skip to content

Commit

Permalink
feature/DTSERWONE-1083 - V3 Support php versions (#118)
Browse files Browse the repository at this point in the history
* DTSERWONE-1083 - Cherry pick f9eb75a from the branch
 `feature/DTSERWONE-1083 - V4 Support php versions (#117)`
Summary:
Enhanced the PHP-SDK to support PHP version build from 5.6 to 8.1

Introduce Hyperwallet URI Template
Introduce GitHubAction to test PHP version from 5.6 to latest
Address PHP Unit test compatibility

* DTSERWONE-1083 - Fix file name to match with the class content
  • Loading branch information
grmeyer-hw-dev authored Aug 24, 2022
1 parent c98c1c0 commit 9e039e4
Show file tree
Hide file tree
Showing 21 changed files with 265 additions and 52 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: PHP SDK CI

on:
workflow_dispatch:
push:
branches:
- master
- support/SDK-V3
- feature/**
- bugfix/**
pull_request:
branches:
- master
- support/SDK-V3
- feature/**
- bugfix/**

jobs:
tests:
name: Tests
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['5.6', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']

steps:
- uses: actions/checkout@master

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: |
php --version
./vendor/bin/phpunit -v
code-coverage:
name: Report code coverage
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ 'ubuntu-latest' ]
php-versions: [ '5.6' ]

steps:
- uses: actions/checkout@master

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: |
php --version
./vendor/bin/phpunit -v
- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./vendor/bin/php-coveralls -v --exclude-no-stmt
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"creditcard",
"ach"
],
"homepage": "http://hyperwallet.github.io/php-sdk",
"homepage": "https://github.com/hyperwallet/php-sdk",
"license": "MIT",
"authors": [
{
Expand All @@ -20,9 +20,9 @@
}
],
"require": {
"php": ">=5.5.9",
"php": ">=5.6.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.2.1 || ^7.0.1",
"guzzlehttp/uri-template": "^0.2.0",
"phpseclib/phpseclib": "^2.0.11",
"gree/jose": "^2.2.1"
},
Expand All @@ -33,9 +33,9 @@
"psr-4": { "Hyperwallet\\Tests\\" : "tests/Hyperwallet/Tests", "ComposerScript\\" : "src/ComposerScript" }
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"phake/phake": "^2.3",
"satooshi/php-coveralls": "^1.0"
"phpunit/phpunit": "^5.7 || ^7.0.0 || ^9.0",
"phake/phake": "^2.3 || ^4.2",
"php-coveralls/php-coveralls": "^2.5"
},
"scripts": {
"post-install-cmd": "ComposerScript\\RsaOaep256AlgorithmInstaller::install"
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand All @@ -21,4 +20,7 @@
<directory>./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion src/Hyperwallet/Exception/HyperwalletApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HyperwalletApiException extends HyperwalletException {
*/
public function __construct(ErrorResponse $errorResponse, \Exception $previous) {
$message = $errorResponse[0] == null ? "Error message is not defined" : $errorResponse[0]->getMessage();
parent::__construct($message, null, $previous);
parent::__construct($message, 0, $previous);

$this->errorResponse = $errorResponse;
$this->relatedResources = $errorResponse[0] == null ? array() : $errorResponse[0]->getRelatedResources();
Expand Down
4 changes: 2 additions & 2 deletions src/Hyperwallet/Exception/HyperwalletArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class HyperwalletArgumentException extends HyperwalletException {
* Creates a instance of the HyperwalletArgumentException
*
* @param string $message The error message
* @param int|null $code The error code
* @param int $code The error code
* @param \Exception|null $previous The original exception
*/
public function __construct($message, $code = null, \Exception $previous = null) {
public function __construct($message, $code = 0, \Exception $previous = null) {
parent::__construct($message, $code, $previous);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Hyperwallet/Exception/HyperwalletException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class HyperwalletException extends \Exception {
* Creates a instance of the HyperwalletException
*
* @param string $message The error message
* @param int|null $code The error code
* @param int $code The error code
* @param \Exception|null $previous The original exception
*/
public function __construct($message, $code = null, \Exception $previous = null) {
public function __construct($message = "", $code = 0, \Exception $previous = null) {
parent::__construct($message, $code, $previous);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Hyperwallet/Hyperwallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Hyperwallet\Model\BankAccountStatusTransition;
use Hyperwallet\Model\BankCard;
use Hyperwallet\Model\BankCardStatusTransition;
use Hyperwallet\Model\HyperwalletVerificationDocument;
use Hyperwallet\Model\HyperWalletVerificationDocument;
use Hyperwallet\Model\HyperwalletVerificationDocumentReason;
use Hyperwallet\Model\HyperwalletVerificationDocumentCollection;
use Hyperwallet\Model\HyperwalletVerificationDocumentReasonCollection;
Expand Down Expand Up @@ -101,7 +101,7 @@ private function setDocumentAndReasonFromResponseHelper($bodyResponse) {
}
$dVal["reasons"] = new HyperwalletVerificationDocumentReasonCollection(...$reasons);
}
$dVal = new HyperwalletVerificationDocument($dVal);
$dVal = new HyperWalletVerificationDocument($dVal);
}
$bodyResponse["documents"] = new HyperwalletVerificationDocumentCollection(...$documents);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Hyperwallet/Model/HyperWalletVerificationDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @package Hyperwallet\Model
*/
class HyperwalletVerificationDocument extends BaseModel {
class HyperWalletVerificationDocument extends BaseModel {

/**
* @internal
Expand Down Expand Up @@ -111,16 +111,16 @@ public function getUploadFiles() {
*/
class HyperwalletVerificationDocumentCollection {

public function __construct(HyperwalletVerificationDocument ...$documents) {
public function __construct(HyperWalletVerificationDocument ...$documents) {
$this->documents = $documents;
}

public function getDocuments() {
return $this->documents;
}

public function getIterator() : ArrayIterator {
return new ArrayIterator($this->documents);
public function getIterator() {
return new \ArrayIterator($this->documents);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function getReasons() {
return $this->reasons;
}

public function getIterator() : ArrayIterator {
return new ArrayIterator($this->reasons);
public function getIterator() {
return new \ArrayIterator($this->reasons);
}

}
9 changes: 3 additions & 6 deletions src/Hyperwallet/Util/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\UriTemplate\UriTemplate;
use Hyperwallet\Exception\HyperwalletApiException;
use Hyperwallet\Exception\HyperwalletException;
use Hyperwallet\Model\BaseModel;
use Hyperwallet\Response\ErrorResponse;
use Hyperwallet\Util\HyperwalletEncryption;
use Hyperwallet\Util\HyperwalletUUID;

/**
* The internal API client
Expand All @@ -23,7 +20,7 @@ class ApiClient {
*
* @var string
*/
const VERSION = '1.7.1';
const VERSION = '1.7.3';

/**
* The Guzzle http client
Expand Down Expand Up @@ -95,7 +92,7 @@ public function __construct($username, $password, $server, $clientOptions = arra
* @throws HyperwalletApiException
*/
public function doPost($partialUrl, array $uriParams, BaseModel $data = null, array $query = array(), array $headers = array()) {
return $this->doRequest('POST', $partialUrl, $uriParams, array(
return $this->doRequest('POST', $partialUrl, $uriParams, array(
'query' => $query,
'body' => $data ? \GuzzleHttp\json_encode($data->getPropertiesForCreate(), JSON_FORCE_OBJECT) : '{}',
'headers' => array_merge($headers, array(
Expand Down Expand Up @@ -154,7 +151,7 @@ public function doGet($partialUrl, array $uriParams, array $query) {
*/
private function doRequest($method, $url, array $urlParams, array $options) {
try {
$uri = new UriTemplate();
$uri = new HyperwalletUriTemplate();
if (!isset($options['headers'])) {
$options[] = array('headers' => array());
}
Expand Down
17 changes: 1 addition & 16 deletions src/Hyperwallet/Util/HyperwalletUUID.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
<?php
namespace Hyperwallet\Util;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\UriTemplate\UriTemplate;
use Hyperwallet\Exception\HyperwalletApiException;

use Hyperwallet\Exception\HyperwalletException;
use Hyperwallet\Model\BaseModel;
use Hyperwallet\Response\ErrorResponse;
use Composer\Autoload\ClassLoader;
use phpseclib\Crypt\RSA;
use phpseclib\Math\BigInteger;
use phpseclib\Crypt\Hash;
use JOSE_URLSafeBase64;
use JOSE_JWS;
use JOSE_JWE;
use JOSE_JWK;
use JOSE_JWT;

/**
* The encryption service for Hyperwallet client's requests/responses
Expand Down
78 changes: 78 additions & 0 deletions src/Hyperwallet/Util/HyperwalletUriTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Hyperwallet\Util;

/**
* A simple implementation of https://www.rfc-editor.org/rfc/rfc6570 for expanding Hyperwallet
* Uniform Resource Identifier (URI) Template.
*
* This class was created to allow the Hyperwallet SDK to support by PHP 5.6 and latest version
* @package Hyperwallet\Util
*/
final class HyperwalletUriTemplate
{

/**
* Regex pattern to find variable identifier defined by pair of braces ('{', '}').
* e.g. {var}
*/
const PATTERN = '/\{([^\}]+)\}/';

/**
* Processes URI Template
*
* This implementation will replace simple key defined in pair of braces ('{', '}') and replaced for the associate
* variable value.
*
* E.g. $uriTemplate = `test/{var-a}/{var-b}`, $variables = array('var-a' => 'testA', 'var-b' => 'testB') will return
* test/testA/testB
*
* @param string $uriTemplate the URI Template is a string that
* contains zero or more embedded variable expressions delimited by pair of braces ('{', '}').
* @param array $variables the variable identifiers for associating values within a template
* processor
* @return string
*/
public function expand($uriTemplate, array $variables)
{
if (!$variables || strpos($uriTemplate, '{') === false) {
// skip processing
return $uriTemplate;
}

return \preg_replace_callback(
self::PATTERN,
self::buildProcessMatchResult($variables),
$uriTemplate
);
}

/**
* Evaluates the match result and find the associated value from the defined variables
* @param array $matches the match results
* @param array $variables the variable identifiers for associating values within a template
* processor
* @return mixed
*/
private static function processMatchResult(array $matches, array $variables)
{
if (!isset($variables[$matches[1]])) {
// missing variable definition, return the match key
return $matches[0];
}

return $variables[$matches[1]];
}

/**
* Builds an anonymous functions to process the match result
* @param array $variables
* @return \Closure
*/
private static function buildProcessMatchResult(array $variables)
{
return static function (array $matches) use ($variables) {
return self::processMatchResult($matches, $variables);
};
}
}
2 changes: 1 addition & 1 deletion tests/Hyperwallet/Tests/HyperwalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Hyperwallet\Response\ErrorResponse;
use Hyperwallet\Util\ApiClient;

class HyperwalletTest extends \PHPUnit_Framework_TestCase {
class HyperwalletTest extends \PHPUnit\Framework\TestCase {

public function testConstructor_throwErrorIfUsernameIsEmpty() {
try {
Expand Down
2 changes: 1 addition & 1 deletion tests/Hyperwallet/Tests/Model/BaseModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Hyperwallet\Model\BaseModel;

class BaseModelTest extends \PHPUnit_Framework_TestCase {
class BaseModelTest extends \PHPUnit\Framework\TestCase {

public function testMagicGetter() {
$data = array(
Expand Down
Loading

0 comments on commit 9e039e4

Please sign in to comment.