Skip to content

Commit

Permalink
Merge pull request #31 from hyperwallet/HW-51699-add-payPal-account-s…
Browse files Browse the repository at this point in the history
…tatus-transitions--php

Add PayPal Account Status Transitions - PHP
  • Loading branch information
wmews-hw committed Dec 5, 2019
2 parents 84a3e6e + 1d5eb0a commit 63681c7
Show file tree
Hide file tree
Showing 3 changed files with 351 additions and 0 deletions.
106 changes: 106 additions & 0 deletions src/Hyperwallet/Hyperwallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Hyperwallet\Model\PaymentStatusTransition;
use Hyperwallet\Model\PaperCheck;
use Hyperwallet\Model\PaperCheckStatusTransition;
use Hyperwallet\Model\PayPalAccountStatusTransition;
use Hyperwallet\Model\Transfer;
use Hyperwallet\Model\TransferStatusTransition;
use Hyperwallet\Model\PayPalAccount;
Expand Down Expand Up @@ -558,6 +559,111 @@ public function listPayPalAccounts($userToken, $options = array()) {
return new PayPalAccount($entry);
});
}

/**
* Deactivate a PayPal account
*
* @param string $userToken The user token
* @param string $payPalAccountToken The PayPal account token
* @return PayPalAccountStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function deactivatePayPalAccount($userToken, $payPalAccountToken)
{
$transition = new PayPalAccountStatusTransition();
$transition->setTransition(PayPalAccountStatusTransition::TRANSITION_DE_ACTIVATED);

return $this->createPayPalAccountStatusTransition($userToken, $payPalAccountToken, $transition);
}

/**
* Create a PayPal account status transition
*
* @param string $userToken The user token
* @param string $payPalAccountToken The PayPal account token
* @param PayPalAccountStatusTransition $transition The status transition
* @return PayPalAccountStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function createPayPalAccountStatusTransition($userToken, $payPalAccountToken, PayPalAccountStatusTransition $transition)
{
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
if (empty($payPalAccountToken)) {
throw new HyperwalletArgumentException('payPalAccountToken is required!');
}

$body = $this->client->doPost('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array(
'user-token' => $userToken,
'payPal-account-token' => $payPalAccountToken
), $transition, array());
return new PayPalAccountStatusTransition($body);
}

/**
* Get a PayPal account status transition
*
* @param string $userToken The user token
* @param string $payPalAccountToken The PayPal account token
* @param string $statusTransitionToken The status transition token
* @return PayPalAccountStatusTransition
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function getPayPalAccountStatusTransition($userToken, $payPalAccountToken, $statusTransitionToken)
{
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
if (empty($payPalAccountToken)) {
throw new HyperwalletArgumentException('payPalAccountToken is required!');
}
if (empty($statusTransitionToken)) {
throw new HyperwalletArgumentException('statusTransitionToken is required!');
}

$body = $this->client->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions/{status-transition-token}', array(
'user-token' => $userToken,
'payPal-account-token' => $payPalAccountToken,
'status-transition-token' => $statusTransitionToken
), array());
return new PayPalAccountStatusTransition($body);
}

/**
* List all PayPal account status transitions
*
* @param string $userToken The user token
* @param string $payPalAccountToken The payPal account token
* @param array $options The query parameters
* @return ListResponse
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
*/
public function listPayPalAccountStatusTransitions($userToken, $payPalAccountToken, array $options = array())
{
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
}
if (empty($payPalAccountToken)) {
throw new HyperwalletArgumentException('payPalAccountToken is required!');
}

$body = $this->client->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array(
'user-token' => $userToken,
'payPal-account-token' => $payPalAccountToken
), $options);
return new ListResponse($body, function ($entry) {
return new PayPalAccountStatusTransition($entry);
});
}

//--------------------------------------
// Prepaid Cards
Expand Down
25 changes: 25 additions & 0 deletions src/Hyperwallet/Model/PayPalAccountStatusTransition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Hyperwallet\Model;

/**
* Represents a V3 PayPal Account Status Transition
*
* @package Hyperwallet\Model
*/
class PayPalAccountStatusTransition extends StatusTransition
{

const TRANSITION_DE_ACTIVATED = 'DE_ACTIVATED';

/**
* Creates a instance of PayPalAccountStatusTransition
*
* @param string[] $properties The default properties
*/
public function __construct(array $properties = array())
{
parent::__construct($properties);
}

}
220 changes: 220 additions & 0 deletions tests/Hyperwallet/Tests/HyperwalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Hyperwallet\Model\Transfer;
use Hyperwallet\Model\TransferStatusTransition;
use Hyperwallet\Model\PayPalAccount;
use Hyperwallet\Model\PayPalAccountStatusTransition;
use Hyperwallet\Model\Payment;
use Hyperwallet\Model\PaymentStatusTransition;
use Hyperwallet\Model\PrepaidCard;
Expand Down Expand Up @@ -1089,6 +1090,225 @@ public function testListPayPalAccounts_withParameters() {
// Validate mock
\Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts', array('user-token' => 'test-user-token'), array('test' => 'value'));
}

public function testDeactivatePayPalAccount_noUserToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');

// Run test
try {
$client->deactivatePayPalAccount('', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('userToken is required!', $e->getMessage());
}
}

public function testDeactivatePayPalAccount_noPayPalAccountToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');

// Run test
try {
$client->deactivatePayPalAccount('test-user-token', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('payPalAccountToken is required!', $e->getMessage());
}
}

public function testDeactivatePayPalAccount_allParameters()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);

$statusTransition = new PayPalAccountStatusTransition();
$statusTransition->setTransition(PayPalAccountStatusTransition::TRANSITION_DE_ACTIVATED);

\Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), $statusTransition, array())->thenReturn(array('success' => 'true'));

// Run test
$newStatusTransition = $client->deactivatePayPalAccount('test-user-token', 'test-payPal-account-token');
$this->assertNotNull($newStatusTransition);
$this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties());

// Validate mock
\Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), $statusTransition, array());
}

public function testCreatePayPalAccountStatusTransition_noUserToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$statusTransition = new PayPalAccountStatusTransition();

try {
$client->createPayPalAccountStatusTransition('', '', $statusTransition);
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('userToken is required!', $e->getMessage());
}
}

public function testCreatePayPalAccountStatusTransition_noPayPalAccountToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$statusTransition = new PayPalAccountStatusTransition();

try {
$client->createPayPalAccountStatusTransition('test-user-token', '', $statusTransition);
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('payPalAccountToken is required!', $e->getMessage());
}
}

public function testCreatePayPalAccountStatusTransition_allParameters()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);
$statusTransition = new PayPalAccountStatusTransition(array('transition' => 'test'));

\Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), $statusTransition, array())->thenReturn(array('success' => 'true'));

// Run test
$newStatusTransition = $client->createPayPalAccountStatusTransition('test-user-token', 'test-payPal-account-token', $statusTransition);
$this->assertNotNull($newStatusTransition);
$this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties());

// Validate mock
\Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), $statusTransition, array());
}

public function testGetPayPalAccountStatusTransition_noUserToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');

// Run test
try {
$client->getPayPalAccountStatusTransition('', '', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('userToken is required!', $e->getMessage());
}
}

public function testGetPayPalAccountStatusTransition_noPayPalAccountToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');

// Run test
try {
$client->getPayPalAccountStatusTransition('test-user-token', '', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('payPalAccountToken is required!', $e->getMessage());
}
}

public function testGetPayPalAccountStatusTransition_noStatusTransitionToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');

// Run test
try {
$client->getPayPalAccountStatusTransition('test-user-token', 'test-payPal-account-token', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('statusTransitionToken is required!', $e->getMessage());
}
}

public function testGetPayPalAccountStatusTransition_allParameters()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);

\Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true'));

// Run test
$statusTransition = $client->getPayPalAccountStatusTransition('test-user-token', 'test-payPal-account-token', 'test-status-transition-token');
$this->assertNotNull($statusTransition);
$this->assertEquals(array('success' => 'true'), $statusTransition->getProperties());

// Validate mock
\Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token', 'status-transition-token' => 'test-status-transition-token'), array());
}

public function testListPayPalAccountStatusTransitions_noUserToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');

// Run test
try {
$client->listPayPalAccountStatusTransitions('', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('userToken is required!', $e->getMessage());
}
}

public function testListPayPalAccountStatusTransitions_noPayPalAccountToken()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password');

// Run test
try {
$client->listPayPalAccountStatusTransitions('test-user-token', '');
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('payPalAccountToken is required!', $e->getMessage());
}
}

public function testListPayPalAccountStatusTransitions_noParameters()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');
$apiClientMock = $this->createAndInjectApiClientMock($client);

\Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), array())->thenReturn(array('count' => 1, 'data' => array()));

// Run test
$statusTransitionList = $client->listPayPalAccountStatusTransitions('test-user-token', 'test-payPal-account-token');
$this->assertNotNull($statusTransitionList);
$this->assertCount(0, $statusTransitionList);
$this->assertEquals(1, $statusTransitionList->getCount());

// Validate mock
\Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), array());
}

public function testListPayPalAccountStatusTransitions_withParameters()
{
// Setup
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');
$apiClientMock = $this->createAndInjectApiClientMock($client);

\Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('success' => 'true'))));

// Run test
$statusTransitionList = $client->listPayPalAccountStatusTransitions('test-user-token', 'test-payPal-account-token', array('test' => 'value'));
$this->assertNotNull($statusTransitionList);
$this->assertCount(1, $statusTransitionList);
$this->assertEquals(1, $statusTransitionList->getCount());

$this->assertEquals(array('success' => 'true'), $statusTransitionList[0]->getProperties());

// Validate mock
\Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paypal-accounts/{payPal-account-token}/status-transitions', array('user-token' => 'test-user-token', 'payPal-account-token' => 'test-payPal-account-token'), array('test' => 'value'));
}

//--------------------------------------
// Prepaid Cards
Expand Down

0 comments on commit 63681c7

Please sign in to comment.