Skip to content

Commit f287695

Browse files
John ZolperJohn Zolper
authored andcommitted
Merge branch 'MC-4239' of github.com:magento-borg/magento2ce into MC-4239
2 parents 4593302 + 055c8e0 commit f287695

File tree

13 files changed

+395
-351
lines changed

13 files changed

+395
-351
lines changed

app/code/Magento/AuthorizenetAcceptjs/Gateway/Command/TransactionReviewUpdateCommand.php renamed to app/code/Magento/AuthorizenetAcceptjs/Gateway/Command/FetchTransactionInfoCommand.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\AuthorizenetAcceptjs\Gateway\Command;
1010

11+
use Magento\AuthorizenetAcceptjs\Gateway\Config;
1112
use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
1213
use Magento\Payment\Gateway\Command\CommandPool;
1314
use Magento\Payment\Gateway\Command\CommandPoolInterface;
@@ -17,7 +18,7 @@
1718
/**
1819
* Syncs the transaction status with authorize.net
1920
*/
20-
class TransactionReviewUpdateCommand implements CommandInterface
21+
class FetchTransactionInfoCommand implements CommandInterface
2122
{
2223
private const REVIEW_PENDING_STATUSES = [
2324
'FDSPendingReview',
@@ -38,37 +39,59 @@ class TransactionReviewUpdateCommand implements CommandInterface
3839
*/
3940
private $subjectReader;
4041

42+
/**
43+
* @var Config
44+
*/
45+
private $config;
46+
4147
/**
4248
* @param CommandPoolInterface $commandPool
4349
* @param SubjectReader $subjectReader
50+
* @param Config $config
4451
*/
45-
public function __construct(CommandPoolInterface $commandPool, SubjectReader $subjectReader)
46-
{
52+
public function __construct(
53+
CommandPoolInterface $commandPool,
54+
SubjectReader $subjectReader,
55+
Config $config
56+
) {
4757
$this->commandPool = $commandPool;
4858
$this->subjectReader = $subjectReader;
59+
$this->config = $config;
4960
}
5061

5162
/**
5263
* @inheritdoc
5364
*/
54-
public function execute(array $commandSubject): void
65+
public function execute(array $commandSubject): array
5566
{
5667
$paymentDO = $this->subjectReader->readPayment($commandSubject);
68+
$order = $paymentDO->getOrder();
5769
$payment = $paymentDO->getPayment();
5870

5971
if (!$payment instanceof Payment) {
60-
return;
72+
return [];
6173
}
6274

6375
$command = $this->commandPool->get('get_transaction_details');
6476
$result = $command->execute($commandSubject);
6577
$response = $result->get();
6678
$status = $response['transaction']['transactionStatus'];
6779

80+
// This data is only used when updating the payment on the order
6881
if (!in_array($status, self::REVIEW_PENDING_STATUSES)) {
6982
$denied = in_array($status, self::REVIEW_DECLINED_STATUSES);
7083
$payment->setData('is_transaction_denied', $denied);
7184
$payment->setData('is_transaction_approved', !$denied);
7285
}
86+
87+
$additionalInformationKeys = $this->config->getTransactionInfoSyncKeys($order->getStoreId());
88+
$rawDetails = [];
89+
foreach ($additionalInformationKeys as $key) {
90+
if (isset($response['transaction'][$key])) {
91+
$rawDetails[$key] = $response['transaction'][$key];
92+
}
93+
}
94+
95+
return $rawDetails;
7396
}
7497
}

app/code/Magento/AuthorizenetAcceptjs/Gateway/Config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
2727
private const KEY_ADDITIONAL_INFO_KEYS = 'paymentInfoKeys';
2828
private const KEY_CLIENT_KEY = 'public_client_key';
2929
private const KEY_CVV_ENABLED = 'cvv_enabled';
30+
private const KEY_TRANSACTION_SYNC_KEYS = 'transactionSyncKeys';
3031
private const ENDPOINT_URL_SANDBOX = 'https://apitest.authorize.net/xml/v1/request.api';
3132
private const ENDPOINT_URL_PRODUCTION = 'https://api.authorize.net/xml/v1/request.api';
3233
private const SOLUTION_ID_SANDBOX = 'AAA102993';
@@ -184,4 +185,15 @@ public function getAdditionalInfoKeys($storeId = null): array
184185
{
185186
return explode(',', $this->getValue(Config::KEY_ADDITIONAL_INFO_KEYS, $storeId) ?? '');
186187
}
188+
189+
/**
190+
* Returns the keys to be pulled from the transaction and displayed when syncing the transaction
191+
*
192+
* @param int|null $storeId
193+
* @return string[]
194+
*/
195+
public function getTransactionInfoSyncKeys($storeId = null): array
196+
{
197+
return explode(',', $this->getValue(Config::KEY_TRANSACTION_SYNC_KEYS, $storeId) ?? '');
198+
}
187199
}

app/code/Magento/AuthorizenetAcceptjs/Gateway/Request/RefundTransactionDetailsDataBuilder.php renamed to app/code/Magento/AuthorizenetAcceptjs/Gateway/Request/TransactionDetailsDataBuilder.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Adds the reference transaction to the request
1717
*/
18-
class RefundTransactionDetailsDataBuilder implements BuilderInterface
18+
class TransactionDetailsDataBuilder implements BuilderInterface
1919
{
2020
/**
2121
* @var SubjectReader
@@ -35,26 +35,33 @@ public function __construct(SubjectReader $subjectReader)
3535
*/
3636
public function build(array $buildSubject): array
3737
{
38-
$paymentDO = $this->subjectReader->readPayment($buildSubject);
39-
$payment = $paymentDO->getPayment();
4038
$data = [];
4139

42-
if ($payment instanceof Payment) {
43-
$authorizationTransaction = $payment->getAuthorizationTransaction();
40+
if (!empty($buildSubject['transactionId'])) {
41+
$data = [
42+
'transId' => $buildSubject['transactionId']
43+
];
44+
} else {
45+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
46+
$payment = $paymentDO->getPayment();
4447

45-
if (empty($authorizationTransaction)) {
46-
$transactionId = $payment->getLastTransId();
47-
} else {
48-
$transactionId = $authorizationTransaction->getParentTxnId();
48+
if ($payment instanceof Payment) {
49+
$authorizationTransaction = $payment->getAuthorizationTransaction();
4950

50-
if (empty($transactionId)) {
51-
$transactionId = $authorizationTransaction->getTxnId();
51+
if (empty($authorizationTransaction)) {
52+
$transactionId = $payment->getLastTransId();
53+
} else {
54+
$transactionId = $authorizationTransaction->getParentTxnId();
55+
56+
if (empty($transactionId)) {
57+
$transactionId = $authorizationTransaction->getTxnId();
58+
}
5259
}
53-
}
5460

55-
$data = [
56-
'transId' => $transactionId
57-
];
61+
$data = [
62+
'transId' => $transactionId
63+
];
64+
}
5865
}
5966

6067
return $data;
Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88

99
namespace Magento\AuthorizenetAcceptjs\Test\Unit\Gateway\Command;
1010

11-
use Magento\AuthorizenetAcceptjs\Gateway\Command\TransactionReviewUpdateCommand;
11+
use Magento\AuthorizenetAcceptjs\Gateway\Command\FetchTransactionInfoCommand;
12+
use Magento\AuthorizenetAcceptjs\Gateway\Config;
1213
use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
1314
use Magento\Payment\Gateway\Command\CommandPoolInterface;
1415
use Magento\Payment\Gateway\Command\ResultInterface;
1516
use Magento\Payment\Gateway\CommandInterface;
1617
use Magento\Payment\Gateway\Data\PaymentDataObject;
18+
use Magento\Sales\Model\Order;
1719
use Magento\Sales\Model\Order\Payment;
1820
use PHPUnit\Framework\MockObject\MockObject;
1921
use PHPUnit\Framework\TestCase;
2022

21-
class TransactionReviewUpdateCommandTest extends TestCase
23+
class FetchTransactionInfoCommandTest extends TestCase
2224
{
2325
/**
2426
* @var CommandInterface|MockObject
@@ -31,7 +33,7 @@ class TransactionReviewUpdateCommandTest extends TestCase
3133
private $commandPoolMock;
3234

3335
/**
34-
* @var TransactionReviewUpdateCommand
36+
* @var FetchTransactionInfoCommand
3537
*/
3638
private $command;
3739

@@ -50,18 +52,30 @@ class TransactionReviewUpdateCommandTest extends TestCase
5052
*/
5153
private $paymentMock;
5254

55+
/**
56+
* @var Config
57+
*/
58+
private $configMock;
59+
5360
protected function setUp()
5461
{
5562
$this->paymentDOMock = $this->createMock(PaymentDataObject::class);
5663
$this->paymentMock = $this->createMock(Payment::class);
5764
$this->paymentDOMock->method('getPayment')
5865
->willReturn($this->paymentMock);
66+
$this->configMock = $this->createMock(Config::class);
67+
$this->configMock->method('getTransactionInfoSyncKeys')
68+
->willReturn(['foo', 'bar']);
69+
$orderMock = $this->createMock(Order::class);
70+
$this->paymentDOMock->method('getOrder')
71+
->willReturn($orderMock);
5972
$this->transactionDetailsCommandMock = $this->createMock(CommandInterface::class);
6073
$this->transactionResultMock = $this->createMock(ResultInterface::class);
6174
$this->commandPoolMock = $this->createMock(CommandPoolInterface::class);
62-
$this->command = new TransactionReviewUpdateCommand(
75+
$this->command = new FetchTransactionInfoCommand(
6376
$this->commandPoolMock,
64-
new SubjectReader()
77+
new SubjectReader(),
78+
$this->configMock
6579
);
6680
}
6781

@@ -75,7 +89,10 @@ public function testCommandWillMarkTransactionAsApprovedWhenNotVoid()
7589
$this->transactionResultMock->method('get')
7690
->willReturn([
7791
'transaction' => [
78-
'transactionStatus' => 'authorizedPendingCapture'
92+
'transactionStatus' => 'authorizedPendingCapture',
93+
'foo' => 'abc',
94+
'bar' => 'cba',
95+
'dontreturnme' => 'justdont'
7996
]
8097
]);
8198

@@ -96,7 +113,14 @@ public function testCommandWillMarkTransactionAsApprovedWhenNotVoid()
96113
->with($buildSubject)
97114
->willReturn($this->transactionResultMock);
98115

99-
$this->command->execute($buildSubject);
116+
$result = $this->command->execute($buildSubject);
117+
118+
$expected = [
119+
'foo' => 'abc',
120+
'bar' => 'cba'
121+
];
122+
123+
$this->assertSame($expected, $result);
100124
}
101125

102126
/**
@@ -113,7 +137,10 @@ public function testCommandWillMarkTransactionAsDeniedWhenDeclined(string $statu
113137
$this->transactionResultMock->method('get')
114138
->willReturn([
115139
'transaction' => [
116-
'transactionStatus' => $status
140+
'transactionStatus' => $status,
141+
'foo' => 'abc',
142+
'bar' => 'cba',
143+
'dontreturnme' => 'justdont'
117144
]
118145
]);
119146

@@ -134,7 +161,14 @@ public function testCommandWillMarkTransactionAsDeniedWhenDeclined(string $statu
134161
->with($buildSubject)
135162
->willReturn($this->transactionResultMock);
136163

137-
$this->command->execute($buildSubject);
164+
$result = $this->command->execute($buildSubject);
165+
166+
$expected = [
167+
'foo' => 'abc',
168+
'bar' => 'cba'
169+
];
170+
171+
$this->assertSame($expected, $result);
138172
}
139173

140174
/**
@@ -151,7 +185,10 @@ public function testCommandWillDoNothingWhenTransactionIsStillPending(string $st
151185
$this->transactionResultMock->method('get')
152186
->willReturn([
153187
'transaction' => [
154-
'transactionStatus' => $status
188+
'transactionStatus' => $status,
189+
'foo' => 'abc',
190+
'bar' => 'cba',
191+
'dontreturnme' => 'justdont'
155192
]
156193
]);
157194

@@ -168,7 +205,14 @@ public function testCommandWillDoNothingWhenTransactionIsStillPending(string $st
168205
->with($buildSubject)
169206
->willReturn($this->transactionResultMock);
170207

171-
$this->command->execute($buildSubject);
208+
$result = $this->command->execute($buildSubject);
209+
210+
$expected = [
211+
'foo' => 'abc',
212+
'bar' => 'cba'
213+
];
214+
215+
$this->assertSame($expected, $result);
172216
}
173217

174218
public function pendingTransactionStatusesProvider()

app/code/Magento/AuthorizenetAcceptjs/Test/Unit/Gateway/ConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function configMapProvider()
9494
['shouldEmailCustomer', 'email_customer', true, true],
9595
['isCvvEnabled', 'cvv_enabled', true, true],
9696
['getAdditionalInfoKeys', 'paymentInfoKeys', 'a,b,c', ['a', 'b', 'c']],
97+
['getTransactionInfoSyncKeys', 'transactionSyncKeys', 'a,b,c', ['a', 'b', 'c']],
9798
];
9899
}
99100
public function environmentUrlProvider()
Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\AuthorizenetAcceptjs\Test\Unit\Gateway\Request;
99

10-
use Magento\AuthorizenetAcceptjs\Gateway\Request\RefundTransactionDetailsDataBuilder;
10+
use Magento\AuthorizenetAcceptjs\Gateway\Request\TransactionDetailsDataBuilder;
1111
use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
1212
use Magento\Sales\Model\Order\Payment\Transaction;
1313
use PHPUnit\Framework\TestCase;
@@ -16,10 +16,10 @@
1616
use Magento\Sales\Model\Order\Payment;
1717
use PHPUnit\Framework\MockObject\MockObject;
1818

19-
class RefundTransactionDetailsDataBuilderTest extends TestCase
19+
class TransactionDetailsDataBuilderTest extends TestCase
2020
{
2121
/**
22-
* @var RefundTransactionDetailsDataBuilder
22+
* @var TransactionDetailsDataBuilder
2323
*/
2424
private $builder;
2525

@@ -41,7 +41,7 @@ protected function setUp()
4141
$this->paymentDOMock->method('getPayment')
4242
->willReturn($this->paymentMock);
4343

44-
$this->builder = new RefundTransactionDetailsDataBuilder(new SubjectReader());
44+
$this->builder = new TransactionDetailsDataBuilder(new SubjectReader());
4545
}
4646

4747
public function testBuild()
@@ -64,4 +64,26 @@ public function testBuild()
6464

6565
$this->assertEquals($expected, $this->builder->build($buildSubject));
6666
}
67+
68+
public function testBuildWithIncludedTransactionId()
69+
{
70+
$transactionMock = $this->createMock(Transaction::class);
71+
72+
$this->paymentMock->expects($this->never())
73+
->method('getAuthorizationTransaction');
74+
75+
$transactionMock->expects($this->never())
76+
->method('getParentTxnId');
77+
78+
$expected = [
79+
'transId' => 'foo'
80+
];
81+
82+
$buildSubject = [
83+
'payment' => $this->paymentDOMock,
84+
'transactionId' => 'foo'
85+
];
86+
87+
$this->assertEquals($expected, $this->builder->build($buildSubject));
88+
}
6789
}

app/code/Magento/AuthorizenetAcceptjs/composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
"magento/module-payment": "*",
1111
"magento/module-sales": "*",
1212
"magento/module-config": "*",
13-
"magento/module-catalog": "*",
1413
"magento/module-backend": "*",
1514
"magento/module-checkout": "*",
16-
"magento/module-customer": "*",
17-
"magento/module-directory": "*",
1815
"magento/module-store": "*",
19-
"magento/module-quote": "*",
20-
"magento/module-ui": "*"
16+
"magento/module-quote": "*"
2117
},
2218
"suggest": {
2319
"magento/module-config": "*"

app/code/Magento/AuthorizenetAcceptjs/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<environment>production</environment>
4343
<privateInfoKeys>authCode,avsResultCode,cvvResultCode,cavvResultCode</privateInfoKeys>
4444
<paymentInfoKeys>accountType,ccLast4,authCode,avsResultCode,cvvResultCode,cavvResultCode</paymentInfoKeys>
45+
<transactionSyncKeys>transactionStatus,responseCode,responseReasonCode,authCode,AVSResponse,cardCodeResponse,CAVVResponse</transactionSyncKeys>
4546
</authorizenet_acceptjs>
4647
</payment>
4748
</default>

0 commit comments

Comments
 (0)