Skip to content

Commit 3c14909

Browse files
Merge pull request #131 from NottingHack/accounts-paymentref
Accounts paymentref
2 parents 0cb24d5 + 029d9c7 commit 3c14909

File tree

15 files changed

+1059
-530
lines changed

15 files changed

+1059
-530
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace HMS\Entities\Banking;
4+
5+
class Account
6+
{
7+
/**
8+
* @var int
9+
*/
10+
protected $id;
11+
12+
/**
13+
* @var string
14+
*/
15+
protected $paymentRef;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $natwestRef;
21+
22+
/**
23+
* @var \HMS\Entities\User
24+
*/
25+
protected $users;
26+
27+
/**
28+
* @param string $paymentRef
29+
*/
30+
public function __construct($paymentRef)
31+
{
32+
$this->paymentRef = $paymentRef;
33+
$this->users = new ArrayCollection();
34+
}
35+
36+
/**
37+
* Gets the value of id.
38+
*
39+
* @return mixed
40+
*/
41+
public function getId()
42+
{
43+
return $this->id;
44+
}
45+
46+
/**
47+
* Gets the value of paymentRef.
48+
*
49+
* @return mixed
50+
*/
51+
public function getPaymentRef()
52+
{
53+
return $this->paymentRef;
54+
}
55+
56+
/**
57+
* Sets the value of paymentRef.
58+
*
59+
* @param mixed $paymentRef the payment ref
60+
*
61+
* @return self
62+
*/
63+
protected function setPaymentRef($paymentRef)
64+
{
65+
$this->paymentRef = $paymentRef;
66+
67+
return $this;
68+
}
69+
70+
/**
71+
* Gets the value of natwestRef.
72+
*
73+
* @return mixed
74+
*/
75+
public function getNatwestRef()
76+
{
77+
return $this->natwestRef;
78+
}
79+
80+
/**
81+
* Gets the value of users.
82+
*
83+
* @return \HMS\Entities\User
84+
*/
85+
public function getUsers()
86+
{
87+
return $this->users;
88+
}
89+
90+
/**
91+
* Sets the value of users.
92+
*
93+
* @param \HMS\Entities\User $users the users
94+
*
95+
* @return self
96+
*/
97+
public function setUsers(\HMS\Entities\User $users)
98+
{
99+
$this->users = $users;
100+
101+
return $this;
102+
}
103+
}

app/HMS/Entities/Profile.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function setJoinDate(Carbon $joinDate)
9898
/**
9999
* @return string
100100
*/
101-
public function getUnlockText(): string
101+
public function getUnlockText()
102102
{
103103
return $this->unlockText;
104104
}
@@ -136,7 +136,7 @@ public function setCreditLimit(int $creditLimit)
136136
/**
137137
* @return string
138138
*/
139-
public function getAddress1(): string
139+
public function getAddress1()
140140
{
141141
return $this->address1;
142142
}
@@ -155,7 +155,7 @@ public function setAddress1(string $address1)
155155
/**
156156
* @return string
157157
*/
158-
public function getAddress2(): string
158+
public function getAddress2()
159159
{
160160
return $this->address2;
161161
}
@@ -174,7 +174,7 @@ public function setAddress2(string $address2)
174174
/**
175175
* @return string
176176
*/
177-
public function getAddress3(): string
177+
public function getAddress3()
178178
{
179179
return $this->address3;
180180
}
@@ -193,7 +193,7 @@ public function setAddress3(string $address3)
193193
/**
194194
* @return string
195195
*/
196-
public function getAddressCity(): string
196+
public function getAddressCity()
197197
{
198198
return $this->addressCity;
199199
}
@@ -212,7 +212,7 @@ public function setAddressCity(string $addressCity)
212212
/**
213213
* @return string
214214
*/
215-
public function getAddressCounty(): string
215+
public function getAddressCounty()
216216
{
217217
return $this->addressCounty;
218218
}
@@ -231,7 +231,7 @@ public function setAddressCounty(string $addressCounty)
231231
/**
232232
* @return string
233233
*/
234-
public function getAddressPostcode(): string
234+
public function getAddressPostcode()
235235
{
236236
return $this->addressPostcode;
237237
}
@@ -250,7 +250,7 @@ public function setAddressPostcode(string $addressPostcode)
250250
/**
251251
* @return string
252252
*/
253-
public function getContactNumber(): string
253+
public function getContactNumber()
254254
{
255255
return $this->contactNumber;
256256
}
@@ -271,7 +271,7 @@ public function setContactNumber(string $contactNumber)
271271
*/
272272
public function getDateOfBirth()
273273
{
274-
return $this->dateOfBirth;
274+
return Carbon::instance($this->dateOfBirth);
275275
}
276276

277277
/**

app/HMS/Entities/User.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace HMS\Entities;
44

5+
use HMS\Entities\Banking\Account;
56
use HMS\Traits\Entities\SoftDeletable;
67
use HMS\Traits\Entities\Timestampable;
78
use LaravelDoctrine\ACL\Roles\HasRoles;
@@ -62,6 +63,11 @@ class User implements AuthenticatableContract, CanResetPasswordContract, HasRole
6263
*/
6364
protected $profile;
6465

66+
/**
67+
* @var Account|null
68+
*/
69+
protected $account;
70+
6571
/**
6672
* User constructor.
6773
* @param string $firstname
@@ -205,7 +211,7 @@ public function getPermissions()
205211
}
206212

207213
/**
208-
* @return Profile The users profile
214+
* @return Profile|null The users profile
209215
*/
210216
public function getProfile() : Profile
211217
{
@@ -222,4 +228,23 @@ public function setProfile(Profile $profile)
222228

223229
return $this;
224230
}
231+
232+
/**
233+
* @return Account The users account
234+
*/
235+
public function getAccount() : Account
236+
{
237+
return $this->account;
238+
}
239+
240+
/**
241+
* @param Account $account
242+
* @return self
243+
*/
244+
public function setAccount(Account $account)
245+
{
246+
$this->account = $account;
247+
248+
return $this;
249+
}
225250
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace HMS\Factories\Banking;
4+
5+
use HMS\Entities\Banking\Account;
6+
use HMS\Repositories\Banking\AccountRepository;
7+
8+
class AccountFactory
9+
{
10+
/**
11+
* @var AccountRepository
12+
*/
13+
protected $accountRepository;
14+
15+
/**
16+
* @param AccountRepository $accountRepository
17+
*/
18+
public function __construct(AccountRepository $accountRepository)
19+
{
20+
$this->accountRepository = $accountRepository;
21+
}
22+
23+
/**
24+
* Create a new Account with a unique payment refrence.
25+
* @return Account
26+
*/
27+
public function createNewAccount()
28+
{
29+
// TODOL: generate new
30+
return new Account($this->generateUniquePaymentRef());
31+
}
32+
33+
/**
34+
* Generate a payment reference.
35+
*
36+
* @return string A unique (at the time of function-call) payment reference.
37+
*/
38+
protected static function generatePaymentRef()
39+
{
40+
// Payment ref is a randomly generates string of 'safechars'
41+
// Stolen from London Hackspace code
42+
$safeChars = '2346789BCDFGHJKMPQRTVWXY';
43+
// We prefix the ref with a string that lets people know it's us
44+
$prefix = 'HSNTSB';
45+
// Payment references can be up to 18 chars according to: http://www.bacs.co.uk/Bacs/Businesses/BacsDirectCredit/Receiving/Pages/PaymentReferenceInformation.aspx
46+
$maxRefLength = 16;
47+
$paymentRef = $prefix;
48+
for ($i = strlen($prefix); $i < $maxRefLength; $i++) {
49+
$paymentRef .= $safeChars[rand(0, strlen($safeChars) - 1)];
50+
}
51+
52+
return $paymentRef;
53+
}
54+
55+
/**
56+
* Generate a unique payment reference.
57+
*
58+
* @return string A unique (at the time of function-call) payment reference.
59+
* @link http://www.bacs.co.uk/Bacs/Businesses/BacsDirectCredit/Receiving/Pages/PaymentReferenceInformation.aspx
60+
*/
61+
protected function generateUniquePaymentRef()
62+
{
63+
$paymentRef = '';
64+
do {
65+
$paymentRef = $this->generatePaymentRef();
66+
} while ($this->accountRepository->findOneByPaymentRef($paymentRef) !== null);
67+
68+
return $paymentRef;
69+
}
70+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# HMS.Entities.Banking.Account.dcm.yml
2+
HMS\Entities\Banking\Account:
3+
type: entity
4+
repositoryClass: HMS\Repositories\Banking\AccountRepository
5+
table: accounts
6+
indexes:
7+
payment_ref_index:
8+
columns: [ payment_ref ]
9+
id:
10+
id:
11+
type: integer
12+
options:
13+
unsigned: true
14+
generator:
15+
strategy: AUTO
16+
fields:
17+
paymentRef:
18+
type: string
19+
length: 18
20+
unique: true
21+
natwestRef:
22+
type: string
23+
length: 18
24+
nullable: true
25+
oneToMany:
26+
users:
27+
targetEntity: \HMS\Entities\User
28+
mappedBy: account

app/HMS/Mappings/HMS.Entities.User.dcm.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ HMS\Entities\User:
5050
targetEntity: Profile
5151
mappedBy: user
5252
cascade: ["all"]
53+
manyToOne:
54+
account:
55+
targetEntity: \HMS\Entities\Banking\Account
56+
inversedBy: users
57+
joinColumns:
58+
acccount_id:
59+
referencedColumnName: id
5360
manyToMany:
5461
roles:
5562
targetEntity: Role
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace HMS\Repositories\Banking;
4+
5+
use HMS\Entities\Banking\Account;
6+
7+
interface AccountRepository
8+
{
9+
/**
10+
* @param $id
11+
* @return array
12+
*/
13+
public function find($id);
14+
15+
/**
16+
* @param string $paymentRef
17+
* @return array
18+
*/
19+
public function findOneByPaymentRef(string $paymentRef);
20+
21+
/**
22+
* @param string $paymentRef
23+
* @return array
24+
*/
25+
public function findLikeByPaymentRef(string $paymentRef);
26+
27+
/**
28+
* save Account to the DB.
29+
* @param Account $account
30+
*/
31+
public function save(Account $account);
32+
}

0 commit comments

Comments
 (0)