From 0ab9af424f839de89273f66cd84b9eb566f1339a Mon Sep 17 00:00:00 2001 From: akreisman-epam Date: Mon, 2 Apr 2018 14:49:21 +0300 Subject: [PATCH 1/6] Added bank account transition and payment status transition endpoints --- CHANGELOG.md | 2 + src/Hyperwallet/Hyperwallet.php | 101 ++++++++++ .../Model/PaymentStatusTransition.php | 22 +++ tests/Hyperwallet/Tests/HyperwalletTest.php | 177 ++++++++++++++++++ 4 files changed, 302 insertions(+) create mode 100644 src/Hyperwallet/Model/PaymentStatusTransition.php diff --git a/CHANGELOG.md b/CHANGELOG.md index bab0c3f7..3df43a5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changelog 0.2.0 (in progress) ------------------- +- Added payment status transition endpoint +- Added get bank account status transition endpoint - Added list program account receipt endpoint - Added list user receipt endpoint - Added list prepaid card receipt endpoint diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 46835e2e..f3959869 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -7,6 +7,7 @@ use Hyperwallet\Model\BankAccountStatusTransition; use Hyperwallet\Model\IProgramAware; use Hyperwallet\Model\Payment; +use Hyperwallet\Model\PaymentStatusTransition; use Hyperwallet\Model\PrepaidCard; use Hyperwallet\Model\PrepaidCardStatusTransition; use Hyperwallet\Model\Program; @@ -353,6 +354,7 @@ public function createPrepaidCardStatusTransition($userToken, $prepaidCardToken, * @return PrepaidCardStatusTransition * * @throws HyperwalletArgumentException + * @throws HyperwalletApiException */ public function getPrepaidCardStatusTransition($userToken, $prepaidCardToken, $statusTransitionToken) { if (empty($userToken)) { @@ -534,6 +536,36 @@ public function createBankAccountStatusTransition($userToken, $bankAccountToken, return new BankAccountStatusTransition($body); } + /** + * Get a bank account status transition + * + * @param string $userToken The user token + * @param string $bankAccountToken The bank account token + * @param string $statusTransitionToken The status transition token + * @return BankAccountStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getBankAccountStatusTransition($userToken, $bankAccountToken, $statusTransitionToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($bankAccountToken)) { + throw new HyperwalletArgumentException('bankAccountToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions/{status-transition-token}', array( + 'user-token' => $userToken, + 'bank-account-token' => $bankAccountToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new BankAccountStatusTransition($body); + } + /** * List all bank account status transitions * @@ -721,6 +753,75 @@ public function listPayments($options = array()) { }); } + /** + * Create a payment status transition + * + * @param string $paymentToken The payment token + * @param PaymentStatusTransition $transition The status transition + * @return PaymentStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function createPaymentStatusTransition($paymentToken, PaymentStatusTransition $transition) { + if (empty($paymentToken)) { + throw new HyperwalletArgumentException('paymentToken is required!'); + } + + $body = $this->client->doPost('/rest/v3/payments/{payment-token}/status-transitions', array( + 'payment-token' => $paymentToken + ), $transition, array()); + return new PaymentStatusTransition($body); + } + + /** + * Get a payment status transition + * + * @param string $paymentToken The payment token + * @param string $statusTransitionToken The status transition token + * @return PaymentStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getPaymentStatusTransition($paymentToken, $statusTransitionToken) { + if (empty($paymentToken)) { + throw new HyperwalletArgumentException('paymentToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/payments/{payment-token}/status-transitions/{status-transition-token}', array( + 'payment-token' => $paymentToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new PaymentStatusTransition($body); + } + + /** + * List all payment status transitions + * + * @param string $paymentToken The payment token + * @param array $options The query parameters + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listPaymentStatusTransitions($paymentToken, array $options = array()) { + if (empty($paymentToken)) { + throw new HyperwalletArgumentException('paymentToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/payments/{payment-token}/status-transitions', array( + 'payment-token' => $paymentToken + ), $options); + return new ListResponse($body, function($entry) { + return new PaymentStatusTransition($entry); + }); + } + //-------------------------------------- // Programs //-------------------------------------- diff --git a/src/Hyperwallet/Model/PaymentStatusTransition.php b/src/Hyperwallet/Model/PaymentStatusTransition.php new file mode 100644 index 00000000..4cd3fa68 --- /dev/null +++ b/src/Hyperwallet/Model/PaymentStatusTransition.php @@ -0,0 +1,22 @@ +doPost('/rest/v3/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-account-token' => 'test-bank-account-token'), $statusTransition, array()); } + public function testGetBankAccountStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBankAccountStatusTransition('', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetBankAccountStatusTransition_noBankAccountToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBankAccountStatusTransition('test-user-token', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('bankAccountToken is required!', $e->getMessage()); + } + } + + public function testGetBankAccountStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBankAccountStatusTransition('test-user-token', 'test-bank-account-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetBankAccountStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'bank-account-token' => 'test-bank-account-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $statusTransition = $client->getBankAccountStatusTransition('test-user-token', 'test-bank-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}/bank-accounts/{bank-account-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'bank-account-token' => 'test-bank-account-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + public function testListBankAccountStatusTransitions_noUserToken() { // Setup $client = new Hyperwallet('test-username', 'test-password'); @@ -1349,6 +1405,127 @@ public function testListPayments_withParameters() { \Phake::verify($apiClientMock)->doGet('/rest/v3/payments', array(), array('test' => 'value')); } + public function testCreatePaymentStatusTransition_noPaymentToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $statusTransition = new PaymentStatusTransition(); + + try { + $client->createPaymentStatusTransition('', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paymentToken is required!', $e->getMessage()); + } + } + + public function testCreatePaymentStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $statusTransition = new PaymentStatusTransition(array('transition' => 'test')); + + \Phake::when($apiClientMock)->doPost('/rest/v3/payments/{payment-token}/status-transitions', array('payment-token' => 'test-payment-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + + // Run test + $newStatusTransition = $client->createPaymentStatusTransition('test-payment-token', $statusTransition); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/payments/{payment-token}/status-transitions', array('payment-token' => 'test-payment-token'), $statusTransition, array()); + } + + public function testGetPaymentStatusTransition_noPaymentToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getPaymentStatusTransition('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paymentToken is required!', $e->getMessage()); + } + } + + public function testGetPaymentStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getPaymentStatusTransition('test-payment-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetPaymentStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/payments/{payment-token}/status-transitions/{status-transition-token}', array('payment-token' => 'test-payment-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $statusTransition = $client->getPaymentStatusTransition('test-payment-token', 'test-status-transition-token'); + $this->assertNotNull($statusTransition); + $this->assertEquals(array('success' => 'true'), $statusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/payments/{payment-token}/status-transitions/{status-transition-token}', array('payment-token' => 'test-payment-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + + public function testListPaymentStatusTransitions_noPaymentToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listPaymentStatusTransitions( ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paymentToken is required!', $e->getMessage()); + } + } + + public function testListPaymentStatusTransitions_noParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/payments/{payment-token}/status-transitions', array('payment-token' => 'test-payment-token'), array())->thenReturn(array('count' => 1, 'data' => array())); + + // Run test + $statusTransitionList = $client->listPaymentStatusTransitions('test-payment-token'); + $this->assertNotNull($statusTransitionList); + $this->assertCount(0, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getCount()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/payments/{payment-token}/status-transitions', array('payment-token' => 'test-payment-token'), array()); + } + + public function testListPaymentStatusTransitions_withParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/payments/{payment-token}/status-transitions', array('payment-token' => 'test-payment-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('success' => 'true')))); + + // Run test + $statusTransitionList = $client->listPaymentStatusTransitions('test-payment-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/payments/{payment-token}/status-transitions', array('payment-token' => 'test-payment-token'), array('test' => 'value')); + } + //-------------------------------------- // Programs //-------------------------------------- From 50ec2df1f5c5afc091a0c69481e997ea79d0bae1 Mon Sep 17 00:00:00 2001 From: Artem_Pryzhkov Date: Mon, 2 Apr 2018 18:53:44 +0300 Subject: [PATCH 2/6] add bank cards endpoint + tests --- CHANGELOG.md | 1 + src/Hyperwallet/Hyperwallet.php | 192 +++++++++ src/Hyperwallet/Model/BankCard.php | 168 ++++++++ .../Model/BankCardStatusTransition.php | 21 + tests/Hyperwallet/Tests/HyperwalletTest.php | 374 +++++++++++++++++- .../Model/BankCardStatusTransitionTest.php | 81 ++++ .../Hyperwallet/Tests/Model/BankCardTest.php | 81 ++++ 7 files changed, 917 insertions(+), 1 deletion(-) create mode 100644 src/Hyperwallet/Model/BankCard.php create mode 100644 src/Hyperwallet/Model/BankCardStatusTransition.php create mode 100644 tests/Hyperwallet/Tests/Model/BankCardStatusTransitionTest.php create mode 100644 tests/Hyperwallet/Tests/Model/BankCardTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3df43a5c..09b4f161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog 0.2.0 (in progress) ------------------- +- Added bank card endpoint - Added payment status transition endpoint - Added get bank account status transition endpoint - Added list program account receipt endpoint diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index f3959869..16ca52e9 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -5,6 +5,8 @@ use Hyperwallet\Model\Balance; use Hyperwallet\Model\BankAccount; use Hyperwallet\Model\BankAccountStatusTransition; +use Hyperwallet\Model\BankCard; +use Hyperwallet\Model\BankCardStatusTransition; use Hyperwallet\Model\IProgramAware; use Hyperwallet\Model\Payment; use Hyperwallet\Model\PaymentStatusTransition; @@ -594,6 +596,196 @@ public function listBankAccountStatusTransitions($userToken, $bankAccountToken, }); } + //-------------------------------------- + // Bank Cards + //-------------------------------------- + + /** + * Create Bank Card + * + * @param string $userToken The user token + * @param BankCard $bankCard The bank card data + * @return BankCard + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function createBankCard($userToken, BankCard $bankCard) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + $body = $this->client->doPost('/rest/v3/users/{user-token}/bank-cards', array('user-token' => $userToken), $bankCard, array()); + return new BankCard($body); + } + + /** + * Get a bank card + * + * @param string $userToken The user token + * @param string $bankCardToken The bank card token + * @return BankCard + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getBankCard($userToken, $bankCardToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($bankCardToken)) { + throw new HyperwalletArgumentException('bankCardToken is required!'); + } + $body = $this->client->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}', array( + 'user-token' => $userToken, + 'bank-card-token' => $bankCardToken + ), array()); + return new BankCard($body); + } + + + /** + * Update a bank card + * + * @param string $userToken The user token + * @param BankCard $bankCard The bank card data + * @return BankCard + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function updateBankCard($userToken, BankCard $bankCard) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (!$bankCard->getToken()) { + throw new HyperwalletArgumentException('token is required!'); + } + $body = $this->client->doPut('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}', array( + 'user-token' => $userToken, + 'bank-card-token' => $bankCard->getToken() + ), $bankCard, array()); + return new BankCard($body); + } + + /** + * List all bank cards + * + * @param string $userToken The user token + * @param array $options The query parameters to send + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listBankCards($userToken, $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + $body = $this->client->doGet('/rest/v3/users/{user-token}/bank-cards', array('user-token' => $userToken), $options); + return new ListResponse($body, function($entry) { + return new BankCard($entry); + }); + } + + /** + * @param string $userToken The user token + * @param string $bankCardToken The bank card token + * @return BankCardStatusTransition + * + * @throws HyperwalletApiException + * @throws HyperwalletArgumentException + */ + public function deactivateBankCard($userToken, $bankCardToken) { + $transition = new BankCardStatusTransition(); + $transition->setTransition(BankCardStatusTransition::TRANSITION_DE_ACTIVATED); + + return $this->createBankCardStatusTransition($userToken, $bankCardToken, $transition); + } + + /** + * Create a bank card status transition + * + * @param string $userToken The user token + * @param string $bankCardToken The bank card token + * @param BankCardStatusTransition $transition The status transition + * @return BankCardStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function createBankCardStatusTransition($userToken, $bankCardToken, BankCardStatusTransition $transition) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($bankCardToken)) { + throw new HyperwalletArgumentException('bankCardToken is required!'); + } + + $body = $this->client->doPost('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array( + 'user-token' => $userToken, + 'bank-card-token' => $bankCardToken + ), $transition, array()); + return new BankCardStatusTransition($body); + } + + /** + * Get a bank card status transition + * + * @param $userToken The user token + * @param $bankCardToken The bank card token + * @param $statusTransitionToken The status transition token + * @return BankCardStatusTransition + * + * @throws HyperwalletApiException + * @throws HyperwalletArgumentException + */ + public function getBankCardStatusTransition($userToken, $bankCardToken, $statusTransitionToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($bankCardToken)) { + throw new HyperwalletArgumentException('bankCardToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions/{status-transition-token}', array( + 'user-token' => $userToken, + 'bank-card-token' => $bankCardToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new BankCardStatusTransition($body); + } + + /** + * List all bank card status transitions + * + * @param string $userToken The user token + * @param string $bankCardToken The bank card token + * @param array $options The query parameters + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listBankCardStatusTransitions($userToken, $bankCardToken, array $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($bankCardToken)) { + throw new HyperwalletArgumentException('bankCardToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array( + 'user-token' => $userToken, + 'bank-card-token' => $bankCardToken + ), $options); + return new ListResponse($body, function($entry) { + return new BankCardStatusTransition($entry); + }); + } + //-------------------------------------- // Transfer Methods //-------------------------------------- diff --git a/src/Hyperwallet/Model/BankCard.php b/src/Hyperwallet/Model/BankCard.php new file mode 100644 index 00000000..ef0ac676 --- /dev/null +++ b/src/Hyperwallet/Model/BankCard.php @@ -0,0 +1,168 @@ +token; + } + + /** + * Get the bank card token + * + * @param string $token + * @return BankCard + */ + public function setToken($token) { + $this->token = $token; + return $this; + } + + /** + * Get the transfer method type + * + * @return string + */ + public function getType() { + return $this->type; + } + + /** + * Set the transfer method type + * + * @param string $type + * @return BankCard + */ + public function setType($type) { + $this->type = $type; + return $this; + } + + /** + * Get the bank card status + * + * @return string + */ + public function getStatus() { + return $this->status; + } + + /** + * Get the bank card creation date + * + * @return \DateTime + */ + public function getCreatedOn() { + return $this->createdOn ? new \DateTime($this->createdOn) : null; + } + + /** + * Get the bank card country + * + * @return string + */ + public function getTransferMethodCountry() { + return $this->transferMethodCountry; + } + + /** + * Get the bank card currency + * + * @return string + */ + public function getTransferMethodCurrency() { + return $this->transferMethodCurrency; + } + + /** + * Get the bank card brand + * + * @return string + */ + public function getCardBrand() { + return $this->cardBrand; + } + + /** + * Get the bank card number + * + * @return string + */ + public function getCardNumber() { + return $this->cardNumber; + } + + /** + * Get the bank card type + * + * @return string + */ + public function getCardType() { + return $this->cardType; + } + + /** + * Get the bank card expiry date + * + * @return \DateTime + */ + public function getDateOfExpiry() { + return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null; + } + +} \ No newline at end of file diff --git a/src/Hyperwallet/Model/BankCardStatusTransition.php b/src/Hyperwallet/Model/BankCardStatusTransition.php new file mode 100644 index 00000000..0d56cb65 --- /dev/null +++ b/src/Hyperwallet/Model/BankCardStatusTransition.php @@ -0,0 +1,21 @@ +doGet('/rest/v3/users/{user-token}/bank-accounts/{bank-account-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-account-token' => 'test-bank-account-token'), array('test' => 'value')); } + //-------------------------------------- + // Bank Cards + //-------------------------------------- + + public function testCreateBankCard_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $bankCard = new BankCard(); + + try { + $client->createBankCard('', $bankCard); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testCreateBankCard_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $bankCard = new BankCard(); + + \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/bank-cards', array('user-token' => 'test-user-token'), $bankCard, array())->thenReturn(array('success' => 'true')); + + // Run test + $newBankCard = $client->createBankCard('test-user-token', $bankCard); + $this->assertNotNull($newBankCard); + $this->assertEquals(array('success' => 'true'), $newBankCard->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/bank-cards', array('user-token' => 'test-user-token'), $bankCard, array()); + } + + public function testGetBankCard_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + try { + $client->getBankCard('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetBankCard_noBankCardToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + try { + $client->getBankCard('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('bankCardToken is required!', $e->getMessage()); + } + } + + public function testGetBankCard_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $bankCard = $client->getBankCard('test-user-token', 'test-bank-card-token'); + $this->assertNotNull($bankCard); + $this->assertEquals(array('success' => 'true'), $bankCard->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), array()); + } + + public function testUpdateBankCard_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $bankCard = new BankCard(); + + try { + $client->updateBankCard('', $bankCard); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testUpdateBankCard_noToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $bankCard = new BankCard(); + + try { + $client->updateBankCard('test-user-token', $bankCard); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('token is required!', $e->getMessage()); + } + } + + public function testUpdateBankCard_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $bankCard = new BankCard(array('token' => 'test-bank-card-token')); + + \Phake::when($apiClientMock)->doPut('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), $bankCard, array())->thenReturn(array('success' => 'true')); + + // Run test + $newBankCard = $client->updateBankCard('test-user-token', $bankCard); + $this->assertNotNull($newBankCard); + $this->assertEquals(array('success' => 'true'), $newBankCard->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPut('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), $bankCard, array()); + } + + public function testListBankCards_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + try { + $client->listBankCards(''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListBankCards_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}/bank-cards', array('user-token' => 'test-user-token'), array())->thenReturn(array('count' => 1, 'data' => array())); + + // Run test + $bankCardList = $client->listBankCards('test-user-token'); + $this->assertNotNull($bankCardList); + $this->assertCount(0, $bankCardList); + $this->assertEquals(1, $bankCardList->getCount()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-cards', array('user-token' => 'test-user-token'), array()); + } + + public function testListBankCards_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}/bank-cards', array('user-token' => 'test-user-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('success' => 'true')))); + + // Run test + $bankCardList = $client->listBankCards('test-user-token', array('test' => 'value')); + $this->assertNotNull($bankCardList); + $this->assertCount(1, $bankCardList); + $this->assertEquals(1, $bankCardList->getCount()); + + $this->assertEquals(array('success' => 'true'), $bankCardList[0]->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-cards', array('user-token' => 'test-user-token'), array('test' => 'value')); + } + + public function testDeactivateBankCard_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->deactivateBankCard('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testDeactivateBankCard_noBankAccountToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->deactivateBankCard('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('bankCardToken is required!', $e->getMessage()); + } + } + + public function testDeactivateBankCard_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + $statusTransition = new BankCardStatusTransition(); + $statusTransition->setTransition(BankCardStatusTransition::TRANSITION_DE_ACTIVATED); + + \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + + // Run test + $newStatusTransition = $client->deactivateBankCard('test-user-token', 'test-bank-card-token'); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), $statusTransition, array()); + } + + public function testCreateBankCardStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $statusTransition = new BankCardStatusTransition(); + + try { + $client->createBankCardStatusTransition('', '', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testCreateBankCardStatusTransition_noBankCardToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $statusTransition = new BankCardStatusTransition(); + + try { + $client->createBankCardStatusTransition('test-user-token', '', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('bankCardToken is required!', $e->getMessage()); + } + } + + public function testCreateBankCardStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $statusTransition = new BankCardStatusTransition(array('transition' => 'test')); + + \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + + // Run test + $newStatusTransition = $client->createBankCardStatusTransition('test-user-token', 'test-bank-card-token', $statusTransition); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), $statusTransition, array()); + } + + public function testGetBankCardStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBankCardStatusTransition('', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetBankCardStatusTransition_noBankCardToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBankCardStatusTransition('test-user-token', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('bankCardToken is required!', $e->getMessage()); + } + } + + public function testGetBankCardStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getPrepaidCardStatusTransition('test-user-token', 'test-bank-card-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetBankCardStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $statusTransition = $client->getBankCardStatusTransition('test-user-token', 'test-bank-card-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}/bank-cards/{bank-card-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + + public function testListBankCardStatusTransitions_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listBankCardStatusTransitions('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListBankCardStatusTransitions_noBankCardToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listBankCardStatusTransitions('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('bankCardToken is required!', $e->getMessage()); + } + } + + public function testListBankCardStatusTransitions_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}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), array())->thenReturn(array('count' => 1, 'data' => array())); + + // Run test + $statusTransitionList = $client->listBankCardStatusTransitions('test-user-token', 'test-bank-card-token'); + $this->assertNotNull($statusTransitionList); + $this->assertCount(0, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getCount()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), array()); + } + + public function testListBankCardStatusTransitions_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}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('success' => 'true')))); + + // Run test + $statusTransitionList = $client->listBankCardStatusTransitions('test-user-token', 'test-bank-card-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}/bank-cards/{bank-card-token}/status-transitions', array('user-token' => 'test-user-token', 'bank-card-token' => 'test-bank-card-token'), array('test' => 'value')); + } + + //-------------------------------------- // Transfer Methods //-------------------------------------- @@ -2053,5 +2426,4 @@ public function prepaidCardStatusTransitionProvider() { 'unlockPrepaidCard' => array('unlockPrepaidCard', PrepaidCardStatusTransition::TRANSITION_UNLOCKED) ); } - } diff --git a/tests/Hyperwallet/Tests/Model/BankCardStatusTransitionTest.php b/tests/Hyperwallet/Tests/Model/BankCardStatusTransitionTest.php new file mode 100644 index 00000000..24f86fa8 --- /dev/null +++ b/tests/Hyperwallet/Tests/Model/BankCardStatusTransitionTest.php @@ -0,0 +1,81 @@ +performGettersForIgnoredPropertiesTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGettersAndSettersForNotIgnoredProperties($property) { + $this->performGettersAndSettersForNotIgnoredPropertiesTest($property); + } + + /** + * @dataProvider propertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterReturnValueIsSet($property) { + $this->performGetterReturnValueIsSetTest($property); + } + + /** + * @dataProvider propertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterReturnValueIsNotSet($property) { + $this->performGetterReturnValueIsNotSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsSet($property) { + $this->performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsNotSet($property) { + $this->performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsNotSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterNullField($property) { + $this->performGetterAndSetterNullFieldTest($property); + } + + public function testTokenSetterTestWithValue() { + $this->performTokenSetterTestWithValue(); + } + + public function testTokenSetterTestWithoutValue() { + $this->performTokenSetterTestWithoutValue(); + } + +} diff --git a/tests/Hyperwallet/Tests/Model/BankCardTest.php b/tests/Hyperwallet/Tests/Model/BankCardTest.php new file mode 100644 index 00000000..fe71fbf7 --- /dev/null +++ b/tests/Hyperwallet/Tests/Model/BankCardTest.php @@ -0,0 +1,81 @@ +performGettersForIgnoredPropertiesTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGettersAndSettersForNotIgnoredProperties($property) { + $this->performGettersAndSettersForNotIgnoredPropertiesTest($property); + } + + /** + * @dataProvider propertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterReturnValueIsSet($property) { + $this->performGetterReturnValueIsSetTest($property); + } + + /** + * @dataProvider propertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterReturnValueIsNotSet($property) { + $this->performGetterReturnValueIsNotSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsSet($property) { + $this->performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsNotSet($property) { + $this->performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsNotSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterNullField($property) { + $this->performGetterAndSetterNullFieldTest($property); + } + + public function testTokenSetterTestWithValue() { + $this->performTokenSetterTestWithValue(); + } + + public function testTokenSetterTestWithoutValue() { + $this->performTokenSetterTestWithoutValue(); + } + +} From 3de2e73c3554130b74d2cbf2b4f554842bf31b0f Mon Sep 17 00:00:00 2001 From: aserediuk_epam Date: Wed, 4 Apr 2018 13:07:05 +0300 Subject: [PATCH 3/6] Added paper checks and paper check status transition endpoints --- src/Hyperwallet/Hyperwallet.php | 193 ++++++ src/Hyperwallet/Model/PaperCheck.php | 564 ++++++++++++++++++ .../Model/PaperCheckStatusTransition.php | 22 + tests/Hyperwallet/Tests/HyperwalletTest.php | 372 ++++++++++++ .../Tests/Model/PaperCheckTest.php | 80 +++ 5 files changed, 1231 insertions(+) create mode 100644 src/Hyperwallet/Model/PaperCheck.php create mode 100644 src/Hyperwallet/Model/PaperCheckStatusTransition.php create mode 100644 tests/Hyperwallet/Tests/Model/PaperCheckTest.php diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 16ca52e9..6cf4f279 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -10,6 +10,8 @@ use Hyperwallet\Model\IProgramAware; use Hyperwallet\Model\Payment; use Hyperwallet\Model\PaymentStatusTransition; +use Hyperwallet\Model\PaperCheck; +use Hyperwallet\Model\PaperCheckStatusTransition; use Hyperwallet\Model\PrepaidCard; use Hyperwallet\Model\PrepaidCardStatusTransition; use Hyperwallet\Model\Program; @@ -129,6 +131,197 @@ public function listUsers($options = array()) { }); } + //-------------------------------------- + // Paper Checks + //-------------------------------------- + + /** + * Create a paper check + * + * @param string $userToken The user token + * @param PaperCheck $paperCheck The paper check data + * @return PaperCheck + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function createPaperCheck($userToken, PaperCheck $paperCheck) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + $body = $this->client->doPost('/rest/v3/users/{user-token}/paper-checks', array('user-token' => $userToken), $paperCheck, array()); + return new PaperCheck($body); + } + + /** + * Get a paper check + * + * @param string $userToken The user token + * @param string $paperCheckToken The paper check token + * @return PaperCheck + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getPaperCheck($userToken, $paperCheckToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($paperCheckToken)) { + throw new HyperwalletArgumentException('paperCheckToken is required!'); + } + $body = $this->client->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}', array( + 'user-token' => $userToken, + 'paper-check-token' => $paperCheckToken + ), array()); + return new PaperCheck($body); + } + + /** + * Update a paper check + * + * @param string $userToken The user token + * @param PaperCheck $paperCheck The paper check data + * @return PaperCheck + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function updatePaperCheck($userToken, PaperCheck $paperCheck) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (!$paperCheck->getToken()) { + throw new HyperwalletArgumentException('token is required!'); + } + $body = $this->client->doPut('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}', array( + 'user-token' => $userToken, + 'paper-check-token' => $paperCheck->getToken() + ), $paperCheck, array()); + return new PaperCheck($body); + } + + /** + * List all paper checks + * + * @param string $userToken The user token + * @param array $options The query parameters to send + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listPaperChecks($userToken, $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + $body = $this->client->doGet('/rest/v3/users/{user-token}/paper-checks', array('user-token' => $userToken), $options); + return new ListResponse($body, function($entry) { + return new PaperCheck($entry); + }); + } + + /** + * Deactivate a paper check + * + * @param string $userToken The user token + * @param string $paperCheckToken The paper check token + * @return PaperCheckStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function deactivatePaperCheck($userToken, $paperCheckToken) { + $transition = new PaperCheckStatusTransition(); + $transition->setTransition(PaperCheckStatusTransition::TRANSITION_DE_ACTIVATED); + + return $this->createPaperCheckStatusTransition($userToken, $paperCheckToken, $transition); + } + + /** + * Create a paper check status transition + * + * @param string $userToken The user token + * @param string $paperCheckToken The paper check token + * @param PaperCheckStatusTransition $transition The status transition + * @return PaperCheckStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function createPaperCheckStatusTransition($userToken, $paperCheckToken, PaperCheckStatusTransition $transition) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($paperCheckToken)) { + throw new HyperwalletArgumentException('paperCheckToken is required!'); + } + + $body = $this->client->doPost('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array( + 'user-token' => $userToken, + 'paper-check-token' => $paperCheckToken + ), $transition, array()); + return new PaperCheckStatusTransition($body); + } + + /** + * Get a paper check status transition + * + * @param string $userToken The user token + * @param string $paperCheckToken The paper check token + * @param string $statusTransitionToken The status transition token + * @return PaperCheckStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getPaperCheckStatusTransition($userToken, $paperCheckToken, $statusTransitionToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($paperCheckToken)) { + throw new HyperwalletArgumentException('paperCheckToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions/{status-transition-token}', array( + 'user-token' => $userToken, + 'paper-check-token' => $paperCheckToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new PaperCheckStatusTransition($body); + } + + /** + * List all paper check status transitions + * + * @param string $userToken The user token + * @param string $paperCheckToken The paper check token + * @param array $options The query parameters + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listPaperCheckStatusTransitions($userToken, $paperCheckToken, array $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($paperCheckToken)) { + throw new HyperwalletArgumentException('paperCheckToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array( + 'user-token' => $userToken, + 'paper-check-token' => $paperCheckToken + ), $options); + return new ListResponse($body, function($entry) { + return new PaperCheckStatusTransition($entry); + }); + } + //-------------------------------------- // Prepaid Cards //-------------------------------------- diff --git a/src/Hyperwallet/Model/PaperCheck.php b/src/Hyperwallet/Model/PaperCheck.php new file mode 100644 index 00000000..40bb2a7c --- /dev/null +++ b/src/Hyperwallet/Model/PaperCheck.php @@ -0,0 +1,564 @@ +token; + } + + /** + * Set the paper check token + * + * @param string $token + * @return PaperCheck + */ + public function setToken($token) { + $this->token = $token; + return $this; + } + + /** + * Get the paper check status + * + * @return string + */ + public function getStatus() { + return $this->status; + } + + /** + * Get the paper check creation date + * + * @return \DateTime + */ + public function getCreatedOn() { + return $this->createdOn ? new \DateTime($this->createdOn) : null; + } + + /** + * Get the transfer method type + * + * @return string + */ + public function getType() { + return $this->type; + } + + /** + * Set the transfer method type + * + * @param string $type + * @return PaperCheck + */ + public function setType($type) { + $this->type = $type; + return $this; + } + + /** + * Get the transfer method country + * + * @return string + */ + public function getTransferMethodCountry() { + return $this->transferMethodCountry; + } + + /** + * Set the transfer method country + * + * @param string $transferMethodCountry + * @return PaperCheck + */ + public function setTransferMethodCountry($transferMethodCountry) { + $this->transferMethodCountry = $transferMethodCountry; + return $this; + } + + /** + * Get the transfer method currency + * + * @return string + */ + public function getTransferMethodCurrency() { + return $this->transferMethodCurrency; + } + + /** + * Set the transfer method currency + * + * @param string $transferMethodCurrency + * @return PaperCheck + */ + public function setTransferMethodCurrency($transferMethodCurrency) { + $this->transferMethodCurrency = $transferMethodCurrency; + return $this; + } + + /** + * Get the address line #1 + * + * @return string + */ + public function getAddressLine1() { + return $this->addressLine1; + } + + /** + * Set the address line #1 + * + * @param string $addressLine1 + * @return PaperCheck + */ + public function setAddressLine1($addressLine1) { + $this->addressLine1 = $addressLine1; + return $this; + } + + /** + * Get the address line #2 + * + * @return string + */ + public function getAddressLine2() { + return $this->addressLine2; + } + + /** + * Set the address line #2 + * + * @param string $addressLine2 + * @return PaperCheck + */ + public function setAddressLine2($addressLine2) { + $this->addressLine2 = $addressLine2; + return $this; + } + + /** + * Get the bank account relationship + * + * @return string + */ + public function getBankAccountRelationship() { + return $this->bankAccountRelationship; + } + + /** + * Set the bank account relationship + * + * @param string $bankAccountRelationship + * @return PaperCheck + */ + public function setBankAccountRelationship($bankAccountRelationship) { + $this->bankAccountRelationship = $bankAccountRelationship; + return $this; + } + + /** + * Get the business contact role + * + * @return string + */ + public function getBusinessContactRole() { + return $this->businessContactRole; + } + + /** + * Get the business name + * + * @return string + */ + public function getBusinessName() { + return $this->businessName; + } + + /** + * Get the business registration country + * + * @return string + */ + public function getBusinessRegistrationCountry() { + return $this->businessRegistrationCountry; + } + + /** + * Get the business registration id + * + * @return string + */ + public function getBusinessRegistrationId() { + return $this->businessRegistrationId; + } + + /** + * Get the business registration state province + * + * @return string + */ + public function getBusinessRegistrationStateProvince() { + return $this->businessRegistrationStateProvince; + } + + /** + * Get the business type + * + * @return string + */ + public function getBusinessType() { + return $this->businessType; + } + + /** + * Get the city + * + * @return string + */ + public function getCity() { + return $this->city; + } + + /** + * Set the city + * + * @param string $city + * @return PaperCheck + */ + public function setCity($city) { + $this->city = $city; + return $this; + } + + /** + * Get the country + * + * @return string + */ + public function getCountry() { + return $this->country; + } + + /** + * Set the country + * + * @param string $country + * @return PaperCheck + */ + public function setCountry($country) { + $this->country = $country; + return $this; + } + + /** + * Get the country of birth + * + * @return string + */ + public function getCountryOfBirth() { + return $this->countryOfBirth; + } + + /** + * Get the country of nationality + * + * @return string + */ + public function getCountryOfNationality() { + return $this->countryOfNationality; + } + + /** + * Get the date of birth + * + * @return \DateTime + */ + public function getDateOfBirth() { + return $this->dateOfBirth ? new \DateTime($this->dateOfBirth) : null; + } + + /** + * Get the drivers license id + * + * @return string + */ + public function getDriversLicenseId() { + return $this->driversLicenseId; + } + + /** + * Get the employer id + * + * @return string + */ + public function getEmployerId() { + return $this->employerId; + } + + /** + * Get the first name + * + * @return string + */ + public function getFirstName() { + return $this->firstName; + } + + /** + * Get the gender + * + * @return string + */ + public function getGender() { + return $this->gender; + } + + /** + * Get the government id + * + * @return string + */ + public function getGovernmentId() { + return $this->governmentId; + } + + /** + * Get the government id type + * + * @return string + */ + public function getGovernmentIdType() { + return $this->governmentIdType; + } + + /** + * Get the is default transfer method + * + * @return string + */ + public function getIsDefaultTransferMethod() { + return $this->isDefaultTransferMethod; + } + + /** + * Set the is default transfer method + * + * @param string $isDefaultTransferMethod + * @return PaperCheck + */ + public function setIsDefaultTransferMethod($isDefaultTransferMethod) { + $this->isDefaultTransferMethod = $isDefaultTransferMethod; + return $this; + } + + /** + * Get the last name + * + * @return string + */ + public function getLastName() { + return $this->lastName; + } + + /** + * Get the middle name + * + * @return string + */ + public function getMiddleName() { + return $this->middleName; + } + + /** + * Get the mobile number + * + * @return string + */ + public function getMobileNumber() { + return $this->mobileNumber; + } + + /** + * Get the passport id + * + * @return string + */ + public function getPassportId() { + return $this->passportId; + } + + /** + * Get the phone number + * + * @return string + */ + public function getPhoneNumber() { + return $this->phoneNumber; + } + + /** + * Get the postal code + * + * @return string + */ + public function getPostalCode() { + return $this->postalCode; + } + + /** + * Set the postal code + * + * @param string $postalCode + * @return PaperCheck + */ + public function setPostalCode($postalCode) { + $this->postalCode = $postalCode; + return $this; + } + + /** + * Get the profile type + * + * @return string + */ + public function getProfileType() { + return $this->profileType; + } + + /** + * Get the shipping method + * + * @return string + */ + public function getShippingMethod() { + return $this->shippingMethod; + } + + /** + * Set the shipping method + * + * @param string $shippingMethod + * @return PaperCheck + */ + public function setShippingMethod($shippingMethod) { + $this->shippingMethod = $shippingMethod; + return $this; + } + + /** + * Get the state province + * + * @return string + */ + public function getStateProvince() { + return $this->stateProvince; + } + + /** + * Set the state province + * + * @param string $stateProvince + * @return PaperCheck + */ + public function setStateProvince($stateProvince) { + $this->stateProvince = $stateProvince; + return $this; + } + +} \ No newline at end of file diff --git a/src/Hyperwallet/Model/PaperCheckStatusTransition.php b/src/Hyperwallet/Model/PaperCheckStatusTransition.php new file mode 100644 index 00000000..9aaae4c8 --- /dev/null +++ b/src/Hyperwallet/Model/PaperCheckStatusTransition.php @@ -0,0 +1,22 @@ +doGet('/rest/v3/users', array(), array('test' => 'value')); } + //-------------------------------------- + // Paper Checks + //-------------------------------------- + + public function testCreatePaperCheck_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $paperCheck = new PaperCheck(); + + try { + $client->createPaperCheck('', $paperCheck); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testCreatePaperCheck_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $paperCheck = new PaperCheck(); + + \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/paper-checks', array('user-token' => 'test-user-token'), $paperCheck, array())->thenReturn(array('postalCode' => 'ABCD')); + + // Run test + $newPaperCheck = $client->createPaperCheck('test-user-token', $paperCheck); + $this->assertNotNull($newPaperCheck); + $this->assertEquals(array('postalCode' => 'ABCD'), $newPaperCheck->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/paper-checks', array('user-token' => 'test-user-token'), $paperCheck, array()); + } + + public function testGetPaperCheck_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + try { + $client->getPaperCheck('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetPaperCheck_noPaperCheckToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + try { + $client->getPaperCheck('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paperCheckToken is required!', $e->getMessage()); + } + } + + public function testGetPaperCheck_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), array())->thenReturn(array('postalCode' => 'ABCD')); + + // Run test + $paperCheck = $client->getPaperCheck('test-user-token', 'test-paper-check-token'); + $this->assertNotNull($paperCheck); + $this->assertEquals(array('postalCode' => 'ABCD'), $paperCheck->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), array()); + } + + public function testUpdatePaperCheck_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $paperCheck = new PaperCheck(); + + try { + $client->updatePaperCheck('', $paperCheck); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testUpdatePaperCheck_noToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $paperCheck = new PaperCheck(); + + try { + $client->updatePaperCheck('test-user-token', $paperCheck); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('token is required!', $e->getMessage()); + } + } + + public function testUpdatePaperCheck_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $paperCheck = new PaperCheck(array('token' => 'test-paper-check-token')); + + \Phake::when($apiClientMock)->doPut('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), $paperCheck, array())->thenReturn(array('postalCode' => 'ABCD')); + + // Run test + $newPaperCheck = $client->updatePaperCheck('test-user-token', $paperCheck); + $this->assertNotNull($newPaperCheck); + $this->assertEquals(array('postalCode' => 'ABCD'), $newPaperCheck->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPut('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), $paperCheck, array()); + } + + public function testListPaperChecks_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + try { + $client->listPaperChecks(''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListPaperChecks_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}/paper-checks', array('user-token' => 'test-user-token'), array())->thenReturn(array('count' => 1, 'data' => array())); + + // Run test + $paperCheckList = $client->listPaperChecks('test-user-token'); + $this->assertNotNull($paperCheckList); + $this->assertCount(0, $paperCheckList); + $this->assertEquals(1, $paperCheckList->getCount()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks', array('user-token' => 'test-user-token'), array()); + } + + public function testListPaperChecks_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}/paper-checks', array('user-token' => 'test-user-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('postalCode' => 'ABCD')))); + + // Run test + $paperCheckList = $client->listPaperChecks('test-user-token', array('test' => 'value')); + $this->assertNotNull($paperCheckList); + $this->assertCount(1, $paperCheckList); + $this->assertEquals(1, $paperCheckList->getCount()); + + $this->assertEquals(array('postalCode' => 'ABCD'), $paperCheckList[0]->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks', array('user-token' => 'test-user-token'), array('test' => 'value')); + } + + public function testDeactivatePaperCheck_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->deactivatePaperCheck('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testDeactivatePaperCheck_noPaperCheckToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->deactivatePaperCheck('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paperCheckToken is required!', $e->getMessage()); + } + } + + public function testDeactivatePaperCheck_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + $statusTransition = new PaperCheckStatusTransition(); + $statusTransition->setTransition(PaperCheckStatusTransition::TRANSITION_DE_ACTIVATED); + + \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), $statusTransition, array())->thenReturn(array('postalCode' => 'ABCD')); + + // Run test + $newStatusTransition = $client->deactivatePaperCheck('test-user-token', 'test-paper-check-token'); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('postalCode' => 'ABCD'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), $statusTransition, array()); + } + + public function testCreatePaperCheckStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $statusTransition = new PaperCheckStatusTransition(); + + try { + $client->createPaperCheckStatusTransition('', '', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testCreatePaperCheckStatusTransition_noPaperCheckToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $statusTransition = new PaperCheckStatusTransition(); + + try { + $client->createPaperCheckStatusTransition('test-user-token', '', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paperCheckToken is required!', $e->getMessage()); + } + } + + public function testCreatePaperCheckStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $statusTransition = new PaperCheckStatusTransition(array('transition' => 'test')); + + \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), $statusTransition, array())->thenReturn(array('postalCode' => 'ABCD')); + + // Run test + $newStatusTransition = $client->createPaperCheckStatusTransition('test-user-token', 'test-paper-check-token', $statusTransition); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('postalCode' => 'ABCD'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), $statusTransition, array()); + } + + public function testGetPaperCheckStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getPaperCheckStatusTransition('', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetPaperCheckStatusTransition_noPaperCheckToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getPaperCheckStatusTransition('test-user-token', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paperCheckToken is required!', $e->getMessage()); + } + } + + public function testGetPaperCheckStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getPaperCheckStatusTransition('test-user-token', 'test-paper-check-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetPaperCheckStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('postalCode' => 'ABCD')); + + // Run test + $statusTransition = $client->getPaperCheckstatusTransition('test-user-token', 'test-paper-check-token', 'test-status-transition-token'); + $this->assertNotNull($statusTransition); + $this->assertEquals(array('postalCode' => 'ABCD'), $statusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + + public function testListPaperCheckStatusTransitions_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listPaperCheckStatusTransitions('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListPaperCheckStatusTransitions_noPaperCheckToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listPaperCheckStatusTransitions('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('paperCheckToken is required!', $e->getMessage()); + } + } + + public function testListPaperCheckStatusTransitions_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}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), array())->thenReturn(array('count' => 1, 'data' => array())); + + // Run test + $statusTransitionList = $client->listPaperCheckStatusTransitions('test-user-token', 'test-paper-check-token'); + $this->assertNotNull($statusTransitionList); + $this->assertCount(0, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getCount()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), array()); + } + + public function testListPaperCheckStatusTransitions_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}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('postalCode' => 'ABCD')))); + + // Run test + $statusTransitionList = $client->listPaperCheckStatusTransitions('test-user-token', 'test-paper-check-token', array('test' => 'value')); + $this->assertNotNull($statusTransitionList); + $this->assertCount(1, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getCount()); + + $this->assertEquals(array('postalCode' => 'ABCD'), $statusTransitionList[0]->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/paper-checks/{paper-check-token}/status-transitions', array('user-token' => 'test-user-token', 'paper-check-token' => 'test-paper-check-token'), array('test' => 'value')); + } + //-------------------------------------- // Prepaid Cards //-------------------------------------- diff --git a/tests/Hyperwallet/Tests/Model/PaperCheckTest.php b/tests/Hyperwallet/Tests/Model/PaperCheckTest.php new file mode 100644 index 00000000..fe75d176 --- /dev/null +++ b/tests/Hyperwallet/Tests/Model/PaperCheckTest.php @@ -0,0 +1,80 @@ +performGettersForIgnoredPropertiesTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGettersAndSettersForNotIgnoredProperties($property) { + $this->performGettersAndSettersForNotIgnoredPropertiesTest($property); + } + + /** + * @dataProvider propertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterReturnValueIsSet($property) { + $this->performGetterReturnValueIsSetTest($property); + } + + /** + * @dataProvider propertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterReturnValueIsNotSet($property) { + $this->performGetterReturnValueIsNotSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsSet($property) { + $this->performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsNotSet($property) { + $this->performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDefaultIsNotSetTest($property); + } + + /** + * @dataProvider notIgnoredPropertiesProvider + * + * @param string $property The property to look for + */ + public function testGetterAndSetterNullField($property) { + $this->performGetterAndSetterNullFieldTest($property); + } + + public function testTokenSetterTestWithValue() { + $this->performTokenSetterTestWithValue(); + } + + public function testTokenSetterTestWithoutValue() { + $this->performTokenSetterTestWithoutValue(); + } +} From a45cdf64fb3755a0cc490d7672a536c63b79a26a Mon Sep 17 00:00:00 2001 From: aserediuk_epam Date: Wed, 4 Apr 2018 17:53:58 +0300 Subject: [PATCH 4/6] fixed paper checks endpoints --- src/Hyperwallet/Model/PaperCheck.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Hyperwallet/Model/PaperCheck.php b/src/Hyperwallet/Model/PaperCheck.php index 40bb2a7c..bddf355f 100644 --- a/src/Hyperwallet/Model/PaperCheck.php +++ b/src/Hyperwallet/Model/PaperCheck.php @@ -521,6 +521,17 @@ public function getProfileType() { return $this->profileType; } + /** + * Set the profile type + * + * @param string $shippingMethod + * @return PaperCheck + */ + public function setProfileType($profileType) { + $this->profileType = $profileType; + return $this; + } + /** * Get the shipping method * From 588b838be82107d7f2812141cf4254bd424e0ad0 Mon Sep 17 00:00:00 2001 From: akreisman-epam Date: Thu, 5 Apr 2018 16:02:04 +0300 Subject: [PATCH 5/6] Fix read only properties for BankCard and PaperCheck --- src/Hyperwallet/Model/BankCard.php | 49 ++++++++++++++++++- src/Hyperwallet/Model/PaperCheck.php | 4 +- .../Hyperwallet/Tests/Model/ModelTestCase.php | 4 +- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/Hyperwallet/Model/BankCard.php b/src/Hyperwallet/Model/BankCard.php index ef0ac676..fce7dfa6 100644 --- a/src/Hyperwallet/Model/BankCard.php +++ b/src/Hyperwallet/Model/BankCard.php @@ -30,7 +30,7 @@ class BankCard extends BaseModel { * * @var string[] */ - private static $READ_ONLY_FIELDS = array('token', 'status', 'createdOn', 'transferMethodCountry', 'transferMethodCurrency', 'cardType', 'cardNumber', 'cardBrand', 'dateOfExpiry'); + private static $READ_ONLY_FIELDS = array('token', 'status', 'createdOn', 'cardType', 'cardBrand'); const TYPE_BANK_CARD = 'BANK_CARD'; @@ -120,6 +120,19 @@ public function getTransferMethodCountry() { return $this->transferMethodCountry; } + + /** + * Set the bank card country + * + * @param string $transferMethodCountry + * @return BankCard + */ + public function setTransferMethodCountry($transferMethodCountry) { + $this->transferMethodCountry = $transferMethodCountry; + return $this; + } + + /** * Get the bank card currency * @@ -129,6 +142,18 @@ public function getTransferMethodCurrency() { return $this->transferMethodCurrency; } + /** + * Set the bank card country + * + * @param string $transferMethodCurrency + * @return BankCard + */ + public function setTransferMethodCurrency($transferMethodCurrency) { + $this->transferMethodCurrency = $transferMethodCurrency; + return $this; + } + + /** * Get the bank card brand * @@ -147,6 +172,17 @@ public function getCardNumber() { return $this->cardNumber; } + /** + * Set the bank card number + * + * @param string $cardNumber + * @return BankCard + */ + public function setCardNumber($cardNumber) { + $this->cardNumber = $cardNumber; + return $this; + } + /** * Get the bank card type * @@ -165,4 +201,15 @@ public function getDateOfExpiry() { return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null; } + /** + * Set the bank card expiry date + * + * @param \DateTime $dateOfExpiry + * @return BankCard + */ + public function setDateOfExpiry(\DateTime $dateOfExpiry = null) { + $this->dateOfExpiry = $dateOfExpiry == null ? null : $dateOfExpiry->format('Y-m-d'); + return $this; + } + } \ No newline at end of file diff --git a/src/Hyperwallet/Model/PaperCheck.php b/src/Hyperwallet/Model/PaperCheck.php index bddf355f..45000eec 100644 --- a/src/Hyperwallet/Model/PaperCheck.php +++ b/src/Hyperwallet/Model/PaperCheck.php @@ -54,7 +54,7 @@ class PaperCheck extends BaseModel { * * @var string[] */ - private static $READ_ONLY_FIELDS = array('profileType', 'phoneNumber', 'passportId', 'mobileNumber', 'middleName', 'lastName', 'governmentIdType', 'governmentId', 'gender', 'firstName', 'employerId', 'driversLicenseId', 'dateOfBirth', 'countryOfNationality', 'countryOfBirth', 'businessType', 'businessRegistrationStateProvince', 'businessRegistrationId', 'businessRegistrationCountry', 'businessName', 'businessContactRole', 'createdOn', 'status', 'token'); + private static $READ_ONLY_FIELDS = array('phoneNumber', 'passportId', 'mobileNumber', 'middleName', 'lastName', 'governmentIdType', 'governmentId', 'gender', 'firstName', 'employerId', 'driversLicenseId', 'dateOfBirth', 'countryOfNationality', 'countryOfBirth', 'businessType', 'businessRegistrationStateProvince', 'businessRegistrationId', 'businessRegistrationCountry', 'businessName', 'businessContactRole', 'createdOn', 'status', 'token'); const TYPE_PAPER_CHECK = 'PAPER_CHECK'; @@ -524,7 +524,7 @@ public function getProfileType() { /** * Set the profile type * - * @param string $shippingMethod + * @param string $profileType * @return PaperCheck */ public function setProfileType($profileType) { diff --git a/tests/Hyperwallet/Tests/Model/ModelTestCase.php b/tests/Hyperwallet/Tests/Model/ModelTestCase.php index 5e1ff5fa..a6ec84ca 100644 --- a/tests/Hyperwallet/Tests/Model/ModelTestCase.php +++ b/tests/Hyperwallet/Tests/Model/ModelTestCase.php @@ -107,7 +107,7 @@ protected function performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDef if ($this->propertiesToType[$property] == '\DateTime') { $val = '2016-04-15T15:00:12'; $newVal = '2016-05-16T14:10:15'; - if ($property === 'dateOfBirth') { + if ($property === 'dateOfBirth' || $property === 'dateOfExpiry') { $val = '2016-04-15'; $newVal = '2016-05-16'; } @@ -153,7 +153,7 @@ protected function performGetterAndSetterReturnValueIsSetIfValueIsProvidedAndDef $newValParam = 'Test-ValueUp'; if ($this->propertiesToType[$property] == '\DateTime') { $newVal = '2016-05-16T14:10:15'; - if ($property === 'dateOfBirth') { + if ($property === 'dateOfBirth' || $property === 'dateOfExpiry') { $newVal = '2016-05-16'; } $newValParam = new \DateTime($newVal); From 7ce88f53367300ca7a61fc49cfc07bd78c519b6b Mon Sep 17 00:00:00 2001 From: akreisman-epam Date: Thu, 5 Apr 2018 18:37:01 +0300 Subject: [PATCH 6/6] Added get and retrive User Status Transition --- src/Hyperwallet/Hyperwallet.php | 49 ++++++++++ .../Model/UserStatusTransition.php | 20 ++++ tests/Hyperwallet/Tests/HyperwalletTest.php | 91 +++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/Hyperwallet/Model/UserStatusTransition.php diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 6cf4f279..41e0eb02 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -20,6 +20,7 @@ use Hyperwallet\Model\TransferMethod; use Hyperwallet\Model\TransferMethodConfiguration; use Hyperwallet\Model\User; +use Hyperwallet\Model\UserStatusTransition; use Hyperwallet\Model\WebhookNotification; use Hyperwallet\Response\ListResponse; use Hyperwallet\Util\ApiClient; @@ -131,6 +132,54 @@ public function listUsers($options = array()) { }); } + /** + * Get a user status transition + * + * @param string $userToken The user token + * @param string $statusTransitionToken The status transition token + * @return UserStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getUserStatusTransition($userToken, $statusTransitionToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/status-transitions/{status-transition-token}', array( + 'user-token' => $userToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new UserStatusTransition($body); + } + + /** + * List all user status transitions + * + * @param string $userToken The user token + * @param array $options The query parameters + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listUserStatusTransitions($userToken, array $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + + $body = $this->client->doGet('/rest/v3/users/{user-token}/status-transitions', array( + 'user-token' => $userToken + ), $options); + return new ListResponse($body, function($entry) { + return new UserStatusTransition($entry); + }); + } + //-------------------------------------- // Paper Checks //-------------------------------------- diff --git a/src/Hyperwallet/Model/UserStatusTransition.php b/src/Hyperwallet/Model/UserStatusTransition.php new file mode 100644 index 00000000..97530bf3 --- /dev/null +++ b/src/Hyperwallet/Model/UserStatusTransition.php @@ -0,0 +1,20 @@ +doGet('/rest/v3/users', array(), array('test' => 'value')); } + public function testGetUserStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getUserStatusTransition('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetUserStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getUserStatusTransition('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetUserStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $statusTransition = $client->getUserStatusTransition('test-user-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}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + + public function testListUserStatusTransitions_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listUserStatusTransitions( ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListUserStatusTransitions_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}/status-transitions', array('user-token' => 'test-user-token'), array())->thenReturn(array('count' => 1, 'data' => array())); + + // Run test + $statusTransitionList = $client->listUserStatusTransitions('test-user-token'); + $this->assertNotNull($statusTransitionList); + $this->assertCount(0, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getCount()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), array()); + } + + public function testListUserStatusTransitions_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}/status-transitions', array('user-token' => 'test-user-token'), array('test' => 'value'))->thenReturn(array('count' => 1, 'data' => array(array('success' => 'true')))); + + // Run test + $statusTransitionList = $client->listUserStatusTransitions('test-user-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}/status-transitions', array('user-token' => 'test-user-token'), array('test' => 'value')); + } + //-------------------------------------- // Paper Checks //--------------------------------------