Skip to content

Commit 73568e3

Browse files
committed
MC-13775: [2.2.x] Accept.js for Auth.net
1 parent 82ce9bd commit 73568e3

38 files changed

+361
-148
lines changed

app/code/Magento/AuthorizenetAcceptjs/Block/Payment.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Payment extends Template
3131
*/
3232
private $json;
3333

34+
/**
35+
* @var string
36+
*/
37+
private static $methodCode = 'authorizenet_acceptjs';
38+
3439
/**
3540
* @param Context $context
3641
* @param ConfigProviderInterface $config
@@ -69,6 +74,6 @@ public function getPaymentConfig(): string
6974
*/
7075
public function getMethodCode(): string
7176
{
72-
return Config::METHOD;
77+
return self::$methodCode;
7378
}
7479
}

app/code/Magento/AuthorizenetAcceptjs/Gateway/Command/AcceptPaymentStrategyCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
*/
1818
class AcceptPaymentStrategyCommand implements CommandInterface
1919
{
20-
const ACCEPT_FDS = 'accept_fds';
21-
const NEEDS_APPROVAL_STATUSES = [
20+
/**
21+
* @var string
22+
*/
23+
private static $acceptFds = 'accept_fds';
24+
25+
/**
26+
* @var array
27+
*/
28+
private static $needsApprovalStatuses = [
2229
'FDSPendingReview',
2330
'FDSAuthorizedPendingReview',
2431
];
@@ -51,7 +58,7 @@ public function __construct(
5158
public function execute(array $commandSubject)
5259
{
5360
if ($this->shouldAcceptInGateway($commandSubject)) {
54-
$this->commandPool->get(self::ACCEPT_FDS)
61+
$this->commandPool->get(self::$acceptFds)
5562
->execute($commandSubject);
5663
}
5764
}
@@ -68,6 +75,6 @@ private function shouldAcceptInGateway(array $commandSubject): bool
6875
->execute($commandSubject)
6976
->get();
7077

71-
return in_array($details['transaction']['transactionStatus'], self::NEEDS_APPROVAL_STATUSES);
78+
return in_array($details['transaction']['transactionStatus'], self::$needsApprovalStatuses);
7279
}
7380
}

app/code/Magento/AuthorizenetAcceptjs/Gateway/Command/CaptureStrategyCommand.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@
2323
*/
2424
class CaptureStrategyCommand implements CommandInterface
2525
{
26-
const SALE = 'sale';
27-
const CAPTURE = 'settle';
26+
/**
27+
* @var string
28+
*/
29+
private static $sale= 'sale';
30+
31+
/**
32+
* @var string
33+
*/
34+
private static $capture = 'settle';
2835

2936
/**
3037
* @var CommandPoolInterface
@@ -99,10 +106,10 @@ private function getCommand(PaymentDataObjectInterface $paymentDO): string
99106
// If auth transaction does not exist then execute authorize&capture command
100107
$captureExists = $this->captureTransactionExists($payment);
101108
if (!$payment->getAuthorizationTransaction() && !$captureExists) {
102-
return self::SALE;
109+
return self::$sale;
103110
}
104111

105-
return self::CAPTURE;
112+
return self::$capture;
106113
}
107114

108115
/**
@@ -126,7 +133,7 @@ private function captureTransactionExists(OrderPaymentInterface $payment): bool
126133
[
127134
$this->filterBuilder
128135
->setField('txn_type')
129-
->setValue(TransactionInterface::TYPE_CAPTURE)
136+
->setValue(self::$capture)
130137
->create(),
131138
]
132139
);

app/code/Magento/AuthorizenetAcceptjs/Gateway/Command/GatewayQueryCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function execute(array $commandSubject)
7878

7979
try {
8080
$response = $this->client->placeRequest($transferO);
81-
} catch (\Throwable $e) {
81+
} catch (\Throwable $e) {
8282
$this->logger->critical($e);
8383

8484
throw new CommandException(__('There was an error while trying to process the request.'));

app/code/Magento/AuthorizenetAcceptjs/Gateway/Command/RefundTransactionStrategyCommand.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
*/
1818
class RefundTransactionStrategyCommand implements CommandInterface
1919
{
20-
const REFUND = 'refund_settled';
21-
const VOID = 'void';
20+
/**
21+
* @var string
22+
*/
23+
private static $refund = 'refund_settled';
24+
25+
/**
26+
* @var string
27+
*/
28+
private static $void = 'void';
2229

2330
/**
2431
* @var CommandPoolInterface
@@ -67,11 +74,11 @@ private function getCommand(array $commandSubject): string
6774
->get();
6875

6976
if ($details['transaction']['transactionStatus'] === 'capturedPendingSettlement') {
70-
return self::VOID;
77+
return self::$void;
7178
} elseif ($details['transaction']['transactionStatus'] !== 'settledSuccessfully') {
7279
throw new CommandException(__('This transaction cannot be refunded with its current status.'));
7380
}
7481

75-
return self::REFUND;
82+
return self::$refund;
7683
}
7784
}

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

Lines changed: 98 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,85 @@
1616
*/
1717
class Config extends \Magento\Payment\Gateway\Config\Config
1818
{
19-
const METHOD = 'authorizenet_acceptjs';
20-
const KEY_LOGIN_ID = 'login';
21-
const KEY_TRANSACTION_KEY = 'trans_key';
22-
const KEY_ENVIRONMENT = 'environment';
23-
const KEY_LEGACY_TRANSACTION_HASH = 'trans_md5';
24-
const KEY_SIGNATURE_KEY = 'trans_signature_key';
25-
const KEY_PAYMENT_ACTION = 'payment_action';
26-
const KEY_SHOULD_EMAIL_CUSTOMER = 'email_customer';
27-
const KEY_ADDITIONAL_INFO_KEYS = 'paymentInfoKeys';
28-
const KEY_CLIENT_KEY = 'public_client_key';
29-
const KEY_CVV_ENABLED = 'cvv_enabled';
30-
const KEY_TRANSACTION_SYNC_KEYS = 'transactionSyncKeys';
31-
const ENDPOINT_URL_SANDBOX = 'https://apitest.authorize.net/xml/v1/request.api';
32-
const ENDPOINT_URL_PRODUCTION = 'https://api.authorize.net/xml/v1/request.api';
33-
const SOLUTION_ID_SANDBOX = 'AAA102993';
34-
const SOLUTION_ID_PRODUCTION = 'AAA175350';
19+
/**
20+
* @var string
21+
*/
22+
private static $keyLoginId = 'login';
23+
24+
/**
25+
* @var string
26+
*/
27+
private static $keyTransactionKey = 'trans_key';
28+
29+
/**
30+
* @var string
31+
*/
32+
private static $keyEnvironment = 'environment';
33+
34+
/**
35+
* @var string
36+
*/
37+
private static $keyLegacyTransactionHash = 'trans_md5';
38+
39+
/**
40+
* @var string
41+
*/
42+
private static $keySignatureKey = 'trans_signature_key';
43+
44+
/**
45+
* @var string
46+
*/
47+
private static $keyPaymentAction = 'payment_action';
48+
49+
/**
50+
* @var string
51+
*/
52+
private static $keyShouldEmailCustomer = 'email_customer';
53+
54+
/**
55+
* @var string
56+
*/
57+
private static $keyAdditionalInfoKeys = 'paymentInfoKeys';
58+
59+
/**
60+
* @var string
61+
*/
62+
private static $keyClientKey = 'public_client_key';
63+
64+
/**
65+
* @var string
66+
*/
67+
private static $keyCvvEnabled = 'cvv_enabled';
68+
69+
/**
70+
* @var string
71+
*/
72+
private static $keyTransactionSyncKeys = 'transactionSyncKeys';
73+
74+
/**
75+
* @var string
76+
*/
77+
private static $endpointUrlSandbox = 'https://apitest.authorize.net/xml/v1/request.api';
78+
79+
/**
80+
* @var string
81+
*/
82+
private static $endpointUrlProduction = 'https://api.authorize.net/xml/v1/request.api';
83+
84+
/**
85+
* @var string
86+
*/
87+
private static $solutionIdSandbox = 'AAA102993';
88+
89+
/**
90+
* @var string
91+
*/
92+
private static $solutionIdProduction = 'AAA175350';
93+
94+
/**
95+
* @var string
96+
*/
97+
private static $environmentSandbox = 'sandbox';
3598

3699
/**
37100
* Gets the login id
@@ -41,7 +104,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config
41104
*/
42105
public function getLoginId($storeId = null)
43106
{
44-
return $this->getValue(Config::KEY_LOGIN_ID, $storeId);
107+
return $this->getValue(Config::$keyLoginId, $storeId);
45108
}
46109

47110
/**
@@ -52,7 +115,7 @@ public function getLoginId($storeId = null)
52115
*/
53116
public function getEnvironment($storeId = null): string
54117
{
55-
return $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
118+
return $this->getValue(Config::$keyEnvironment, $storeId);
56119
}
57120

58121
/**
@@ -63,7 +126,7 @@ public function getEnvironment($storeId = null): string
63126
*/
64127
public function getTransactionKey($storeId = null)
65128
{
66-
return $this->getValue(Config::KEY_TRANSACTION_KEY, $storeId);
129+
return $this->getValue(Config::$keyTransactionKey, $storeId);
67130
}
68131

69132
/**
@@ -74,11 +137,11 @@ public function getTransactionKey($storeId = null)
74137
*/
75138
public function getApiUrl($storeId = null): string
76139
{
77-
$environment = $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
140+
$environment = $this->getValue(Config::$keyEnvironment, $storeId);
78141

79-
return $environment === Environment::ENVIRONMENT_SANDBOX
80-
? self::ENDPOINT_URL_SANDBOX
81-
: self::ENDPOINT_URL_PRODUCTION;
142+
return $environment === self::$environmentSandbox
143+
? self::$endpointUrlSandbox
144+
: self::$endpointUrlProduction;
82145
}
83146

84147
/**
@@ -89,7 +152,7 @@ public function getApiUrl($storeId = null): string
89152
*/
90153
public function getTransactionSignatureKey($storeId = null)
91154
{
92-
return $this->getValue(Config::KEY_SIGNATURE_KEY, $storeId);
155+
return $this->getValue(Config::$keySignatureKey, $storeId);
93156
}
94157

95158
/**
@@ -100,7 +163,7 @@ public function getTransactionSignatureKey($storeId = null)
100163
*/
101164
public function getLegacyTransactionHash($storeId = null)
102165
{
103-
return $this->getValue(Config::KEY_LEGACY_TRANSACTION_HASH, $storeId);
166+
return $this->getValue(Config::$keyLegacyTransactionHash, $storeId);
104167
}
105168

106169
/**
@@ -111,7 +174,7 @@ public function getLegacyTransactionHash($storeId = null)
111174
*/
112175
public function getPaymentAction($storeId = null)
113176
{
114-
return $this->getValue(Config::KEY_PAYMENT_ACTION, $storeId);
177+
return $this->getValue(Config::$keyPaymentAction, $storeId);
115178
}
116179

117180
/**
@@ -122,7 +185,7 @@ public function getPaymentAction($storeId = null)
122185
*/
123186
public function getClientKey($storeId = null)
124187
{
125-
return $this->getValue(Config::KEY_CLIENT_KEY, $storeId);
188+
return $this->getValue(Config::$keyClientKey, $storeId);
126189
}
127190

128191
/**
@@ -133,7 +196,7 @@ public function getClientKey($storeId = null)
133196
*/
134197
public function shouldEmailCustomer($storeId = null): bool
135198
{
136-
return (bool)$this->getValue(Config::KEY_SHOULD_EMAIL_CUSTOMER, $storeId);
199+
return (bool)$this->getValue(Config::$keyShouldEmailCustomer, $storeId);
137200
}
138201

139202
/**
@@ -144,7 +207,7 @@ public function shouldEmailCustomer($storeId = null): bool
144207
*/
145208
public function isCvvEnabled($storeId = null): bool
146209
{
147-
return (bool)$this->getValue(Config::KEY_CVV_ENABLED, $storeId);
210+
return (bool)$this->getValue(Config::$keyCvvEnabled, $storeId);
148211
}
149212

150213
/**
@@ -155,11 +218,11 @@ public function isCvvEnabled($storeId = null): bool
155218
*/
156219
public function getSolutionId($storeId = null)
157220
{
158-
$environment = $this->getValue(Config::KEY_ENVIRONMENT, $storeId);
221+
$environment = $this->getValue(Config::$keyEnvironment, $storeId);
159222

160-
return $environment === Environment::ENVIRONMENT_SANDBOX
161-
? self::SOLUTION_ID_SANDBOX
162-
: self::SOLUTION_ID_PRODUCTION;
223+
return $environment === self::$environmentSandbox
224+
? self::$solutionIdSandbox
225+
: self::$solutionIdProduction;
163226
}
164227

165228
/**
@@ -170,7 +233,7 @@ public function getSolutionId($storeId = null)
170233
*/
171234
public function getAdditionalInfoKeys($storeId = null): array
172235
{
173-
return explode(',', $this->getValue(Config::KEY_ADDITIONAL_INFO_KEYS, $storeId) ?? '');
236+
return explode(',', $this->getValue(Config::$keyAdditionalInfoKeys, $storeId) ?? '');
174237
}
175238

176239
/**
@@ -181,6 +244,6 @@ public function getAdditionalInfoKeys($storeId = null): array
181244
*/
182245
public function getTransactionInfoSyncKeys($storeId = null): array
183246
{
184-
return explode(',', $this->getValue(Config::KEY_TRANSACTION_SYNC_KEYS, $storeId) ?? '');
247+
return explode(',', $this->getValue(Config::$keyTransactionSyncKeys, $storeId) ?? '');
185248
}
186249
}

app/code/Magento/AuthorizenetAcceptjs/Gateway/Request/AuthorizeDataBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
*/
1919
class AuthorizeDataBuilder implements BuilderInterface
2020
{
21-
const REQUEST_AUTH_ONLY = 'authOnlyTransaction';
21+
/**
22+
* @var string
23+
*/
24+
private static $requestAuthOnly = 'authOnlyTransaction';
2225

2326
/**
2427
* @var SubjectReader
@@ -54,7 +57,7 @@ public function build(array $buildSubject)
5457
if ($payment instanceof Payment) {
5558
$data = [
5659
'transactionRequest' => [
57-
'transactionType' => self::REQUEST_AUTH_ONLY,
60+
'transactionType' => self::$requestAuthOnly,
5861
],
5962
];
6063

0 commit comments

Comments
 (0)