1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @jayS-de <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Payment; |
7
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Resource; |
9
|
|
|
use Commercetools\Core\Model\Common\DateTimeDecorator; |
10
|
|
|
use Commercetools\Core\Model\Customer\CustomerReference; |
11
|
|
|
use Commercetools\Core\Model\Common\Money; |
12
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObject; |
13
|
|
|
use Commercetools\Core\Model\CustomField\CustomFieldObjectCollection; |
14
|
|
|
use DateTime; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @package Commercetools\Core\Model\Payment |
18
|
|
|
* @link https://dev.commercetools.com/http-api-projects-payments.html#payment |
19
|
|
|
* @method string getId() |
20
|
|
|
* @method Payment setId(string $id = null) |
21
|
|
|
* @method int getVersion() |
22
|
|
|
* @method Payment setVersion(int $version = null) |
23
|
|
|
* @method DateTimeDecorator getCreatedAt() |
24
|
|
|
* @method Payment setCreatedAt(DateTime $createdAt = null) |
25
|
|
|
* @method DateTimeDecorator getLastModifiedAt() |
26
|
|
|
* @method Payment setLastModifiedAt(DateTime $lastModifiedAt = null) |
27
|
|
|
* @method CustomerReference getCustomer() |
28
|
|
|
* @method Payment setCustomer(CustomerReference $customer = null) |
29
|
|
|
* @method string getInterfaceId() |
30
|
|
|
* @method Payment setInterfaceId(string $interfaceId = null) |
31
|
|
|
* @method Money getAmountPlanned() |
32
|
|
|
* @method Payment setAmountPlanned(Money $amountPlanned = null) |
33
|
|
|
* @method PaymentMethodInfo getPaymentMethodInfo() |
34
|
|
|
* @method Payment setPaymentMethodInfo(PaymentMethodInfo $paymentMethodInfo = null) |
35
|
|
|
* @method CustomFieldObject getCustom() |
36
|
|
|
* @method Payment setCustom(CustomFieldObject $custom = null) |
37
|
|
|
* @method PaymentStatus getPaymentStatus() |
38
|
|
|
* @method Payment setPaymentStatus(PaymentStatus $paymentStatus = null) |
39
|
|
|
* @method TransactionCollection getTransactions() |
40
|
|
|
* @method Payment setTransactions(TransactionCollection $transactions = null) |
41
|
|
|
* @method CustomFieldObjectCollection getInterfaceInteractions() |
42
|
|
|
* @method Payment setInterfaceInteractions(CustomFieldObjectCollection $interfaceInteractions = null) |
43
|
|
|
* @method string getKey() |
44
|
|
|
* @method Payment setKey(string $key = null) |
45
|
|
|
* @method PaymentReference getReference() |
46
|
|
|
*/ |
47
|
|
|
class Payment extends Resource |
48
|
|
|
{ |
49
|
24 |
|
public function fieldDefinitions() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
24 |
|
'id' => [static::TYPE => 'string'], |
53
|
24 |
|
'version' => [static::TYPE => 'int'], |
54
|
24 |
|
'key' => [static::TYPE => 'string'], |
55
|
|
|
'createdAt' => [ |
56
|
24 |
|
static::TYPE => DateTime::class, |
57
|
24 |
|
static::DECORATOR => DateTimeDecorator::class |
58
|
|
|
], |
59
|
|
|
'lastModifiedAt' => [ |
60
|
24 |
|
static::TYPE => DateTime::class, |
61
|
24 |
|
static::DECORATOR => DateTimeDecorator::class |
62
|
|
|
], |
63
|
24 |
|
'customer' => [static::TYPE => CustomerReference::class], |
64
|
24 |
|
'externalId' => [static::TYPE => 'string'], |
65
|
24 |
|
'interfaceId' => [static::TYPE => 'string'], |
66
|
24 |
|
'amountPlanned' => [static::TYPE => Money::class], |
67
|
24 |
|
'amountAuthorized' => [static::TYPE => Money::class], |
68
|
|
|
'authorizedUntil' => [ |
69
|
24 |
|
static::TYPE => DateTime::class, |
70
|
24 |
|
static::DECORATOR => DateTimeDecorator::class |
71
|
|
|
], |
72
|
24 |
|
'amountPaid' => [static::TYPE => Money::class], |
73
|
24 |
|
'amountRefunded' => [static::TYPE => Money::class], |
74
|
24 |
|
'paymentMethodInfo' => [static::TYPE => PaymentMethodInfo::class], |
75
|
24 |
|
'custom' => [static::TYPE => CustomFieldObject::class], |
76
|
24 |
|
'paymentStatus' => [static::TYPE => PaymentStatus::class], |
77
|
24 |
|
'transactions' => [static::TYPE => TransactionCollection::class], |
78
|
|
|
'interfaceInteractions' => [ |
79
|
24 |
|
static::TYPE => CustomFieldObjectCollection::class |
80
|
|
|
], |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @deprecated |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
1 |
|
public function getExternalId() |
89
|
|
|
{ |
90
|
1 |
|
return parent::getExternalId(); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @deprecated |
95
|
|
|
* @param string $externalId |
96
|
|
|
* @return static |
97
|
|
|
*/ |
98
|
|
|
public function setExternalId($externalId = null) |
99
|
|
|
{ |
100
|
|
|
return parent::setExternalId($externalId); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @deprecated |
105
|
|
|
* @return Money |
106
|
|
|
*/ |
107
|
1 |
|
public function getAmountAuthorized() |
108
|
|
|
{ |
109
|
1 |
|
return parent::getAmountAuthorized(); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @deprecated |
114
|
|
|
* @param Money $amountAuthorized |
115
|
|
|
* @return static |
116
|
|
|
*/ |
117
|
|
|
public function setAmountAuthorized(Money $amountAuthorized = null) |
118
|
|
|
{ |
119
|
|
|
return parent::setAmountAuthorized($amountAuthorized); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @deprecated |
124
|
|
|
* @return Money |
125
|
|
|
*/ |
126
|
1 |
|
public function getAmountPaid() |
127
|
|
|
{ |
128
|
1 |
|
return parent::getAmountPaid(); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @deprecated |
133
|
|
|
* @param Money $amountPaid |
134
|
|
|
* @return static |
135
|
|
|
*/ |
136
|
|
|
public function setAmountPaid(Money $amountPaid = null) |
137
|
|
|
{ |
138
|
|
|
return parent::setAmountPaid($amountPaid); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @deprecated |
143
|
|
|
* @return Money |
144
|
|
|
*/ |
145
|
1 |
|
public function getAmountRefunded() |
146
|
|
|
{ |
147
|
1 |
|
return parent::getAmountRefunded(); |
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @deprecated |
152
|
|
|
* @param Money $amountRefunded |
153
|
|
|
* @return static |
154
|
|
|
*/ |
155
|
|
|
public function setAmountRefunded(Money $amountRefunded = null) |
156
|
|
|
{ |
157
|
|
|
return parent::setAmountRefunded($amountRefunded); |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @deprecated |
162
|
|
|
* @return Money |
163
|
|
|
*/ |
164
|
1 |
|
public function getAuthorizedUntil() |
165
|
|
|
{ |
166
|
1 |
|
return parent::getAuthorizedUntil(); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @deprecated |
171
|
|
|
* @param Money $amountUntil |
172
|
|
|
* @return static |
173
|
|
|
*/ |
174
|
|
|
public function setAuthorizedUntil(Money $amountUntil = null) |
175
|
|
|
{ |
176
|
|
|
return parent::setAuthorizedUntil($amountUntil); |
|
|
|
|
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: