Skip to content

Commit 8673cf8

Browse files
authored
Merge pull request #1263 from BearGroup/release/5.18.1
Release/5.18.1
2 parents 658f831 + b020e2b commit 8673cf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+571
-120
lines changed

Block/Config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function getConfig()
7575
'is_lwa_enabled' => $this->isLwaEnabled(),
7676
'is_guest_checkout_enabled' => $this->amazonConfig->isGuestCheckoutEnabled(),
7777
'has_restricted_products' => $this->amazonHelper->hasRestrictedProducts(),
78-
'is_multicurrency_enabled' => $this->amazonConfig->multiCurrencyEnabled()
78+
'is_multicurrency_enabled' => $this->amazonConfig->multiCurrencyEnabled(),
79+
'acceptance_mark' => $this->amazonConfig->getAcceptanceMark()
7980
];
8081

8182
if ($subscriptionLabel = $this->subscriptionManager->getSubscriptionLabel()) {

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## 5.18.1
4+
* Add new logos/acceptance marks at checkout
5+
* Improved clarity of order comments on cancelled orders
6+
* Fixed issue where order confirmation emails could be sent before payment processed successfully
7+
* Fixed issue with some inventory reservations not being adjusted after a cancelled order
8+
* Fixed issue where credit memos occasionally fail to process due to a missing parent transaction ID
9+
* Fixed APB issue where billing address information may fail to be set on virtual quotes
10+
* Fixed APB issue with family name/first name being passed incorrectly in JP region
11+
* Fixed dynamic property declaration in subscription classes (thanks, @navarr!)
12+
* Fixed failures and corrected logging in CleanUpIncompleteSessions cron job (thanks, @mohit-sharma-rp!)
13+
* Fixed various code smells
14+
315
## 5.18.0
416
* Added product page promo banner functionality and configuration
517

Command/Async/ProcessCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7474
$this->asyncUpdater->processPending($item);
7575
}
7676

77-
return Command::SUCCESS;
77+
$code = defined('Command::SUCCESS') ? Command::SUCCESS : 0;
78+
return $code;
7879
}
7980
}

Command/Sales/AmazonChargePermissionCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
123123
}
124124

125125
$verified = $referenceID == $orderId;
126-
$output->writeln(var_export($verified));
126+
if (!empty($verified) && $dump = var_export($verified)) {
127+
$output->writeln($dump);
128+
}
127129
}
128130

129-
return Command::SUCCESS;
131+
$code = defined('Command::SUCCESS') ? Command::SUCCESS : 0;
132+
return $code;
130133
}
131134
}

Controller/Checkout/Cancel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function execute()
7171
$redirectParam = $this->request->getParam('redirect');
7272
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
7373

74+
$this->messageManager->addErrorMessage(__('This transaction was cancelled. Please try again.'));
75+
7476
// redirect to cart if no redirect param provided
7577
if (empty($redirectParam)) {
7678
return $result->setPath('checkout/cart');
@@ -92,8 +94,6 @@ public function execute()
9294
$this->checkoutSessionManagement->cancelOrder($order, $quote);
9395

9496
$this->magentoCheckoutSession->restoreQuote();
95-
96-
$this->messageManager->addErrorMessage(__('This transaction was cancelled. Please try again.'));
9797
}
9898
}
9999
}

Cron/CleanUpIncompleteSessions.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
namespace Amazon\Pay\Cron;
1818

1919
use Amazon\Pay\Helper\Transaction as TransactionHelper;
20+
use Amazon\Pay\Logger\Logger;
2021
use Amazon\Pay\Model\Adapter\AmazonPayAdapter;
21-
use Amazon\Pay\Model\AsyncManagement\Charge;
2222
use Amazon\Pay\Model\CheckoutSessionManagement;
2323
use Magento\Sales\Api\Data\OrderInterface;
2424
use Magento\Sales\Api\OrderRepositoryInterface;
25-
use Psr\Log\LoggerInterface;
2625
use Amazon\Pay\Model\AsyncManagement\Charge as AsyncCharge;
2726

2827
class CleanUpIncompleteSessions
@@ -39,7 +38,7 @@ class CleanUpIncompleteSessions
3938
protected $transactionHelper;
4039

4140
/**
42-
* @var LoggerInterface
41+
* @var Logger
4342
*/
4443
protected $logger;
4544

@@ -65,15 +64,15 @@ class CleanUpIncompleteSessions
6564

6665
/**
6766
* @param TransactionHelper $transactionHelper
68-
* @param LoggerInterface $logger
67+
* @param Logger $logger
6968
* @param AmazonPayAdapter $amazonPayAdapter
7069
* @param CheckoutSessionManagement $checkoutSessionManagement
7170
* @param OrderRepositoryInterface $orderRepository
7271
* @param AsyncCharge $asyncCharge
7372
*/
7473
public function __construct(
7574
TransactionHelper $transactionHelper,
76-
LoggerInterface $logger,
75+
Logger $logger,
7776
AmazonPayAdapter $amazonPayAdapter,
7877
CheckoutSessionManagement $checkoutSessionManagement,
7978
OrderRepositoryInterface $orderRepository,
@@ -114,31 +113,31 @@ protected function processTransaction(array $transactionData)
114113
$checkoutSessionId = $transactionData['checkout_session_id'];
115114
$orderId = $transactionData['order_id'];
116115

117-
$this->logger->info(self::LOG_PREFIX . 'Cleaning up checkout session id: ' . $checkoutSessionId);
116+
$this->logger->debug(self::LOG_PREFIX . 'Cleaning up checkout session id: ' . $checkoutSessionId);
118117

119118
try {
120-
121119
// Check current state of Amazon checkout session
122-
$amazonSession = $this->amazonPayAdapter->getCheckoutSession(null, $checkoutSessionId);
120+
$amazonSession = $this->amazonPayAdapter->getCheckoutSession($transactionData['store_id'], $checkoutSessionId);
123121
$state = $amazonSession['statusDetails']['state'] ?? false;
124122
switch ($state) {
125123
case self::SESSION_STATUS_STATE_CANCELED:
126124
$logMessage = 'Checkout session Canceled, cancelling order and closing transaction: ';
127125
$logMessage .= $checkoutSessionId;
128126
$this->logger->info(self::LOG_PREFIX . $logMessage);
129-
$this->cancelOrder($orderId);
127+
$cancelledMessage = $this->checkoutSessionManagement->getCanceledMessage($amazonSession);
128+
$this->cancelOrder($orderId, $cancelledMessage);
130129
$this->transactionHelper->closeTransaction($transactionData['transaction_id']);
131130
break;
132131
case self::SESSION_STATUS_STATE_OPEN:
133132
$logMessage = 'Checkout session Open, completing: ';
134133
$logMessage .= $checkoutSessionId;
135-
$this->logger->info(self::LOG_PREFIX . $logMessage);
134+
$this->logger->debug(self::LOG_PREFIX . $logMessage);
136135
$this->checkoutSessionManagement->completeCheckoutSession($checkoutSessionId, null, $orderId);
137136
break;
138137
case self::SESSION_STATUS_STATE_COMPLETED:
139138
$logMessage = 'Checkout session Completed, nothing more needed: ';
140139
$logMessage .= $checkoutSessionId;
141-
$this->logger->info(self::LOG_PREFIX . $logMessage);
140+
$this->logger->debug(self::LOG_PREFIX . $logMessage);
142141
break;
143142
}
144143
} catch (\Exception $e) {
@@ -153,12 +152,12 @@ protected function processTransaction(array $transactionData)
153152
* @param int $orderId
154153
* @return void
155154
*/
156-
protected function cancelOrder($orderId)
155+
protected function cancelOrder($orderId, $reasonMessage = '')
157156
{
158157
$order = $this->loadOrder($orderId);
159158

160159
if ($order) {
161-
$this->checkoutSessionManagement->cancelOrder($order);
160+
$this->checkoutSessionManagement->cancelOrder($order, null, $reasonMessage);
162161
} else {
163162
$this->logger->error(self::LOG_PREFIX . 'Order not found for ID: ' . $orderId);
164163
}

Gateway/Request/SettlementRequestBuilder.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,27 @@ protected function getHeaders($payment)
104104
return $result;
105105
}
106106

107+
/**
108+
* Get charge ID from payment transaction information
109+
*
110+
* @param \Magento\Payment\Model\InfoInterface $payment
111+
* @return string
112+
*/
113+
protected function getChargeId($payment) {
114+
$chargeId = '';
115+
116+
if ($parentTransactionId = $payment->getParentTransactionId()) {
117+
$chargeId = rtrim($parentTransactionId, '-capture');
118+
return $chargeId;
119+
}
120+
121+
if (preg_match('/[A-Z]..-[0-9]*-[0-9]*-C[0-9]*/', $payment->getLastTransId(), $matches)) {
122+
$chargeId = array_shift($matches);
123+
}
124+
125+
return $chargeId;
126+
}
127+
107128
/**
108129
* @inheritdoc
109130
*/
@@ -128,7 +149,7 @@ public function build(array $buildSubject)
128149

129150
$data = [
130151
'store_id' => $storeId,
131-
'charge_id' => rtrim($paymentDO->getPayment()->getParentTransactionId(), '-capture'),
152+
'charge_id' => $this->getChargeId($payment),
132153
'amount' => $total,
133154
'currency_code' => $currencyCode,
134155
];

Helper/Transaction.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
use Amazon\Pay\Gateway\Config\Config;
2020
use Magento\Framework\App\ResourceConnection;
21-
use Magento\Sales\Api\Data\TransactionInterface;
2221
use Magento\Sales\Api\TransactionRepositoryInterface;
2322
use Magento\Sales\Model\Order;
2423

@@ -28,6 +27,9 @@ class Transaction
2827
// Length of time in minutes we wait before cleaning up the transaction
2928
protected const MIN_ORDER_AGE_MINUTES = 30;
3029

30+
// Avoid deprecation warnings with prepared statement
31+
protected const MAX_SQL_PARAM_LENGTH = 5;
32+
3133
/**
3234
* @var int
3335
*/
@@ -143,8 +145,15 @@ public function closeTransaction(mixed $transactionId)
143145
*/
144146
private function getMaxOrderPlacedTime()
145147
{
146-
// phpcs:ignore Magento2.SQL.RawQuery
147-
$query = 'SELECT NOW() - INTERVAL ' . self::MIN_ORDER_AGE_MINUTES . ' MINUTE';
148-
return $this->resourceConnection->getConnection()->fetchOne($query);
148+
$query = $this->resourceConnection->getConnection()
149+
->select()
150+
->getAdapter()
151+
->prepare("SELECT NOW() - INTERVAL :minutes MINUTE");
152+
153+
$minutes = self::MIN_ORDER_AGE_MINUTES;
154+
$query->bindParam(':minutes', $minutes, \PDO::PARAM_INT, self::MAX_SQL_PARAM_LENGTH);
155+
$query->execute();
156+
157+
return $query->fetchColumn(0);
149158
}
150159
}

Model/Adapter/AmazonPayAdapter.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ protected function createPrice($amount, $currencyCode)
160160
*/
161161
public function getCheckoutSession($storeId, $checkoutSessionId)
162162
{
163-
$response = $this->clientFactory->create($storeId)->getCheckoutSession($checkoutSessionId);
163+
$headers = $this->getPlatformHeaders();
164+
$response = $this->clientFactory->create($storeId)->getCheckoutSession($checkoutSessionId, $headers);
164165

165166
return $this->processResponse($response, __FUNCTION__);
166167
}
@@ -201,7 +202,8 @@ public function updateCheckoutSession($quote, $checkoutSessionId, $paymentIntent
201202
'platformId' => $this->amazonConfig->getPlatformId(),
202203
];
203204

204-
$response = $this->clientFactory->create($storeId)->updateCheckoutSession($checkoutSessionId, $payload);
205+
$headers = $this->getPlatformHeaders();
206+
$response = $this->clientFactory->create($storeId)->updateCheckoutSession($checkoutSessionId, $payload, $headers);
205207

206208
return $this->processResponse($response, __FUNCTION__);
207209
}
@@ -215,7 +217,8 @@ public function updateCheckoutSession($quote, $checkoutSessionId, $paymentIntent
215217
*/
216218
public function getCharge($storeId, $chargeId)
217219
{
218-
$response = $this->clientFactory->create($storeId)->getCharge($chargeId);
220+
$headers = $this->getPlatformHeaders();
221+
$response = $this->clientFactory->create($storeId)->getCharge($chargeId, $headers);
219222
return $this->processResponse($response, __FUNCTION__);
220223
}
221224

@@ -232,7 +235,7 @@ public function getCharge($storeId, $chargeId)
232235
*/
233236
public function createCharge($storeId, $chargePermId, $amt, $currency, $captureNow = false, $merchantRefId = null)
234237
{
235-
$headers = $this->getIdempotencyHeader();
238+
$headers = array_merge($this->getIdempotencyHeader(), $this->getPlatformHeaders());
236239

237240
$payload = [
238241
'chargePermissionId' => $chargePermId,
@@ -261,7 +264,7 @@ public function createCharge($storeId, $chargePermId, $amt, $currency, $captureN
261264
*/
262265
public function captureCharge($storeId, $chargeId, $amount, $currency, $headers = [])
263266
{
264-
$headers = array_merge($headers, $this->getIdempotencyHeader());
267+
$headers = array_merge($headers, $this->getIdempotencyHeader(), $this->getPlatformHeaders());
265268

266269
$payload = [
267270
'captureAmount' => $this->createPrice($amount, $currency),
@@ -283,7 +286,7 @@ public function captureCharge($storeId, $chargeId, $amount, $currency, $headers
283286
*/
284287
public function createRefund($storeId, $chargeId, $amount, $currency)
285288
{
286-
$headers = $this->getIdempotencyHeader();
289+
$headers = array_merge($this->getIdempotencyHeader(), $this->getPlatformHeaders());
287290

288291
$payload = [
289292
'chargeId' => $chargeId,
@@ -304,7 +307,8 @@ public function createRefund($storeId, $chargeId, $amount, $currency)
304307
*/
305308
public function getRefund($storeId, $refundId)
306309
{
307-
$response = $this->clientFactory->create($storeId)->getRefund($refundId);
310+
$headers = $this->getPlatformHeaders();
311+
$response = $this->clientFactory->create($storeId)->getRefund($refundId, $headers);
308312
return $this->processResponse($response, __FUNCTION__);
309313
}
310314

@@ -317,7 +321,8 @@ public function getRefund($storeId, $refundId)
317321
*/
318322
public function getChargePermission(int $storeId, string $chargePermissionId)
319323
{
320-
$response = $this->clientFactory->create($storeId)->getChargePermission($chargePermissionId);
324+
$headers = $this->getPlatformHeaders();
325+
$response = $this->clientFactory->create($storeId)->getChargePermission($chargePermissionId, $headers);
321326

322327
return $this->processResponse($response, __FUNCTION__);
323328
}
@@ -355,7 +360,8 @@ public function updateChargePermission(int $storeId, string $chargePermissionId,
355360
$payload['recurringMetadata'] = $data['recurringMetadata'];
356361
}
357362

358-
$response = $this->clientFactory->create($storeId)->updateChargePermission($chargePermissionId, $payload);
363+
$headers = $this->getPlatformHeaders();
364+
$response = $this->clientFactory->create($storeId)->updateChargePermission($chargePermissionId, $payload, $headers);
359365

360366
return $this->processResponse($response, __FUNCTION__);
361367
}
@@ -373,7 +379,8 @@ public function cancelCharge($storeId, $chargeId, $reason = 'ADMIN VOID')
373379
'cancellationReason' => $reason
374380
];
375381

376-
$response = $this->clientFactory->create($storeId)->cancelCharge($chargeId, $payload);
382+
$headers = $this->getPlatformHeaders();
383+
$response = $this->clientFactory->create($storeId)->cancelCharge($chargeId, $payload, $headers);
377384

378385
return $this->processResponse($response, __FUNCTION__);
379386
}
@@ -394,7 +401,8 @@ public function closeChargePermission($storeId, $chargePermissionId, $reason, $c
394401
'cancelPendingCharges' => $cancelPendingCharges,
395402
];
396403

397-
$response = $this->clientFactory->create($storeId)->closeChargePermission($chargePermissionId, $payload);
404+
$headers = $this->getPlatformHeaders();
405+
$response = $this->clientFactory->create($storeId)->closeChargePermission($chargePermissionId, $payload, $headers);
398406

399407
return $this->processResponse($response, __FUNCTION__);
400408
}
@@ -452,9 +460,11 @@ public function completeCheckoutSession($storeId, $sessionId, $amount, $currency
452460
'chargeAmount' => $this->createPrice($amount, $currencyCode),
453461
];
454462

463+
$headers = $this->getPlatformHeaders();
455464
$rawResponse = $this->clientFactory->create($storeId)->completeCheckoutSession(
456465
$sessionId,
457-
json_encode($payload)
466+
json_encode($payload),
467+
$headers
458468
);
459469
return $this->processResponse($rawResponse, __FUNCTION__);
460470
}
@@ -549,6 +559,20 @@ protected function getIdempotencyHeader()
549559
];
550560
}
551561

562+
/**
563+
* Create headers for platform and integration/module version
564+
*
565+
* @return array
566+
*/
567+
protected function getPlatformHeaders()
568+
{
569+
return[
570+
'x-amz-pay-platform-version' => $this->productMetadata->getVersion(),
571+
'x-amz-pay-integrator-version' => $this->amazonHelper->getModuleVersion('Amazon_Pay'),
572+
'x-amz-pay-integrator-id' => $this->amazonConfig->getPlatformId()
573+
];
574+
}
575+
552576
/**
553577
* Generate login static signature for amazon.Pay.renderButton used by checkout.js
554578
*

0 commit comments

Comments
 (0)