1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Carl Owens ([email protected]) |
4
|
|
|
* Company: PartFire Ltd (www.partfire.co.uk) |
5
|
|
|
* Copyright © 2017 PartFire Ltd. All rights reserved. |
6
|
|
|
* |
7
|
|
|
* User: Carl Owens |
8
|
|
|
* Date: 19/01/2017 |
9
|
|
|
* Time: 12:49 |
10
|
|
|
* File: PayInTranslator.php |
11
|
|
|
**/ |
12
|
|
|
|
13
|
|
|
namespace PartFire\MangoPayBundle\Models\DTOs\Translators; |
14
|
|
|
|
15
|
|
|
use MangoPay\Money; |
16
|
|
|
use MangoPay\PayIn; |
17
|
|
|
use MangoPay\PayInExecutionDetailsDirect; |
18
|
|
|
use MangoPay\PayInPaymentDetailsBankWire; |
19
|
|
|
use MangoPay\PayInPaymentDetailsCard; |
20
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\BankwireDirectPayIn; |
21
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\CardDirectPayIn; |
22
|
|
|
|
23
|
|
|
class PayInTranslator |
24
|
|
|
{ |
25
|
|
|
public function translateDtoToMangoPayInForDirectPayIn(CardDirectPayIn $cardDirectPayIn) |
26
|
|
|
{ |
27
|
|
|
$payIn = new PayIn(); |
28
|
|
|
$payIn->CreditedWalletId = $cardDirectPayIn->getCreditedWalletId(); |
29
|
|
|
$payIn->AuthorId = $cardDirectPayIn->getAuthorId(); |
30
|
|
|
$payIn->DebitedFunds = new Money(); |
31
|
|
|
$payIn->DebitedFunds->Amount = $cardDirectPayIn->getAmount(); |
32
|
|
|
$payIn->DebitedFunds->Currency = $cardDirectPayIn->getCurrency(); |
33
|
|
|
$payIn->Fees = new Money(); |
34
|
|
|
$payIn->Fees->Amount = $cardDirectPayIn->getFees(); |
35
|
|
|
$payIn->Fees->Currency = $cardDirectPayIn->getFeesCurrency(); |
36
|
|
|
$payIn->Tag = $cardDirectPayIn->getTag(); |
37
|
|
|
|
38
|
|
|
// payment type as CARD |
39
|
|
|
$payIn->PaymentDetails = new PayInPaymentDetailsCard(); |
40
|
|
|
$payIn->PaymentDetails->CardType = $cardDirectPayIn->getCardType(); |
41
|
|
|
$payIn->PaymentDetails->CardId = $cardDirectPayIn->getCardId(); |
42
|
|
|
|
43
|
|
|
// execution type as DIRECT |
44
|
|
|
$payIn->ExecutionDetails = new PayInExecutionDetailsDirect(); |
45
|
|
|
$payIn->ExecutionDetails->SecureModeReturnURL = $cardDirectPayIn->getSecureModeReturnUrl(); |
46
|
|
|
return $payIn; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function translateMangoPayDirectPayInToDto(PayIn $payIn) |
50
|
|
|
{ |
51
|
|
|
$cardDirectPayIn = new CardDirectPayIn(); |
52
|
|
|
$cardDirectPayIn->setStatus($payIn->Status); |
53
|
|
|
$cardDirectPayIn->setCurrency($payIn->DebitedFunds->Currency); |
54
|
|
|
|
55
|
|
View Code Duplication |
if (isset($payIn->CreditedFunds->Amount)) { |
|
|
|
|
56
|
|
|
$cardDirectPayIn->setAmount($payIn->CreditedFunds->Amount); |
57
|
|
|
} else { |
58
|
|
|
$cardDirectPayIn->setAmount($payIn->DebitedFunds->Amount); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$cardDirectPayIn->setAuthorId($payIn->AuthorId); |
62
|
|
|
$cardDirectPayIn->setFees($payIn->Fees->Amount); |
63
|
|
|
$cardDirectPayIn->setFeesCurrency($payIn->Fees->Currency); |
64
|
|
|
$cardDirectPayIn->setCardId($payIn->PaymentDetails->CardId); |
65
|
|
|
$cardDirectPayIn->setCardType($payIn->PaymentDetails->CardType); |
66
|
|
|
$cardDirectPayIn->setSecureModeReturnUrl($payIn->ExecutionDetails->SecureModeReturnURL); |
67
|
|
|
$cardDirectPayIn->setSecureMode($payIn->ExecutionDetails->SecureMode); |
68
|
|
|
$cardDirectPayIn->setSecureModeRedirectUrl($payIn->ExecutionDetails->SecureModeRedirectURL); |
69
|
|
|
$cardDirectPayIn->setSecureModeNeeded($payIn->ExecutionDetails->SecureModeNeeded); |
70
|
|
|
$cardDirectPayIn->setTag($payIn->Tag); |
71
|
|
|
$cardDirectPayIn->setResourceId($payIn->Id); |
72
|
|
|
$cardDirectPayIn->setResultCode($payIn->ResultCode); |
73
|
|
|
$cardDirectPayIn->setResultMessage($payIn->ResultMessage); |
74
|
|
|
return $cardDirectPayIn; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function translateDtoToMangoPayInForBankwireDirectPayIn(BankwireDirectPayIn $bankwireDirectPayIn) |
78
|
|
|
{ |
79
|
|
|
$payIn = new PayIn(); |
80
|
|
|
$payIn->CreditedWalletId = $bankwireDirectPayIn->getCreditedWalletId(); |
81
|
|
|
$payIn->AuthorId = $bankwireDirectPayIn->getAuthorId(); |
82
|
|
|
$payIn->Tag = $bankwireDirectPayIn->getTag(); |
83
|
|
|
$payIn->CreditedUserId = $bankwireDirectPayIn->getCreditedUserId(); |
84
|
|
|
|
85
|
|
|
$payIn->PaymentDetails = new PayInPaymentDetailsBankWire(); |
86
|
|
|
$payIn->PaymentDetails->DeclaredDebitedFunds = new Money(); |
87
|
|
|
$payIn->PaymentDetails->DeclaredDebitedFunds->Amount = $bankwireDirectPayIn->getDeclaredDebitedFundsAmount(); |
88
|
|
|
$payIn->PaymentDetails->DeclaredDebitedFunds->Currency = $bankwireDirectPayIn->getDeclaredDebitedFundsCurrency(); |
89
|
|
|
$payIn->PaymentDetails->DeclaredFees = new Money(); |
90
|
|
|
$payIn->PaymentDetails->DeclaredFees->Amount = $bankwireDirectPayIn->getDeclaredFeesAmount(); |
91
|
|
|
$payIn->PaymentDetails->DeclaredFees->Currency = $bankwireDirectPayIn->getDeclaredFeesCurrency(); |
92
|
|
|
$payIn->ExecutionDetails = new PayInExecutionDetailsDirect(); |
93
|
|
|
|
94
|
|
|
return $payIn; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function translateMangoPayBankwireDirectPayInToDto(PayIn $payIn) |
98
|
|
|
{ |
99
|
|
|
$cardDirectPayIn = new BankwireDirectPayIn(); |
100
|
|
|
$cardDirectPayIn->setStatus($payIn->Status); |
101
|
|
|
$cardDirectPayIn->setTag($payIn->Tag); |
102
|
|
|
$cardDirectPayIn->setAuthorId($payIn->AuthorId); |
103
|
|
|
$cardDirectPayIn->setCreditedWalletId($payIn->CreditedWalletId); |
104
|
|
|
$cardDirectPayIn->setCreditedUserId($payIn->CreditedUserId); |
105
|
|
View Code Duplication |
if (isset($payIn->CreditedFunds->Amount)) { |
|
|
|
|
106
|
|
|
$cardDirectPayIn->setDeclaredDebitedFundsAmount($payIn->CreditedFunds->Amount); |
107
|
|
|
} else { |
108
|
|
|
$cardDirectPayIn->setDeclaredDebitedFundsAmount($payIn->DebitedFunds->Amount); |
109
|
|
|
} |
110
|
|
|
$cardDirectPayIn->setDeclaredDebitedFundsCurrency($payIn->PaymentDetails->DeclaredDebitedFunds->Currency); |
111
|
|
|
$cardDirectPayIn->setDeclaredFeesAmount($payIn->PaymentDetails->DeclaredFees->Amount); |
112
|
|
|
$cardDirectPayIn->setDeclaredFeesCurrency($payIn->PaymentDetails->DeclaredFees->Currency); |
113
|
|
|
$cardDirectPayIn->setType($payIn->Type); |
114
|
|
|
$cardDirectPayIn->setNature($payIn->Nature); |
115
|
|
|
$cardDirectPayIn->setPaymentType($payIn->PaymentType); |
116
|
|
|
$cardDirectPayIn->setExecutionType($payIn->ExecutionType); |
117
|
|
|
$cardDirectPayIn->setWireReference($payIn->PaymentDetails->WireReference); |
118
|
|
|
$cardDirectPayIn->setBankAccountType($payIn->PaymentDetails->BankAccount->Type); |
119
|
|
|
$cardDirectPayIn->setBankAccountOwnerName($payIn->PaymentDetails->BankAccount->OwnerName); |
120
|
|
|
$cardDirectPayIn->setBankAccountIban($payIn->PaymentDetails->BankAccount->Details->IBAN); |
121
|
|
|
$cardDirectPayIn->setBankAccountBic($payIn->PaymentDetails->BankAccount->Details->BIC); |
122
|
|
|
$cardDirectPayIn->setResourceId($payIn->Id); |
123
|
|
|
|
124
|
|
|
return $cardDirectPayIn; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.