1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Carl Owens ([email protected]) |
4
|
|
|
* Company: PartFire Ltd (www.partfire.co.uk) |
5
|
|
|
* Copyright © 2016 PartFire Ltd. All rights reserved. |
6
|
|
|
* |
7
|
|
|
* User: Carl Owens |
8
|
|
|
* Date: 28/11/2016 |
9
|
|
|
* Time: 11:14 |
10
|
|
|
* File: UserTranslator.php |
11
|
|
|
**/ |
12
|
|
|
|
13
|
|
|
namespace PartFire\MangoPayBundle\Models\DTOs\Translators; |
14
|
|
|
|
15
|
|
|
use MangoPay\UserLegal; |
16
|
|
|
use MangoPay\UserNatural; |
17
|
|
|
use MangoPay\Address; |
18
|
|
|
|
19
|
|
|
use PartFire\MangoPayBundle\MangoPayConstants; |
20
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\UserBase; |
21
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\Address as PFAddress; |
22
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\UserNatural as PFUserNatural; |
23
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\UserLegal as PFUserLegal; |
24
|
|
|
|
25
|
|
|
class UserTranslator |
26
|
|
|
{ |
27
|
|
|
public function convertDTOToMangoPayNaturalUser(PFUserNatural $userDto) |
28
|
|
|
{ |
29
|
|
|
$mangoUser = new UserNatural(); |
30
|
|
|
$mangoUser->PersonType = MangoPayConstants::NATURAL_PERSON_TYPE; |
31
|
|
|
$mangoUser->FirstName = $userDto->getFirstName(); |
32
|
|
|
$mangoUser->LastName = $userDto->getLastName(); |
33
|
|
|
$mangoUser->Birthday = (int) $userDto->getBirthday(); |
34
|
|
|
$mangoUser->Nationality = $userDto->getNationality(); |
35
|
|
|
$mangoUser->CountryOfResidence = $userDto->getCountryOfResidence(); |
36
|
|
|
$mangoUser->Email = $userDto->getEmail(); |
37
|
|
|
$mangoUser->Tag = $userDto->getTag(); |
38
|
|
|
$mangoUser->Address = $this->getConvertDTOToMangoPayAddress($userDto->getAddress()); |
|
|
|
|
39
|
|
|
if ($userDto->getId()) { |
40
|
|
|
$mangoUser->Id = $userDto->getId(); |
41
|
|
|
} |
42
|
|
|
return $mangoUser; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function convertMangoPayNaturalUserToDTO(UserNatural $mangoUser) |
46
|
|
|
{ |
47
|
|
|
$userDto = new PFUserNatural(); |
48
|
|
|
$userDto->setPersonType($mangoUser->PersonType); |
49
|
|
|
$userDto->setFirstName($mangoUser->FirstName); |
50
|
|
|
$userDto->setLastName($mangoUser->LastName); |
51
|
|
|
$userDto->setBirthday($mangoUser->Birthday); |
52
|
|
|
$userDto->setNationality($mangoUser->Nationality); |
53
|
|
|
$userDto->setCountryOfResidence($mangoUser->CountryOfResidence); |
54
|
|
|
$userDto->setEmail($mangoUser->Email); |
55
|
|
|
$userDto->setId($mangoUser->Id); |
56
|
|
|
$userDto->setKYCLevel($mangoUser->KYCLevel); |
57
|
|
|
$userDto->setAddress($this->getConvertMangoAddressToDTO($mangoUser->Address)); |
58
|
|
|
return $userDto; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function convertDTOToMangoPayLegalUser(PFUserLegal $userDto) |
62
|
|
|
{ |
63
|
|
|
$mangoUser = new UserLegal(); |
64
|
|
|
$mangoUser->PersonType = MangoPayConstants::LEAGAL_PERSON_TYPE; |
65
|
|
|
$mangoUser->Name = $userDto->getFirstName() . " " . $userDto->getLastName(); |
66
|
|
|
$mangoUser->LastName = $userDto->getLastName(); |
|
|
|
|
67
|
|
|
$mangoUser->Birthday = (int) $userDto->getLegalRepresentativeBirthday(); |
|
|
|
|
68
|
|
|
$mangoUser->Nationality = $userDto->getNationality(); |
|
|
|
|
69
|
|
|
$mangoUser->CountryOfResidence = $userDto->getCountryOfResidence(); |
|
|
|
|
70
|
|
|
$mangoUser->Email = $userDto->getEmail(); |
71
|
|
|
$mangoUser->Tag = $userDto->getTag(); |
72
|
|
|
if ($userDto->getId()) { |
73
|
|
|
$mangoUser->Id = $userDto->getId(); |
74
|
|
|
} |
75
|
|
|
return $mangoUser; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function convertMangoPayLegalUserToDTO(UserNatural $mangoUser) |
79
|
|
|
{ |
80
|
|
|
$userDto = new PFUserLegal(); |
81
|
|
|
$userDto->setPersonType($mangoUser->PersonType); |
82
|
|
|
$userDto->setFirstName($mangoUser->FirstName); |
83
|
|
|
$userDto->setLastName($mangoUser->LastName); |
84
|
|
|
$userDto->setLegalRepresentativeBirthday($mangoUser->Birthday); |
85
|
|
|
$userDto->setNationality($mangoUser->Nationality); |
86
|
|
|
$userDto->setCountryOfResidence($mangoUser->CountryOfResidence); |
87
|
|
|
$userDto->setEmail($mangoUser->Email); |
88
|
|
|
$userDto->setId($mangoUser->Id); |
89
|
|
|
$userDto->setKYCLevel($mangoUser->KYCLevel); |
90
|
|
|
return $userDto; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function getConvertDTOToMangoPayAddress(PFAddress $pfAddress) |
94
|
|
|
{ |
95
|
|
|
$address = new Address(); |
96
|
|
|
$address->AddressLine1 = $pfAddress->getAddressLine1(); |
97
|
|
|
$address->AddressLine2 = $pfAddress->getAddressLine2(); |
98
|
|
|
$address->City = $pfAddress->getCity(); |
99
|
|
|
$address->Region = $pfAddress->getRegion(); |
100
|
|
|
$address->PostalCode = $pfAddress->getPostalCode(); |
101
|
|
|
$address->Country = $pfAddress->getCountry(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
private function getConvertMangoAddressToDTO(Address $address) |
105
|
|
|
{ |
106
|
|
|
$pfAddress = new PFAddress(); |
107
|
|
|
$pfAddress->setAddressLine1($address->AddressLine1); |
108
|
|
|
$pfAddress->setAddressLine2($address->AddressLine2); |
109
|
|
|
$pfAddress->setCity($address->City); |
110
|
|
|
$pfAddress->setRegion($address->Region); |
111
|
|
|
$pfAddress->setPostalCode($address->PostalCode); |
112
|
|
|
$pfAddress->setCountry($address->Country); |
113
|
|
|
|
114
|
|
|
return $pfAddress; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.