|
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 PayPalPayment implements IPayPalPayment |
|
30
|
|
|
{ |
|
31
|
|
|
use TPayload, TAmount, TCustomAttributeContainer, TPaymentContext; |
|
32
|
|
|
|
|
33
|
|
|
const ROOT_NODE = 'PayPal'; |
|
34
|
|
|
|
|
35
|
|
|
/** @var float */ |
|
36
|
|
|
protected $amount; |
|
37
|
|
|
/** @var float */ |
|
38
|
|
|
protected $amountAuthorized; |
|
39
|
|
|
/** @Datvar DateTime */ |
|
40
|
|
|
protected $createTimeStamp; |
|
41
|
|
|
/** @svar string */ |
|
42
|
|
|
protected $authorizationResponseCode; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param IValidatorIterator |
|
46
|
|
|
* @param ISchemaValidator |
|
47
|
|
|
* @param IPayloadMap |
|
48
|
|
|
* @param LoggerInterface |
|
49
|
|
|
* @param IPayload |
|
50
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
51
|
|
|
*/ |
|
52
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
53
|
|
|
IValidatorIterator $validators, |
|
54
|
|
|
ISchemaValidator $schemaValidator, |
|
|
|
|
|
|
55
|
|
|
IPayloadMap $payloadMap, |
|
56
|
|
|
LoggerInterface $logger, |
|
57
|
|
|
IPayload $parentPayload = null |
|
58
|
|
|
) { |
|
59
|
|
|
$this->logger = $logger; |
|
|
|
|
|
|
60
|
|
|
$this->validators = $validators; |
|
61
|
|
|
$this->payloadMap = $payloadMap; |
|
62
|
|
|
$this->parentPayload = $parentPayload; |
|
63
|
|
|
$this->payloadFactory = new PayloadFactory; |
|
64
|
|
|
|
|
65
|
|
|
$this->extractionPaths = [ |
|
66
|
|
|
'amount' => 'string(x:Amount)', |
|
67
|
|
|
'amountAuthorized' => 'string(x:AmountAuthorized)', |
|
68
|
|
|
'authorizationResponseCode' => 'string(x:Authorization/x:ResponseCode)', |
|
69
|
|
|
'orderId' => 'string(x:PaymentContext/x:PaymentSessionId)', |
|
70
|
|
|
'tenderType' => 'string(x:PaymentContext/x:TenderType)', |
|
71
|
|
|
'accountUniqueId' => 'string(x:PaymentContext/x:PaymentAccountUniqueId)', |
|
72
|
|
|
'paymentRequestId' => 'string(x:PaymentRequestId)', |
|
73
|
|
|
]; |
|
74
|
|
|
$this->booleanExtractionPaths = [ |
|
75
|
|
|
'panIsToken' => 'string(x:PaymentContext/x:PaymentAccountUniqueId/@isToken)', |
|
76
|
|
|
]; |
|
77
|
|
|
$this->subpayloadExtractionPaths = [ |
|
78
|
|
|
'customAttributes' => 'x:CustomAttributes', |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
$this->customAttributes = $this->buildPayloadForInterface(self::CUSTOM_ATTRIBUTE_ITERABLE_INTERFACE); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getAmount() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->amount; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setAmount($amount) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->amount = $this->sanitizeAmount($amount); |
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getAmountAuthorized() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->amountAuthorized; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function setAmountAuthorized($amountAuthorized) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->amountAuthorized = $this->sanitizeAmount($amountAuthorized); |
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getCreateTimeStamp() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->createTimeStamp; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function setCreateTimeStamp(DateTime $createTimeStamp) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->createTimeStamp = $createTimeStamp; |
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getAuthorizationResponseCode() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->authorizationResponseCode; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function setAuthorizationResponseCode($authorizationResponseCode) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->authorizationResponseCode = $authorizationResponseCode; |
|
125
|
|
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
protected function serializeContents() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->serializeAmount('Amount', $this->getAmount()) |
|
131
|
|
|
. $this->serializeAmount('AmountAuthorized', $this->getAmountAuthorized()) |
|
132
|
|
|
. $this->serializePaymentContext() |
|
133
|
|
|
. "<CreateTimeStamp>{$this->getCreateTimeStamp()->format('c')}</CreateTimeStamp>" |
|
134
|
|
|
. $this->serializePaymentRequestId() |
|
135
|
|
|
. "<Authorization><ResponseCode>{$this->xmlEncode($this->getAuthorizationResponseCode())}</ResponseCode></Authorization>" |
|
136
|
|
|
. $this->getCustomAttributes()->serialize(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
View Code Duplication |
protected function deserializeExtra($serializedPayload) |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
$xpath = $this->getPayloadAsXPath($serializedPayload); |
|
142
|
|
|
$createTimestampValue = $xpath->evaluate('string(x:CreateTimeStamp)'); |
|
143
|
|
|
$this->createTimeStamp = $createTimestampValue ? new DateTime($createTimestampValue) : null; |
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
protected function getRootNodeName() |
|
148
|
|
|
{ |
|
149
|
|
|
return self::ROOT_NODE; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
protected function getXmlNamespace() |
|
153
|
|
|
{ |
|
154
|
|
|
return self::XML_NS; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
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.