1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2015 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
@@ -117,10 +117,12 @@ protected function setUp(): void
117
117
*
118
118
* @dataProvider captureCorrectIdDataProvider
119
119
* @param string $parentTransactionId
120
+ * @param bool $createPaymentToken
120
121
* @throws InvalidTransitionException
121
122
* @throws LocalizedException
123
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
122
124
*/
123
- public function testCaptureCorrectId (string $ parentTransactionId )
125
+ public function testCaptureCorrectId (string $ parentTransactionId, bool $ createPaymentToken )
124
126
{
125
127
if (empty ($ parentTransactionId )) {
126
128
$ setParentTransactionIdCalls = 1 ;
@@ -132,36 +134,54 @@ public function testCaptureCorrectId(string $parentTransactionId)
132
134
$ getGatewayTokenCalls = 0 ;
133
135
}
134
136
135
- $ gatewayToken = 'gateway_token ' ;
136
- $ this ->payment ->expects ($ this ->once ())->method ('getParentTransactionId ' )->willReturn ($ parentTransactionId );
137
- $ this ->payment ->expects ($ this ->exactly ($ setParentTransactionIdCalls ))->method ('setParentTransactionId ' );
138
- $ this ->payment ->expects ($ this ->exactly ($ setAdditionalInformationCalls ))
139
- ->method ('setAdditionalInformation ' )
140
- ->with (Payflowpro::PNREF , $ gatewayToken );
141
- $ this ->payment ->expects ($ this ->exactly (4 ))
137
+ $ this ->payment ->expects ($ this ->any ())
142
138
->method ('getAdditionalInformation ' )
143
- ->willReturnCallback (function ($ args ) {
139
+ ->willReturnCallback (function ($ args ) use ( $ createPaymentToken ) {
144
140
static $ callCount = 0 ;
145
141
if ($ callCount == 0 && $ args == 'result_code ' ) {
146
142
$ callCount ++;
147
143
return 0 ;
148
- } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF ) {
144
+ } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && ! $ createPaymentToken ) {
149
145
$ callCount ++;
150
146
return '' ;
147
+ } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && $ createPaymentToken ) {
148
+ $ callCount ++;
149
+ return 'ABCD ' ;
151
150
} elseif ($ callCount == 2 && $ args == Payflowpro::PNREF ) {
152
151
$ callCount ++;
153
152
return Payflowpro::PNREF ;
154
153
} elseif ($ callCount == 3 && $ args == Payflowpro::PNREF ) {
155
154
$ callCount ++;
156
155
return Payflowpro::PNREF ;
156
+ } elseif ($ args == PayPalPayflowTransparent::CC_DETAILS && $ createPaymentToken ) {
157
+ return json_encode ([]);
157
158
}
158
159
});
159
- $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
160
- ->method ('getVaultPaymentToken ' )
161
- ->willReturn ($ this ->paymentToken );
162
- $ this ->paymentToken ->expects ($ this ->exactly ($ getGatewayTokenCalls ))
163
- ->method ('getGatewayToken ' )
164
- ->willReturn ($ gatewayToken );
160
+
161
+ $ gatewayToken = 'gateway_token ' ;
162
+ if ($ createPaymentToken ) {
163
+ $ this ->payment ->expects ($ this ->never ())->method ('setParentTransactionId ' );
164
+ $ this ->payment ->expects ($ this ->never ())
165
+ ->method ('setAdditionalInformation ' );
166
+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
167
+ ->method ('getVaultPaymentToken ' )
168
+ ->willReturn (null );
169
+ $ this ->paymentToken ->expects ($ this ->never ())
170
+ ->method ('getGatewayToken ' )
171
+ ->willReturn ($ gatewayToken );
172
+ } else {
173
+ $ this ->payment ->expects ($ this ->once ())->method ('getParentTransactionId ' )->willReturn ($ parentTransactionId );
174
+ $ this ->payment ->expects ($ this ->exactly ($ setParentTransactionIdCalls ))->method ('setParentTransactionId ' );
175
+ $ this ->payment ->expects ($ this ->exactly ($ setAdditionalInformationCalls ))
176
+ ->method ('setAdditionalInformation ' )
177
+ ->with (Payflowpro::PNREF , $ gatewayToken );
178
+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
179
+ ->method ('getVaultPaymentToken ' )
180
+ ->willReturn ($ this ->paymentToken );
181
+ $ this ->paymentToken ->expects ($ this ->exactly ($ getGatewayTokenCalls ))
182
+ ->method ('getGatewayToken ' )
183
+ ->willReturn ($ gatewayToken );
184
+ }
165
185
166
186
$ this ->subject ->capture ($ this ->payment , 100 );
167
187
}
@@ -174,8 +194,10 @@ public function testCaptureCorrectId(string $parentTransactionId)
174
194
public static function captureCorrectIdDataProvider (): array
175
195
{
176
196
return [
177
- 'No Transaction ID ' => ['' ],
178
- 'With Transaction ID ' => ['1 ' ],
197
+ ['' , false ],
198
+ ['1 ' , false ],
199
+ ['' , true ],
200
+ ['1 ' , true ],
179
201
];
180
202
}
181
203
@@ -387,7 +409,8 @@ private function initPayment()
387
409
'getParentTransactionId ' ,
388
410
'setParentTransactionId ' ,
389
411
'setAdditionalInformation ' ,
390
- 'getAdditionalInformation '
412
+ 'getAdditionalInformation ' ,
413
+ 'setExtensionAttributes '
391
414
]
392
415
)
393
416
->getMock ();
0 commit comments