Skip to content

Commit 86ebb81

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4064' into PR_2025_07_18_chittima
2 parents c0cb63c + f5066f4 commit 86ebb81

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
lines changed

app/code/Magento/Paypal/Model/Payflow/Transparent.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ protected function createPaymentToken(Payment $payment, $token)
284284
*/
285285
private function getExpirationDate(Payment $payment)
286286
{
287-
$expDate = new \DateTime(
287+
$cardExpDate = new \DateTime(
288288
$payment->getCcExpYear()
289289
. '-'
290290
. $payment->getCcExpMonth()
@@ -294,8 +294,13 @@ private function getExpirationDate(Payment $payment)
294294
. '00:00:00',
295295
new \DateTimeZone('UTC')
296296
);
297-
$expDate->add(new \DateInterval('P1M'));
298-
return $expDate->format('Y-m-d 00:00:00');
297+
$cardExpDate->add(new \DateInterval('P1M'));
298+
$oneYearFromNow = new \DateTime('now', new \DateTimeZone('UTC'));
299+
$oneYearFromNow->add(new \DateInterval('P1Y'));
300+
if ($cardExpDate <= $oneYearFromNow) {
301+
return $cardExpDate->format('Y-m-d 00:00:00');
302+
}
303+
return $oneYearFromNow->format('Y-m-d 00:00:00');
299304
}
300305

301306
/**

app/code/Magento/Paypal/Test/Unit/Model/Payflow/TransparentTest.php

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
*/
66
declare(strict_types=1);
77

@@ -117,10 +117,12 @@ protected function setUp(): void
117117
*
118118
* @dataProvider captureCorrectIdDataProvider
119119
* @param string $parentTransactionId
120+
* @param bool $createPaymentToken
120121
* @throws InvalidTransitionException
121122
* @throws LocalizedException
123+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
122124
*/
123-
public function testCaptureCorrectId(string $parentTransactionId)
125+
public function testCaptureCorrectId(string $parentTransactionId, bool $createPaymentToken)
124126
{
125127
if (empty($parentTransactionId)) {
126128
$setParentTransactionIdCalls = 1;
@@ -132,36 +134,54 @@ public function testCaptureCorrectId(string $parentTransactionId)
132134
$getGatewayTokenCalls = 0;
133135
}
134136

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())
142138
->method('getAdditionalInformation')
143-
->willReturnCallback(function ($args) {
139+
->willReturnCallback(function ($args) use ($createPaymentToken) {
144140
static $callCount = 0;
145141
if ($callCount == 0 && $args == 'result_code') {
146142
$callCount++;
147143
return 0;
148-
} elseif ($callCount == 1 && $args == Payflowpro::PNREF) {
144+
} elseif ($callCount == 1 && $args == Payflowpro::PNREF && !$createPaymentToken) {
149145
$callCount++;
150146
return '';
147+
} elseif ($callCount == 1 && $args == Payflowpro::PNREF && $createPaymentToken) {
148+
$callCount++;
149+
return 'ABCD';
151150
} elseif ($callCount == 2 && $args == Payflowpro::PNREF) {
152151
$callCount++;
153152
return Payflowpro::PNREF;
154153
} elseif ($callCount == 3 && $args == Payflowpro::PNREF) {
155154
$callCount++;
156155
return Payflowpro::PNREF;
156+
} elseif ($args == PayPalPayflowTransparent::CC_DETAILS && $createPaymentToken) {
157+
return json_encode([]);
157158
}
158159
});
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+
}
165185

166186
$this->subject->capture($this->payment, 100);
167187
}
@@ -174,8 +194,10 @@ public function testCaptureCorrectId(string $parentTransactionId)
174194
public static function captureCorrectIdDataProvider(): array
175195
{
176196
return [
177-
'No Transaction ID' => [''],
178-
'With Transaction ID' => ['1'],
197+
['', false],
198+
['1', false],
199+
['', true],
200+
['1', true],
179201
];
180202
}
181203

@@ -387,7 +409,8 @@ private function initPayment()
387409
'getParentTransactionId',
388410
'setParentTransactionId',
389411
'setAdditionalInformation',
390-
'getAdditionalInformation'
412+
'getAdditionalInformation',
413+
'setExtensionAttributes'
391414
]
392415
)
393416
->getMock();

0 commit comments

Comments
 (0)