11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2015 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -117,10 +117,11 @@ protected function setUp(): void
117117 *
118118 * @dataProvider captureCorrectIdDataProvider
119119 * @param string $parentTransactionId
120+ * @param bool $createPaymentToken
120121 * @throws InvalidTransitionException
121122 * @throws LocalizedException
122123 */
123- public function testCaptureCorrectId (string $ parentTransactionId )
124+ public function testCaptureCorrectId (string $ parentTransactionId, bool $ createPaymentToken )
124125 {
125126 if (empty ($ parentTransactionId )) {
126127 $ setParentTransactionIdCalls = 1 ;
@@ -132,36 +133,54 @@ public function testCaptureCorrectId(string $parentTransactionId)
132133 $ getGatewayTokenCalls = 0 ;
133134 }
134135
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 ())
142137 ->method ('getAdditionalInformation ' )
143- ->willReturnCallback (function ($ args ) {
138+ ->willReturnCallback (function ($ args ) use ( $ createPaymentToken ) {
144139 static $ callCount = 0 ;
145140 if ($ callCount == 0 && $ args == 'result_code ' ) {
146141 $ callCount ++;
147142 return 0 ;
148- } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF ) {
143+ } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && ! $ createPaymentToken ) {
149144 $ callCount ++;
150145 return '' ;
146+ }elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && $ createPaymentToken ) {
147+ $ callCount ++;
148+ return 'ABCD ' ;
151149 } elseif ($ callCount == 2 && $ args == Payflowpro::PNREF ) {
152150 $ callCount ++;
153151 return Payflowpro::PNREF ;
154152 } elseif ($ callCount == 3 && $ args == Payflowpro::PNREF ) {
155153 $ callCount ++;
156154 return Payflowpro::PNREF ;
155+ } else if ($ args == PayPalPayflowTransparent::CC_DETAILS && $ createPaymentToken ) {
156+ return json_encode ([]);
157157 }
158158 });
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+ }
165184
166185 $ this ->subject ->capture ($ this ->payment , 100 );
167186 }
@@ -174,8 +193,10 @@ public function testCaptureCorrectId(string $parentTransactionId)
174193 public static function captureCorrectIdDataProvider (): array
175194 {
176195 return [
177- 'No Transaction ID ' => ['' ],
178- 'With Transaction ID ' => ['1 ' ],
196+ ['' , false ],
197+ ['1 ' , false ],
198+ ['' , true ],
199+ ['1 ' , true ],
179200 ];
180201 }
181202
@@ -387,7 +408,8 @@ private function initPayment()
387408 'getParentTransactionId ' ,
388409 'setParentTransactionId ' ,
389410 'setAdditionalInformation ' ,
390- 'getAdditionalInformation '
411+ 'getAdditionalInformation ' ,
412+ 'setExtensionAttributes '
391413 ]
392414 )
393415 ->getMock ();
0 commit comments