|
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
|
|
|
use PartFire\MangoPayBundle\MangoPayConstants; |
|
23
|
|
|
|
|
24
|
|
|
class PayInTranslator |
|
25
|
|
|
{ |
|
26
|
|
|
public function translateDtoToMangoPayInForDirectPayIn(CardDirectPayIn $cardDirectPayIn) |
|
27
|
|
|
{ |
|
28
|
|
|
$payIn = new PayIn(); |
|
29
|
|
|
$payIn->CreditedWalletId = $cardDirectPayIn->getCreditedWalletId(); |
|
30
|
|
|
$payIn->AuthorId = $cardDirectPayIn->getAuthorId(); |
|
31
|
|
|
$payIn->DebitedFunds = new Money(); |
|
32
|
|
|
$payIn->DebitedFunds->Amount = $cardDirectPayIn->getAmount(); |
|
33
|
|
|
$payIn->DebitedFunds->Currency = $cardDirectPayIn->getCurrency(); |
|
34
|
|
|
$payIn->Fees = new Money(); |
|
35
|
|
|
$payIn->Fees->Amount = $cardDirectPayIn->getFees(); |
|
36
|
|
|
$payIn->Fees->Currency = $cardDirectPayIn->getFeesCurrency(); |
|
37
|
|
|
$payIn->Tag = $cardDirectPayIn->getTag(); |
|
38
|
|
|
|
|
39
|
|
|
// payment type as CARD |
|
40
|
|
|
$payIn->PaymentDetails = new PayInPaymentDetailsCard(); |
|
41
|
|
|
$payIn->PaymentDetails->CardType = $cardDirectPayIn->getCardType(); |
|
42
|
|
|
$payIn->PaymentDetails->CardId = $cardDirectPayIn->getCardId(); |
|
43
|
|
|
|
|
44
|
|
|
// execution type as DIRECT |
|
45
|
|
|
$payIn->ExecutionDetails = new PayInExecutionDetailsDirect(); |
|
46
|
|
|
$payIn->ExecutionDetails->SecureModeReturnURL = $cardDirectPayIn->getSecureModeReturnUrl(); |
|
47
|
|
|
return $payIn; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function translateMangoPayDirectPayInToDto(PayIn $payIn) |
|
51
|
|
|
{ |
|
52
|
|
|
$cardDirectPayIn = new CardDirectPayIn(); |
|
53
|
|
|
$cardDirectPayIn->setStatus($payIn->Status); |
|
54
|
|
|
$cardDirectPayIn->setCurrency($payIn->DebitedFunds->Currency); |
|
55
|
|
|
|
|
56
|
|
|
if (isset($payIn->CreditedFunds->Amount)) { |
|
57
|
|
|
$cardDirectPayIn->setAmount($payIn->CreditedFunds->Amount); |
|
58
|
|
|
} else { |
|
59
|
|
|
$cardDirectPayIn->setAmount($payIn->DebitedFunds->Amount); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$cardDirectPayIn->setAuthorId($payIn->AuthorId); |
|
63
|
|
|
$cardDirectPayIn->setFees($payIn->Fees->Amount); |
|
64
|
|
|
$cardDirectPayIn->setFeesCurrency($payIn->Fees->Currency); |
|
65
|
|
|
$cardDirectPayIn->setCardId($payIn->PaymentDetails->CardId); |
|
66
|
|
|
$cardDirectPayIn->setCardType($payIn->PaymentDetails->CardType); |
|
67
|
|
|
$cardDirectPayIn->setSecureModeReturnUrl($payIn->ExecutionDetails->SecureModeReturnURL); |
|
68
|
|
|
$cardDirectPayIn->setSecureMode($payIn->ExecutionDetails->SecureMode); |
|
69
|
|
|
$cardDirectPayIn->setSecureModeRedirectUrl($payIn->ExecutionDetails->SecureModeRedirectURL); |
|
70
|
|
|
$cardDirectPayIn->setSecureModeNeeded($payIn->ExecutionDetails->SecureModeNeeded); |
|
71
|
|
|
$cardDirectPayIn->setTag($payIn->Tag); |
|
72
|
|
|
$cardDirectPayIn->setResourceId($payIn->Id); |
|
73
|
|
|
$cardDirectPayIn->setResultCode($payIn->ResultCode); |
|
74
|
|
|
$cardDirectPayIn->setResultMessage($payIn->ResultMessage); |
|
75
|
|
|
return $cardDirectPayIn; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function translateDtoToMangoPayInForBankwireDirectPayIn(BankwireDirectPayIn $bankwireDirectPayIn) |
|
79
|
|
|
{ |
|
80
|
|
|
$payIn = new PayIn(); |
|
81
|
|
|
$payIn->CreditedWalletId = $bankwireDirectPayIn->getCreditedWalletId(); |
|
82
|
|
|
$payIn->AuthorId = $bankwireDirectPayIn->getAuthorId(); |
|
83
|
|
|
$payIn->Tag = $bankwireDirectPayIn->getTag(); |
|
84
|
|
|
$payIn->CreditedUserId = $bankwireDirectPayIn->getCreditedUserId(); |
|
85
|
|
|
|
|
86
|
|
|
$payIn->PaymentDetails = new PayInPaymentDetailsBankWire(); |
|
87
|
|
|
$payIn->PaymentDetails->DeclaredDebitedFunds = new Money(); |
|
88
|
|
|
$payIn->PaymentDetails->DeclaredDebitedFunds->Amount = $bankwireDirectPayIn->getDeclaredDebitedFundsAmount(); |
|
89
|
|
|
$payIn->PaymentDetails->DeclaredDebitedFunds->Currency = $bankwireDirectPayIn->getDeclaredDebitedFundsCurrency(); |
|
90
|
|
|
$payIn->PaymentDetails->DeclaredFees = new Money(); |
|
91
|
|
|
$payIn->PaymentDetails->DeclaredFees->Amount = $bankwireDirectPayIn->getDeclaredFeesAmount(); |
|
92
|
|
|
$payIn->PaymentDetails->DeclaredFees->Currency = $bankwireDirectPayIn->getDeclaredFeesCurrency(); |
|
93
|
|
|
$payIn->ExecutionDetails = new PayInExecutionDetailsDirect(); |
|
94
|
|
|
|
|
95
|
|
|
return $payIn; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function translateMangoPayBankwireDirectPayInToDto(PayIn $payIn) |
|
99
|
|
|
{ |
|
100
|
|
|
$cardDirectPayIn = new BankwireDirectPayIn(); |
|
101
|
|
|
$cardDirectPayIn->setStatus($payIn->Status); |
|
102
|
|
|
$cardDirectPayIn->setTag($payIn->Tag); |
|
103
|
|
|
$cardDirectPayIn->setAuthorId($payIn->AuthorId); |
|
104
|
|
|
$cardDirectPayIn->setCreditedWalletId($payIn->CreditedWalletId); |
|
105
|
|
|
$cardDirectPayIn->setCreditedUserId($payIn->CreditedUserId); |
|
106
|
|
|
if (MangoPayConstants::CREATED == $payIn->Status) { |
|
107
|
|
|
$cardDirectPayIn->setDeclaredDebitedFundsAmount($payIn->PaymentDetails->DeclaredDebitedFunds->Amount); |
|
108
|
|
|
} else { |
|
109
|
|
|
$cardDirectPayIn->setDeclaredDebitedFundsAmount($payIn->CreditedFunds->Amount); |
|
110
|
|
|
} |
|
111
|
|
|
$cardDirectPayIn->setDeclaredDebitedFundsCurrency($payIn->PaymentDetails->DeclaredDebitedFunds->Currency); |
|
112
|
|
|
$cardDirectPayIn->setDeclaredFeesAmount($payIn->PaymentDetails->DeclaredFees->Amount); |
|
113
|
|
|
$cardDirectPayIn->setDeclaredFeesCurrency($payIn->PaymentDetails->DeclaredFees->Currency); |
|
114
|
|
|
$cardDirectPayIn->setType($payIn->Type); |
|
115
|
|
|
$cardDirectPayIn->setNature($payIn->Nature); |
|
116
|
|
|
$cardDirectPayIn->setPaymentType($payIn->PaymentType); |
|
117
|
|
|
$cardDirectPayIn->setExecutionType($payIn->ExecutionType); |
|
118
|
|
|
$cardDirectPayIn->setWireReference($payIn->PaymentDetails->WireReference); |
|
119
|
|
|
$cardDirectPayIn->setBankAccountType($payIn->PaymentDetails->BankAccount->Type); |
|
120
|
|
|
$cardDirectPayIn->setBankAccountOwnerName($payIn->PaymentDetails->BankAccount->OwnerName); |
|
121
|
|
|
$cardDirectPayIn->setBankAccountIban($payIn->PaymentDetails->BankAccount->Details->IBAN); |
|
122
|
|
|
$cardDirectPayIn->setBankAccountBic($payIn->PaymentDetails->BankAccount->Details->BIC); |
|
123
|
|
|
$cardDirectPayIn->setResourceId($payIn->Id); |
|
124
|
|
|
|
|
125
|
|
|
return $cardDirectPayIn; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|