Skip to content

Commit

Permalink
Merge pull request #70 from hyperwallet/DEV-v4
Browse files Browse the repository at this point in the history
Dev v4
  • Loading branch information
jchanghw authored Nov 14, 2020
2 parents 2f3a313 + ed94f93 commit cbdf6fb
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ php:
- '5.6'
- '7.0'
- '7.3'
- hhvm-3.18
- hhvm-3.24
cache:
directories:
- $HOME/.composer/cache
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
ChangeLog
=========

2.1.0
-------------------
- Added header data to the requests (user-agent, sdk version etc)
- Added Business Stakeholders status transitions
- Added Transfer status transitions - get, list

2.0.0
-------------------
- Updated the methods to point to V4 Rest APIs
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Installation
$ composer require hyperwallet/sdk
```


Documentation
-------------

Expand Down
175 changes: 174 additions & 1 deletion src/Hyperwallet/Hyperwallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Hyperwallet\Model\BankCard;
use Hyperwallet\Model\BankCardStatusTransition;
use Hyperwallet\Model\BusinessStakeholder;
use Hyperwallet\Model\BusinessStakeholderStatusTransition;
use Hyperwallet\Model\IProgramAware;
use Hyperwallet\Model\PaperCheck;
use Hyperwallet\Model\PaperCheckStatusTransition;
Expand Down Expand Up @@ -560,6 +561,54 @@ public function createTransferStatusTransition($transferToken, TransferStatusTra
return new TransferStatusTransition($body);
}

/**
* Get a transfer status transition
*
* @param string $transferToken The transfer token
* @param string $statusTransitionToken The status transition token
* @return TransferStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function getTransferStatusTransition($transferToken, $statusTransitionToken) {
if (empty($transferToken)) {
throw new HyperwalletArgumentException('transferToken is required!');
}
if (empty($statusTransitionToken)) {
throw new HyperwalletArgumentException('statusTransitionToken is required!');
}

$body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/status-transitions/{status-transition-token}', array(
'transfer-token' => $transferToken,
'status-transition-token' => $statusTransitionToken
), array());
return new TransferStatusTransition($body);
}

/**
* List all transfer status transitions
*
* @param string $transferToken The transfer token
* @param array $options The query parameters
* @return ListResponse
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function listTransferStatusTransitions($transferToken, array $options = array()) {
if (empty($transferToken)) {
throw new HyperwalletArgumentException('transfer token is required!');
}

$body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/status-transitions', array(
'transfer-token' => $transferToken
), $options);
return new ListResponse($body, function ($entry) {
return new TransferStatusTransition($entry);
});
}

//--------------------------------------
// PayPal Accounts
//--------------------------------------
Expand Down Expand Up @@ -2029,7 +2078,7 @@ public function createUserStatusTransition($userToken, UserStatusTransition $tra
}

/**
* Activate an User
* Activate a User
*
* @param string $userToken The user token
* @return UserStatusTransition
Expand Down Expand Up @@ -2417,6 +2466,130 @@ public function listBusinessStakeholders($userToken , $options) {
});
}

/**
* Create a Business Stakeholder status transition
*
* @param string $userToken The user token
* @param string $businessToken The Business Token
* @param BusinessStakeholderStatusTransition $transition The status transition
* @return BusinessStakeholderStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function createBusinessStakeholderStatusTransition($userToken, $businessToken, BusinessStakeholderStatusTransition $transition) {
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
if (empty($businessToken)) {
throw new HyperwalletArgumentException('businessToken is required!');
}

$body = $this->client->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array(
'user-token' => $userToken,
'business-token' => $businessToken
), $transition, array());
return new BusinessStakeholderStatusTransition($body);
}

/**
* activate a Business Stakeholder
*
* @param string $userToken The user token
* @param string $businessToken The Business Token
* @return BusinessStakeholderStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function activateBusinessStakeholder($userToken, $businessToken) {
$transition = new BusinessStakeholderStatusTransition();
$transition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_ACTIVATED);

return $this->createBusinessStakeholderStatusTransition($userToken, $businessToken, $transition);
}

/**
* Deactivate a Business Stakeholder
*
* @param string $userToken The user token
* @param string $businessToken The Business Token
* @return BusinessStakeholderStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function deactivateBusinessStakeholder($userToken, $businessToken) {
$transition = new BusinessStakeholderStatusTransition();
$transition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_DE_ACTIVATED);

return $this->createBusinessStakeholderStatusTransition($userToken, $businessToken, $transition);
}

/**
* Get a Business Stakeholder status transition
*
* @param string $userToken The user token
* @param string $businessToken The Business Token
* @param string $statusTransitionToken The status transition token
* @return BusinessStakeholderStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function getBusinessStakeholderStatusTransition($userToken, $businessToken, $statusTransitionToken) {
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
if (empty($businessToken)) {
throw new HyperwalletArgumentException('businessToken is required!');
}
if (empty($statusTransitionToken)) {
throw new HyperwalletArgumentException('statusTransitionToken is required!');
}

$body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions/{status-transition-token}', array(
'user-token' => $userToken,
'business-token' => $businessToken,
'status-transition-token' => $statusTransitionToken
), array());
return new BusinessStakeholderStatusTransition($body);
}

/**
* List all Business Stakeholder status transitions
*
* @param string $userToken The user token
* @param string $businessToken The Business Token
* @param array $options The query parameters
* @return ListResponse
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function listBusinessStakeholderStatusTransitions($userToken, $businessToken, array $options = array()) {
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
if (empty($businessToken)) {
throw new HyperwalletArgumentException('businessToken is required!');
}
if (!empty($options)) {
$filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY()));
if (!empty($filteredArr)) {
throw new HyperwalletArgumentException('Invalid filter');
}
}

$body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array(
'user-token' => $userToken,
'business-token' => $businessToken
), $options);
return new ListResponse($body, function ($entry) {
return new BusinessStakeholderStatusTransition($entry);
});
}

/**
* List all Transfer Methods
*
Expand Down
25 changes: 25 additions & 0 deletions src/Hyperwallet/Model/BusinessStakeholderStatusTransition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace Hyperwallet\Model;

/**
* Represents a V4 Business Stakeholder Status Transition
*
* @package Hyperwallet\Model
*/
class BusinessStakeholderStatusTransition extends StatusTransition
{
const TRANSITION_ACTIVATED = 'ACTIVATED';
const TRANSITION_DE_ACTIVATED = 'DE_ACTIVATED';

/**
* Creates a instance of BusinessStakeholderStatusTransition
*
* @param string[] $properties The default properties
*/
public function __construct(array $properties = array())
{
parent::__construct($properties);
}
}
18 changes: 15 additions & 3 deletions src/Hyperwallet/Util/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Hyperwallet\Model\BaseModel;
use Hyperwallet\Response\ErrorResponse;
use Hyperwallet\Util\HyperwalletEncryption;
use Hyperwallet\Util\HyperwalletUUID;


/**
* The internal API client
Expand All @@ -22,7 +24,7 @@ class ApiClient {
*
* @var string
*/
const VERSION = '0.1.0';
const VERSION = '2.1.0';

/**
* The Guzzle http client
Expand All @@ -38,6 +40,13 @@ class ApiClient {
*/
private $encryption;

/**
* The UUID generator for http request/response
*
* @var HyperwalletUUID
*/
private $uuid;

/**
* Boolean flag that checks if ApiClient is constructed with encryption enabled or not
*
Expand All @@ -55,14 +64,17 @@ class ApiClient {
* @param array $encryptionData Encryption data to initialize ApiClient with encryption enabled
*/
public function __construct($username, $password, $server, $clientOptions = array(), $encryptionData = array()) {
$this->uuid = HyperwalletUUID::v4();
// Setup http client if not specified
$this->client = new Client(array_merge_recursive(array(
'base_uri' => $server,
'auth' => array($username, $password),
'headers' => array(
'User-Agent' => 'Hyperwallet PHP SDK v' . self::VERSION,
'Accept' => 'application/json'
)
'Accept' => 'application/json',
'x-sdk-version' => self::VERSION,
'x-sdk-type' => 'PHP',
'x-sdk-contextId' => $this->uuid)
), $clientOptions));
if (!empty($encryptionData) && isset($encryptionData['clientPrivateKeySetLocation']) &&
isset($encryptionData['hyperwalletKeySetLocation'])) {
Expand Down
57 changes: 57 additions & 0 deletions src/Hyperwallet/Util/HyperwalletUUID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace Hyperwallet\Util;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\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
*
* @package Hyperwallet\Util
*/
class HyperwalletUUID {

/**
* Generates UUID
*
* @return string
*
* @throws HyperwalletException
*/
public static function v4() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',

// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),

// 16 bits for "time_mid"
mt_rand(0, 0xffff),

// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,

// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,

// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
}
Loading

0 comments on commit cbdf6fb

Please sign in to comment.