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-2015 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\Order; |
17
|
|
|
|
18
|
|
|
use DateTime; |
19
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayload; |
20
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IPayloadMap; |
21
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\ISchemaValidator; |
22
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\IValidatorIterator; |
23
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\PayloadFactory; |
24
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\Payment\TAmount; |
25
|
|
|
use eBayEnterprise\RetailOrderManagement\Payload\TPayload; |
26
|
|
|
use Psr\Log\LoggerInterface; |
27
|
|
|
use Psr\Log\NullLogger; |
28
|
|
|
|
29
|
|
|
class StoredValueCardPayment implements IStoredValueCardPayment |
30
|
|
|
{ |
31
|
|
|
use TPayload, TAmount, TCustomAttributeContainer, TCardPayment; |
32
|
|
|
|
33
|
|
|
const ROOT_NODE = 'StoredValueCard'; |
34
|
|
|
|
35
|
|
|
/** @var DateTime */ |
36
|
|
|
protected $createTimeStamp; |
37
|
|
|
/** @var float */ |
38
|
|
|
protected $amount; |
39
|
|
|
/** @var string */ |
40
|
|
|
protected $pin; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param IValidatorIterator |
44
|
|
|
* @param ISchemaValidator |
45
|
|
|
* @param IPayloadMap |
46
|
|
|
* @param LoggerInterface |
47
|
|
|
* @param IPayload |
48
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
49
|
|
|
*/ |
50
|
|
|
public function __construct( |
51
|
|
|
IValidatorIterator $validators, |
52
|
|
|
ISchemaValidator $schemaValidator, |
53
|
|
|
IPayloadMap $payloadMap, |
54
|
|
|
LoggerInterface $logger, |
55
|
|
|
IPayload $parentPayload = null |
56
|
|
|
) { |
57
|
|
|
$this->logger = $logger; |
|
|
|
|
58
|
|
|
$this->validators = $validators; |
59
|
|
|
$this->schemaValidator = $schemaValidator; |
60
|
|
|
$this->payloadMap = $payloadMap; |
61
|
|
|
$this->parentPayload = $parentPayload; |
62
|
|
|
$this->payloadFactory = new PayloadFactory; |
63
|
|
|
|
64
|
|
|
$this->extractionPaths = [ |
65
|
|
|
'orderId' => 'string(x:PaymentContext/x:PaymentSessionId)', |
66
|
|
|
'tenderType' => 'string(x:PaymentContext/x:TenderType)', |
67
|
|
|
'accountUniqueId' => 'string(x:PaymentContext/x:PaymentAccountUniqueId)', |
68
|
|
|
'paymentRequestId' => 'string(x:PaymentRequestId)', |
69
|
|
|
]; |
70
|
|
|
$this->optionalExtractionPaths = [ |
71
|
|
|
'amount' => 'x:Amount', |
72
|
|
|
'pin' => 'x:Pin', |
73
|
|
|
]; |
74
|
|
|
$this->booleanExtractionPaths = [ |
75
|
|
|
'isMockPayment' => 'string(@isMockPayment)', |
76
|
|
|
'panIsToken' => 'string(x:PaymentContext/x:PaymentAccountUniqueId/@isToken)' |
77
|
|
|
]; |
78
|
|
|
$this->subpayloadExtractionPaths = [ |
79
|
|
|
'customAttributes' => 'x:CustomAttributes', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$this->customAttributes = $this->buildPayloadForInterface(self::CUSTOM_ATTRIBUTE_ITERABLE_INTERFACE); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getCreateTimeStamp() |
86
|
|
|
{ |
87
|
|
|
return $this->createTimeStamp; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function setCreateTimeStamp(DateTime $createTimeStamp) |
91
|
|
|
{ |
92
|
|
|
$this->createTimeStamp = $createTimeStamp; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getAmount() |
97
|
|
|
{ |
98
|
|
|
return $this->amount; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function setAmount($amount) |
102
|
|
|
{ |
103
|
|
|
$this->amount = $this->sanitizeAmount($amount); |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getPin() |
108
|
|
|
{ |
109
|
|
|
return $this->pin; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function setPin($pin) |
113
|
|
|
{ |
114
|
|
|
$this->pin = $this->cleanString($pin, 22); |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
protected function serializeContents() |
119
|
|
|
{ |
120
|
|
|
return $this->serializePaymentContext() |
121
|
|
|
. $this->serializePaymentRequestId() |
122
|
|
|
. "<CreateTimeStamp>{$this->getCreateTimeStamp()->format('c')}</CreateTimeStamp>" |
123
|
|
|
. $this->serializeOptionalXmlEncodedValue('Pin', $this->getPin()) |
124
|
|
|
. $this->serializeAmount('Amount', $this->getAmount()) |
125
|
|
|
. $this->getCustomAttributes()->serialize(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
protected function deserializeExtra($serializedPayload) |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$xpath = $this->getPayloadAsXPath($serializedPayload); |
131
|
|
|
$createTimestampValue = $xpath->evaluate('string(x:CreateTimeStamp)'); |
132
|
|
|
$this->createTimeStamp = $createTimestampValue ? new DateTime($createTimestampValue) : null; |
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
View Code Duplication |
protected function getRootAttributes() |
|
|
|
|
137
|
|
|
{ |
138
|
|
|
$isMockPayment = $this->getIsMockPayment(); |
139
|
|
|
return !is_null($isMockPayment) |
140
|
|
|
? ['isMockPayment' => $this->convertBooleanToString($isMockPayment)] |
141
|
|
|
: []; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
protected function getRootNodeName() |
145
|
|
|
{ |
146
|
|
|
return static::ROOT_NODE; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
protected function getXmlNamespace() |
150
|
|
|
{ |
151
|
|
|
return self::XML_NS; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
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..