1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace eBayEnterprise\RetailOrderManagement\Payload\Payment; |
17
|
|
|
|
18
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayload; |
19
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap; |
20
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator; |
21
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator; |
22
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
23
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\TTopLevelPayload; |
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
use Psr\Log\NullLogger; |
26
|
|
|
|
27
|
|
|
class PayPalGetExpressCheckoutReply implements IPayPalGetExpressCheckoutReply |
28
|
|
|
{ |
29
|
|
|
use TTopLevelPayload, TOrderId, TBillingAddress, TShippingAddress; |
30
|
|
|
|
31
|
|
|
const ADDRESS_INTERFACE = '\eBayEnterprise\RetailOrderManagement\Payload\Payment\IPayPalAddress'; |
32
|
|
|
const SUCCESS = 'Success'; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
protected $responseCode; |
36
|
|
|
/** @var string */ |
37
|
|
|
protected $payerEmail; |
38
|
|
|
/** @var string */ |
39
|
|
|
protected $payerId; |
40
|
|
|
/** @var string */ |
41
|
|
|
protected $payerStatus; |
42
|
|
|
/** @var string */ |
43
|
|
|
protected $payerNameHonorific; |
44
|
|
|
/** @var string */ |
45
|
|
|
protected $payerLastName; |
46
|
|
|
/** @var string */ |
47
|
|
|
protected $payerMiddleName; |
48
|
|
|
/** @var string */ |
49
|
|
|
protected $payerFirstName; |
50
|
|
|
/** @var string */ |
51
|
|
|
protected $payerCountry; |
52
|
|
|
/** @var string */ |
53
|
|
|
protected $payerPhone; |
54
|
|
|
/** @var string */ |
55
|
|
|
protected $billingAddressStatus; |
56
|
|
|
/** @var string */ |
57
|
|
|
protected $shippingAddressStatus; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param IValidatorIterator |
61
|
|
|
* @param ISchemaValidator |
62
|
|
|
* @param IPayloadMap |
63
|
|
|
* @param LoggerInterface |
64
|
|
|
* @param IPayload |
65
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
66
|
|
|
*/ |
67
|
|
|
public function __construct( |
68
|
|
|
IValidatorIterator $validators, |
69
|
|
|
ISchemaValidator $schemaValidator, |
70
|
|
|
IPayloadMap $payloadMap, |
71
|
|
|
LoggerInterface $logger, |
72
|
|
|
IPayload $parentPayload = null |
73
|
|
|
) { |
74
|
|
|
$this->logger = $logger; |
|
|
|
|
75
|
|
|
$this->validators = $validators; |
76
|
|
|
$this->schemaValidator = $schemaValidator; |
77
|
|
|
$this->payloadMap = $payloadMap; |
78
|
|
|
$this->parentPayload = $parentPayload; |
79
|
|
|
$this->payloadFactory = new PayloadFactory(); |
80
|
|
|
|
81
|
|
|
$this->extractionPaths = [ |
82
|
|
|
'orderId' => 'string(x:OrderId)', |
83
|
|
|
'responseCode' => 'string(x:ResponseCode)', |
84
|
|
|
'payerEmail' => 'string(x:PayerEmail)', |
85
|
|
|
'payerId' => 'string(x:PayerId)', |
86
|
|
|
'payerStatus' => 'string(x:PayerStatus)', |
87
|
|
|
'payerNameHonorific' => 'string(x:PayerName/x:Honorific)', |
88
|
|
|
'payerLastName' => 'string(x:PayerName/x:LastName)', |
89
|
|
|
'payerMiddleName' => 'string(x:PayerName/x:MiddleName)', |
90
|
|
|
'payerFirstName' => 'string(x:PayerName/x:FirstName)', |
91
|
|
|
'payerCountry' => 'string(x:PayerCountry)', |
92
|
|
|
'payerPhone' => 'string(x:PayerPhone)', |
93
|
|
|
'billingCity' => 'string(x:BillingAddress/x:City)', |
94
|
|
|
'billingCountryCode' => 'string(x:BillingAddress/x:CountryCode)', |
95
|
|
|
'shipToCity' => 'string(x:ShippingAddress/x:City)', |
96
|
|
|
'shipToCountryCode' => 'string(x:ShippingAddress/x:CountryCode)', |
97
|
|
|
]; |
98
|
|
|
$this->optionalExtractionPaths = [ |
99
|
|
|
'billingMainDivision' => 'x:BillingAddress/x:MainDivision', |
100
|
|
|
'billingPostalCode' => 'x:BillingAddress/x:PostalCode', |
101
|
|
|
'shipToMainDivision' => 'x:ShippingAddress/x:MainDivision', |
102
|
|
|
'shipToPostalCode' => 'x:ShippingAddress/x:PostalCode', |
103
|
|
|
'billingAddressStatus' => 'x:BillingAddress/x:AddressStatus', |
104
|
|
|
'shippingAddressStatus' => 'x:ShippingAddress/x:AddressStatus', |
105
|
|
|
]; |
106
|
|
|
$this->addressLinesExtractionMap = [ |
107
|
|
|
[ |
108
|
|
|
'property' => 'billingLines', |
109
|
|
|
'xPath' => "x:BillingAddress/*[starts-with(name(), 'Line')]" |
110
|
|
|
], |
111
|
|
|
[ |
112
|
|
|
'property' => 'shipToLines', |
113
|
|
|
'xPath' => "x:ShippingAddress/*[starts-with(name(), 'Line')]" |
114
|
|
|
] |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Should downstream systems consider this reply a success? |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
|
|
public function isSuccess() |
124
|
|
|
{ |
125
|
|
|
return $this->getResponseCode() === static::SUCCESS; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Response code like Success, Failure etc |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getResponseCode() |
134
|
|
|
{ |
135
|
|
|
return $this->responseCode; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string |
140
|
|
|
* @return self |
141
|
|
|
*/ |
142
|
|
|
public function setResponseCode($code) |
143
|
|
|
{ |
144
|
|
|
$this->responseCode = $code; |
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Serialize a complete reply |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function serializeContents() |
153
|
|
|
{ |
154
|
|
|
return $this->serializeOrderId() |
155
|
|
|
. $this->serializeResponseCode() |
156
|
|
|
. $this->serializePayerEmail() |
157
|
|
|
. $this->serializePayerId() |
158
|
|
|
. $this->serializePayerStatus() |
159
|
|
|
. $this->serializePayerName() |
160
|
|
|
. $this->serializePayerCountry() |
161
|
|
|
. $this->serializeBillingAddressWithStatus() |
162
|
|
|
. $this->serializePayerPhone() |
163
|
|
|
. $this->serializeShippingAddressWithStatus(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Serialize a ResponseCode |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
protected function serializeResponseCode() |
171
|
|
|
{ |
172
|
|
|
return "<ResponseCode>{$this->xmlEncode($this->getResponseCode())}</ResponseCode>"; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Serialize a PayerEmail |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
protected function serializePayerEmail() |
180
|
|
|
{ |
181
|
|
|
return "<PayerEmail>{$this->xmlEncode($this->getPayerEmail())}</PayerEmail>"; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Email address of the payer. Character length and limitations: 127 single-byte characters |
186
|
|
|
* |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
public function getPayerEmail() |
190
|
|
|
{ |
191
|
|
|
return $this->payerEmail; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param string |
196
|
|
|
* @return self |
197
|
|
|
*/ |
198
|
|
|
public function setPayerEmail($email) |
199
|
|
|
{ |
200
|
|
|
$this->payerEmail = $email; |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Serialize a PayerId |
206
|
|
|
* @return string |
207
|
|
|
*/ |
208
|
|
|
protected function serializePayerId() |
209
|
|
|
{ |
210
|
|
|
return "<PayerId>{$this->xmlEncode($this->getPayerId())}</PayerId>"; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Unique identifier of the customer's PayPal account. Character length and limitations: 17 single-byte characters |
215
|
|
|
* |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
public function getPayerId() |
219
|
|
|
{ |
220
|
|
|
return $this->payerId; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param string |
225
|
|
|
* @return self |
226
|
|
|
*/ |
227
|
|
|
public function setPayerId($id) |
228
|
|
|
{ |
229
|
|
|
$this->payerId = $id; |
230
|
|
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Serialize a PayerStatus |
235
|
|
|
* @return string |
236
|
|
|
*/ |
237
|
|
|
protected function serializePayerStatus() |
238
|
|
|
{ |
239
|
|
|
return "<PayerStatus>{$this->xmlEncode($this->getPayerStatus())}</PayerStatus>"; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Status of payer's email address. |
244
|
|
|
* "verified" or "unverified" |
245
|
|
|
* |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
public function getPayerStatus() |
249
|
|
|
{ |
250
|
|
|
return $this->payerStatus; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param string |
255
|
|
|
* @return self |
256
|
|
|
*/ |
257
|
|
|
public function setPayerStatus($payerStatus) |
258
|
|
|
{ |
259
|
|
|
$this->payerStatus = $payerStatus; |
260
|
|
|
return $this; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Billing address status to be sent to the Order Management System |
265
|
|
|
* |
266
|
|
|
* @return string |
267
|
|
|
*/ |
268
|
|
|
public function getBillingAddressStatus() |
269
|
|
|
{ |
270
|
|
|
return $this->billingAddressStatus; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @param string |
275
|
|
|
* @return self |
276
|
|
|
*/ |
277
|
|
|
public function setBillingAddressStatus($status) |
278
|
|
|
{ |
279
|
|
|
$this->billingAddressStatus = $status; |
280
|
|
|
return $this; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Shipping address status to be sent to the Order Management System |
285
|
|
|
* |
286
|
|
|
* @return string |
287
|
|
|
*/ |
288
|
|
|
public function getShippingAddressStatus() |
289
|
|
|
{ |
290
|
|
|
return $this->shippingAddressStatus; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param string |
295
|
|
|
* @return self |
296
|
|
|
*/ |
297
|
|
|
public function setShippingAddressStatus($status) |
298
|
|
|
{ |
299
|
|
|
$this->shippingAddressStatus = $status; |
300
|
|
|
return $this; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Serialize Payer Name Details |
305
|
|
|
* @return string |
306
|
|
|
*/ |
307
|
|
|
protected function serializePayerName() |
308
|
|
|
{ |
309
|
|
|
return "<PayerName>" |
310
|
|
|
. "<Honorific>{$this->xmlEncode($this->getPayerNameHonorific())}</Honorific>" |
311
|
|
|
. "<LastName>{$this->xmlEncode($this->getPayerLastName())}</LastName>" |
312
|
|
|
. "<MiddleName>{$this->xmlEncode($this->getPayerMiddleName())}</MiddleName>" |
313
|
|
|
. "<FirstName>{$this->xmlEncode($this->getPayerFirstName())}</FirstName>" |
314
|
|
|
. "</PayerName>"; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* A title you can assign to the payer. Typically "Dr.", "Mr.", "Ms." etc. |
319
|
|
|
* |
320
|
|
|
* @return string |
321
|
|
|
*/ |
322
|
|
|
public function getPayerNameHonorific() |
323
|
|
|
{ |
324
|
|
|
return $this->payerNameHonorific; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @param string |
329
|
|
|
* @return self |
330
|
|
|
*/ |
331
|
|
|
public function setPayerNameHonorific($hon) |
332
|
|
|
{ |
333
|
|
|
$this->payerNameHonorific = $hon; |
334
|
|
|
return $this; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* The surname of the payer. |
339
|
|
|
* |
340
|
|
|
* @return string |
341
|
|
|
*/ |
342
|
|
|
public function getPayerLastName() |
343
|
|
|
{ |
344
|
|
|
return $this->payerLastName; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @param string |
349
|
|
|
* @return self |
350
|
|
|
*/ |
351
|
|
|
public function setPayerLastName($name) |
352
|
|
|
{ |
353
|
|
|
$this->payerLastName = $name; |
354
|
|
|
return $this; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* The payer's middle name. |
359
|
|
|
* |
360
|
|
|
* @return string |
361
|
|
|
*/ |
362
|
|
|
public function getPayerMiddleName() |
363
|
|
|
{ |
364
|
|
|
return $this->payerMiddleName; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param string |
369
|
|
|
* @return self |
370
|
|
|
*/ |
371
|
|
|
public function setPayerMiddleName($name) |
372
|
|
|
{ |
373
|
|
|
$this->payerMiddleName = $name; |
374
|
|
|
return $this; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* The payer's first name. |
379
|
|
|
* |
380
|
|
|
* @return string |
381
|
|
|
*/ |
382
|
|
|
public function getPayerFirstName() |
383
|
|
|
{ |
384
|
|
|
return $this->payerFirstName; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* @param string |
389
|
|
|
* @return self |
390
|
|
|
*/ |
391
|
|
|
public function setPayerFirstName($name) |
392
|
|
|
{ |
393
|
|
|
$this->payerFirstName = $name; |
394
|
|
|
return $this; |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* Serialize Payer Country |
399
|
|
|
* @return string |
400
|
|
|
*/ |
401
|
|
|
protected function serializePayerCountry() |
402
|
|
|
{ |
403
|
|
|
return "<PayerCountry>{$this->xmlEncode($this->getPayerCountry())}</PayerCountry>"; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Payment sender's country of residence using standard two-character ISO 3166 country codes. |
408
|
|
|
* Character length and limitations: Two single-byte characters. |
409
|
|
|
* |
410
|
|
|
* @link http://countrycode.org/ |
411
|
|
|
* @return string |
412
|
|
|
*/ |
413
|
|
|
public function getPayerCountry() |
414
|
|
|
{ |
415
|
|
|
return $this->payerCountry; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @param string |
420
|
|
|
* @return self |
421
|
|
|
*/ |
422
|
|
|
public function setPayerCountry($country) |
423
|
|
|
{ |
424
|
|
|
$this->payerCountry = $country; |
425
|
|
|
return $this; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Serialize Payer Phone |
430
|
|
|
* @return string |
431
|
|
|
*/ |
432
|
|
|
protected function serializePayerPhone() |
433
|
|
|
{ |
434
|
|
|
return "<PayerPhone>{$this->xmlEncode($this->getPayerPhone())}</PayerPhone>"; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Payer's phone on file with PayPal. |
439
|
|
|
* |
440
|
|
|
* @return string |
441
|
|
|
*/ |
442
|
|
|
public function getPayerPhone() |
443
|
|
|
{ |
444
|
|
|
return $this->payerPhone; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* @param string |
449
|
|
|
* @return self |
450
|
|
|
*/ |
451
|
|
|
public function setPayerPhone($phone) |
452
|
|
|
{ |
453
|
|
|
$this->payerPhone = $phone; |
454
|
|
|
return $this; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
protected function getSchemaFile() |
458
|
|
|
{ |
459
|
|
|
return $this->getSchemaDir() . self::XSD; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* The XML namespace for the payload. |
464
|
|
|
* |
465
|
|
|
* @return string |
466
|
|
|
*/ |
467
|
|
|
protected function getXmlNamespace() |
468
|
|
|
{ |
469
|
|
|
return static::XML_NS; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Return the name of the xml root node. |
474
|
|
|
* |
475
|
|
|
* @return string |
476
|
|
|
*/ |
477
|
|
|
protected function getRootNodeName() |
478
|
|
|
{ |
479
|
|
|
return static::ROOT_NODE; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* add the address status element to a serialized IBillingAddress or |
484
|
|
|
* IShippingAddress |
485
|
|
|
* @param string $status |
486
|
|
|
* @param string $serializedAddress |
487
|
|
|
* @return string |
488
|
|
|
*/ |
489
|
|
|
protected function injectAddressStatus($status, $serializedAddress) |
490
|
|
|
{ |
491
|
|
|
if ($status) { |
492
|
|
|
$closeTagPos = strrpos($serializedAddress, '</'); |
493
|
|
|
$serializedAddress = substr_replace( |
494
|
|
|
$serializedAddress, |
495
|
|
|
"<AddressStatus>{$this->xmlEncode($status)}</AddressStatus>", |
496
|
|
|
$closeTagPos, |
497
|
|
|
0 |
498
|
|
|
); |
499
|
|
|
} |
500
|
|
|
return $serializedAddress; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* serialize the billing address along with the address |
505
|
|
|
* status |
506
|
|
|
* @return string |
507
|
|
|
*/ |
508
|
|
|
protected function serializeBillingAddressWithStatus() |
509
|
|
|
{ |
510
|
|
|
return $this->injectAddressStatus($this->getBillingAddressStatus(), $this->serializeBillingAddress()); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* serialize the shipping address along with the address |
515
|
|
|
* status |
516
|
|
|
* @return string |
517
|
|
|
*/ |
518
|
|
|
protected function serializeShippingAddressWithStatus() |
519
|
|
|
{ |
520
|
|
|
return $this->injectAddressStatus($this->getShippingAddressStatus(), $this->serializeShippingAddress()); |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..