Skip to content

Commit 15e1a3a

Browse files
SDKPHP-60 add withdrawal account endpoints (#97)
* Adds find withdrawal accounts endpoint * Adds withdrawal accounts pull funds endpoint * Tidy code
1 parent ff08e11 commit 15e1a3a

File tree

6 files changed

+665
-0
lines changed

6 files changed

+665
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace CurrencyCloud\Criteria;
3+
4+
class FindWithdrawalAccountsCriteria {
5+
6+
7+
/**
8+
* @var string
9+
*/
10+
private $accountId;
11+
12+
/**
13+
* @return string
14+
*/
15+
public function getAccountId()
16+
{
17+
return $this->accountId;
18+
}
19+
20+
/**
21+
* @param string $accountId
22+
* @return $this
23+
*/
24+
public function setAccountId($accountId)
25+
{
26+
$this->accountId = $accountId;
27+
return $this;
28+
}
29+
30+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace CurrencyCloud\EntryPoint;
4+
5+
use CurrencyCloud\Model\WithdrawalAccountFunds;
6+
use CurrencyCloud\Model\Pagination;
7+
use CurrencyCloud\Model\WithdrawalAccount;
8+
use CurrencyCloud\Model\WithdrawalAccounts;
9+
use CurrencyCloud\Criteria\FindWithdrawalAccountsCriteria;
10+
use DateTime;
11+
12+
class WithdrawalAccountsEntryPoint extends AbstractEntityEntryPoint
13+
{
14+
public function findWithdrawalAccounts(
15+
FindWithdrawalAccountsCriteria $findWithdrawalAccountsCriteria,
16+
Pagination $pagination)
17+
{
18+
if (null === $findWithdrawalAccountsCriteria) {
19+
$findWithdrawalAccountsCriteria = new FindWithdrawalAccountsCriteria();
20+
}
21+
if (null === $pagination) {
22+
$pagination = new Pagination();
23+
}
24+
return $this->doFind('withdrawal_accounts/find', $findWithdrawalAccountsCriteria, $pagination, function ($findWithdrawalAccountsCriteria) {
25+
return $this->convertFindWithdrawalAccountsCriteriaToRequest($findWithdrawalAccountsCriteria);
26+
}, function ($response) {
27+
return $this->convertResponseToWithdrawalAccount($response);
28+
}, function (array $entities, Pagination $pagination) {
29+
return new WithdrawalAccounts($entities, $pagination);
30+
}, 'withdrawal_accounts');
31+
}
32+
33+
/**
34+
* @param string $withdrawalAccountId
35+
* @param string $reference
36+
* @param string $amount
37+
*
38+
* @return WithdrawalAccountFunds
39+
*/
40+
public function pullFunds(
41+
$withdrawalAccountId,
42+
$reference,
43+
$amount
44+
) {
45+
$response = $this->request('POST',
46+
sprintf('withdrawal_accounts/%s/pull_funds', $withdrawalAccountId),
47+
[],
48+
[
49+
'reference' => $reference,
50+
'amount' => $amount
51+
]);
52+
53+
return $this->convertResponseToWithdrawalAccountFunds($response);
54+
}
55+
56+
57+
protected function convertFindWithdrawalAccountsCriteriaToRequest(FindWithdrawalAccountsCriteria $findWithdrawalAccountsCriteria){
58+
$common = [
59+
'account_id' => $findWithdrawalAccountsCriteria->getAccountId()
60+
];
61+
return $common;
62+
}
63+
64+
protected function convertResponseToWithdrawalAccount($response) {
65+
$withdrawalAccount = new WithdrawalAccount();
66+
67+
$this->setIdProperty($withdrawalAccount, $response->id, 'id');
68+
$withdrawalAccount->setAccountId($response->account_id);
69+
$withdrawalAccount->setAccountName($response->account_name);
70+
$withdrawalAccount->setAccountHolderName($response->account_holder_name);
71+
$withdrawalAccount->setAccountHolderDob(null !== $response->account_holder_dob ? new DateTime($response->account_holder_dob) : null);
72+
$withdrawalAccount->setRoutingCode($response->routing_code);
73+
$withdrawalAccount->setAccountNumber($response->account_number);
74+
$withdrawalAccount->setCurrency($response->currency);
75+
76+
return $withdrawalAccount;
77+
}
78+
79+
protected function convertResponseToWithdrawalAccountFunds($response) {
80+
$withdrawalAccountFunds = new WithdrawalAccountFunds();
81+
82+
$this->setIdProperty($withdrawalAccountFunds, $response->id, 'id');
83+
$withdrawalAccountFunds->setWithdrawalAccountId($response->withdrawal_account_id);
84+
$withdrawalAccountFunds->setReference($response->reference);
85+
$withdrawalAccountFunds->setAmount($response->amount);
86+
$withdrawalAccountFunds->setCreatedAt(null !== $response->created_at ? new DateTime($response->created_at) : null);
87+
88+
return $withdrawalAccountFunds;
89+
}
90+
91+
}

src/Model/WithdrawalAccount.php

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
namespace CurrencyCloud\Model;
3+
4+
use DateTime;
5+
6+
class WithdrawalAccount implements EntityInterface {
7+
8+
/**
9+
* @var string
10+
*/
11+
private $id;
12+
/**
13+
* @var string
14+
*/
15+
private $accountId;
16+
/**
17+
* @var string
18+
*/
19+
private $accountName;
20+
/**
21+
* @var string
22+
*/
23+
private $accountHolderName;
24+
/**
25+
* @var DateTime
26+
*/
27+
private $accountHolderDob;
28+
/**
29+
* @var string
30+
*/
31+
private $routingCode;
32+
/**
33+
* @var string
34+
*/
35+
private $accountNumber;
36+
/**
37+
* @var string
38+
*/
39+
private $currency;
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getId()
45+
{
46+
return $this->id;
47+
}
48+
49+
/**
50+
* @return string
51+
*/
52+
public function getAccountId()
53+
{
54+
return $this->accountId;
55+
}
56+
57+
/**
58+
* @param string $accountId
59+
* @return $this
60+
*/
61+
public function setAccountId($accountId)
62+
{
63+
$this->accountId = $accountId;
64+
return $this;
65+
}
66+
67+
/**
68+
* @return string
69+
*/
70+
public function getAccountName()
71+
{
72+
return $this->accountName;
73+
}
74+
75+
/**
76+
* @param string $accountName
77+
* @return $this
78+
*/
79+
public function setAccountName($accountName)
80+
{
81+
$this->accountName = $accountName;
82+
return $this;
83+
}
84+
85+
/**
86+
* @return string
87+
*/
88+
public function getAccountHolderName()
89+
{
90+
return $this->accountHolderName;
91+
}
92+
93+
/**
94+
* @param string $accountHolderName
95+
* @return $this
96+
*/
97+
public function setAccountHolderName($accountHolderName)
98+
{
99+
$this->accountHolderName = $accountHolderName;
100+
return $this;
101+
}
102+
103+
/**
104+
* @return DateTime
105+
*/
106+
public function getAccountHolderDob()
107+
{
108+
return $this->accountHolderDob;
109+
}
110+
111+
/**
112+
* @param DateTime $accountHolderDob
113+
* @return $this
114+
*/
115+
public function setAccountHolderDob(DateTime $accountHolderDob = null)
116+
{
117+
$this->accountHolderDob = $accountHolderDob;
118+
return $this;
119+
}
120+
121+
/**
122+
* @return string
123+
*/
124+
public function getRoutingCode()
125+
{
126+
return $this->routingCode;
127+
}
128+
129+
/**
130+
* @param string $routingCode
131+
* @return $this
132+
*/
133+
public function setRoutingCode($routingCode)
134+
{
135+
$this->routingCode = $routingCode;
136+
return $this;
137+
}
138+
139+
/**
140+
* @return string
141+
*/
142+
public function getAccountNumber()
143+
{
144+
return $this->accountNumber;
145+
}
146+
147+
/**
148+
* @param string $accountNumber
149+
* @return $this
150+
*/
151+
public function setAccountNumber($accountNumber)
152+
{
153+
$this->accountNumber = $accountNumber;
154+
return $this;
155+
}
156+
157+
/**
158+
* @return string
159+
*/
160+
public function getCurrency()
161+
{
162+
return $this->currency;
163+
}
164+
165+
/**
166+
* @param string $currency
167+
* @return $this
168+
*/
169+
public function setCurrency($currency)
170+
{
171+
$this->currency = $currency;
172+
return $this;
173+
}
174+
175+
}

0 commit comments

Comments
 (0)