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,11 @@ 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
122
123
*/
123
- public function testCaptureCorrectId (string $ parentTransactionId )
124
+ public function testCaptureCorrectId (string $ parentTransactionId, bool $ createPaymentToken )
124
125
{
125
126
if (empty ($ parentTransactionId )) {
126
127
$ setParentTransactionIdCalls = 1 ;
@@ -132,36 +133,54 @@ public function testCaptureCorrectId(string $parentTransactionId)
132
133
$ getGatewayTokenCalls = 0 ;
133
134
}
134
135
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 ))
136
+ $ this ->payment ->expects ($ this ->any ())
142
137
->method ('getAdditionalInformation ' )
143
- ->willReturnCallback (function ($ args ) {
138
+ ->willReturnCallback (function ($ args ) use ( $ createPaymentToken ) {
144
139
static $ callCount = 0 ;
145
140
if ($ callCount == 0 && $ args == 'result_code ' ) {
146
141
$ callCount ++;
147
142
return 0 ;
148
- } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF ) {
143
+ } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && ! $ createPaymentToken ) {
149
144
$ callCount ++;
150
145
return '' ;
146
+ }elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && $ createPaymentToken ) {
147
+ $ callCount ++;
148
+ return 'ABCD ' ;
151
149
} elseif ($ callCount == 2 && $ args == Payflowpro::PNREF ) {
152
150
$ callCount ++;
153
151
return Payflowpro::PNREF ;
154
152
} elseif ($ callCount == 3 && $ args == Payflowpro::PNREF ) {
155
153
$ callCount ++;
156
154
return Payflowpro::PNREF ;
155
+ } else if ($ args == PayPalPayflowTransparent::CC_DETAILS && $ createPaymentToken ) {
156
+ return json_encode ([]);
157
157
}
158
158
});
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 );
159
+
160
+ $ gatewayToken = 'gateway_token ' ;
161
+ if ($ createPaymentToken ) {
162
+ $ this ->payment ->expects ($ this ->never ())->method ('setParentTransactionId ' );
163
+ $ this ->payment ->expects ($ this ->never ())
164
+ ->method ('setAdditionalInformation ' );
165
+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
166
+ ->method ('getVaultPaymentToken ' )
167
+ ->willReturn (null );
168
+ $ this ->paymentToken ->expects ($ this ->never ())
169
+ ->method ('getGatewayToken ' )
170
+ ->willReturn ($ gatewayToken );
171
+ } else {
172
+ $ this ->payment ->expects ($ this ->once ())->method ('getParentTransactionId ' )->willReturn ($ parentTransactionId );
173
+ $ this ->payment ->expects ($ this ->exactly ($ setParentTransactionIdCalls ))->method ('setParentTransactionId ' );
174
+ $ this ->payment ->expects ($ this ->exactly ($ setAdditionalInformationCalls ))
175
+ ->method ('setAdditionalInformation ' )
176
+ ->with (Payflowpro::PNREF , $ gatewayToken );
177
+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
178
+ ->method ('getVaultPaymentToken ' )
179
+ ->willReturn ($ this ->paymentToken );
180
+ $ this ->paymentToken ->expects ($ this ->exactly ($ getGatewayTokenCalls ))
181
+ ->method ('getGatewayToken ' )
182
+ ->willReturn ($ gatewayToken );
183
+ }
165
184
166
185
$ this ->subject ->capture ($ this ->payment , 100 );
167
186
}
@@ -174,8 +193,10 @@ public function testCaptureCorrectId(string $parentTransactionId)
174
193
public static function captureCorrectIdDataProvider (): array
175
194
{
176
195
return [
177
- 'No Transaction ID ' => ['' ],
178
- 'With Transaction ID ' => ['1 ' ],
196
+ ['' , false ],
197
+ ['1 ' , false ],
198
+ ['' , true ],
199
+ ['1 ' , true ],
179
200
];
180
201
}
181
202
@@ -387,7 +408,8 @@ private function initPayment()
387
408
'getParentTransactionId ' ,
388
409
'setParentTransactionId ' ,
389
410
'setAdditionalInformation ' ,
390
- 'getAdditionalInformation '
411
+ 'getAdditionalInformation ' ,
412
+ 'setExtensionAttributes '
391
413
]
392
414
)
393
415
->getMock ();
0 commit comments