Skip to content

Commit

Permalink
Merge pull request #123 from hyperwallet/feature/DTPAYETWO-759-HWPari…
Browse files Browse the repository at this point in the history
…ty_PayPalAccountPhpDev

Feature/dtpayetwo 759 hw parity paypal account php dev
  • Loading branch information
akswaminathan-pp-dev committed Aug 8, 2023
2 parents d9d5891 + 7ed283a commit 27747f2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,12 @@
ChangeLog
=========
2.4.4
2.2.5
-------------------
- Added field 'accountId' to PayPal.
- PayPal account creation allowed using field 'accountId' which accepts Email, Phone Number, PayPal PayerID.
- Venmo account creation allowed using field 'accountId' which accepts Email, Phone Number, Venmo Handle, Venmo External ID.

2.2.4
-------------------
- Added attribute 'isDefaultTransferMethod' to identify default accounts.

Expand Down
4 changes: 2 additions & 2 deletions src/Hyperwallet/Hyperwallet.php
Expand Up @@ -666,8 +666,8 @@ public function createPayPalAccount($userToken, PayPalAccount $payPalAccount) {
if (empty($payPalAccount->getTransferMethodCurrency())) {
throw new HyperwalletArgumentException('transferMethodCurrency is required!');
}
if (empty($payPalAccount->getEmail())) {
throw new HyperwalletArgumentException('email is required!');
if (empty($payPalAccount->getEmail()) and empty($payPalAccount->getAccountId()) ) {
throw new HyperwalletArgumentException('email or accountId is required!');
}
$body = $this->client->doPost('/rest/v4/users/{user-token}/paypal-accounts', array('user-token' => $userToken), $payPalAccount, array());
return new PayPalAccount($body);
Expand Down
21 changes: 21 additions & 0 deletions src/Hyperwallet/Model/PayPalAccount.php
Expand Up @@ -12,6 +12,7 @@
* @property string $transferMethodCurrency The transfer method currency
* @property bool $isDefaultTransferMethod The flag to denote default account
* @property string $email The PayPal account email
* @property string $accountId The PayPal account identifier
*
* @package Hyperwallet\Model
Expand Down Expand Up @@ -178,4 +179,24 @@ public function setEmail($email) {
$this->email = $email;
return $this;
}

/**
* Set the PayPal account identifier
*
* @param string $accountId
* @return PayPalAccount
*/
public function setAccountId($accountId) {
$this->accountId = $accountId;
return $this;
}

/**
* Get the PayPal account identifier
*
* @return string
*/
public function getAccountId() {
return $this->accountId;
}
}
25 changes: 23 additions & 2 deletions tests/Hyperwallet/Tests/HyperwalletTest.php
Expand Up @@ -1284,7 +1284,7 @@ public function testCreatePayPalAccount_noEmail() {
$client->createPayPalAccount('test-user-token', $payPalAccount);
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('email is required!', $e->getMessage());
$this->assertEquals('email or accountId is required!', $e->getMessage());
}
}

Expand Down Expand Up @@ -4036,7 +4036,7 @@ public function testListReceiptsForPrepaidCard_withParameters() {
// Validate mock
\Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/receipts', array('user-token' => 'test-user-token', 'prepaid-card-token' => 'test-prepaid-card-token'), array('createdBefore' => 'value'));
}

public function testListReceiptsForPrepaidCard_withInvalidFilter() {
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');
try {
Expand Down Expand Up @@ -5775,4 +5775,25 @@ public function testListTransferMethods_withParameters() {
// Validate mock
\Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array('type'=>TransferMethod::TYPE_PREPAID_CARD));
}

public function testCreatePayPalAccount_WithAccountId() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);
$payPalAccount = new PayPalAccount();
$payPalAccount->setTransferMethodCountry('test-transferMethodCountry');
$payPalAccount->setTransferMethodCurrency('test-transferMethodCurrency');
$payPalAccount->setAccountId('test-accountId');

\Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/paypal-accounts', array('user-token' => 'test-user-token'), $payPalAccount, array())->thenReturn(array('token' => 'test-token'));

// Run test
$newPayPalAccount = $client->createPayPalAccount('test-user-token', $payPalAccount);
$this->assertNotNull($newPayPalAccount);
$this->assertEquals(array('token' => 'test-token'), $newPayPalAccount->getProperties());


// Validate mock
\Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/paypal-accounts', array('user-token' => 'test-user-token'), $payPalAccount, array());
}
}

0 comments on commit 27747f2

Please sign in to comment.