Skip to content

Commit e456d2d

Browse files
authored
Merge pull request #18 from mercadopago/release/1.8.3
v.1.8.3
2 parents 2da109a + cf447d2 commit e456d2d

37 files changed

+721
-253
lines changed

Block/MpDeviceSessionId.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace MercadoPago\AdbPayment\Block;
4+
5+
use Magento\Framework\View\Element\Template;
6+
use Magento\Framework\View\Element\Template\Context;
7+
use Magento\Framework\Math\Random;
8+
use Magento\Csp\Model\Collector\DynamicCollector;
9+
use Magento\Csp\Model\Policy\FetchPolicy;
10+
11+
class MpDeviceSessionId extends Template
12+
{
13+
private const NONCE_LENGTH = 32;
14+
15+
private DynamicCollector $dynamicCollector;
16+
private Random $random;
17+
18+
/**
19+
* @param Context $context
20+
* @param DynamicCollector $dynamicCollector
21+
* @param Random $random
22+
* @param array $data
23+
*/
24+
public function __construct(Context $context, DynamicCollector $dynamicCollector, Random $random, array $data = [])
25+
{
26+
parent::__construct($context, $data);
27+
28+
$this->dynamicCollector = $dynamicCollector;
29+
$this->random = $random;
30+
}
31+
32+
public function getNonce(): string
33+
{
34+
$nonce = $this->random->getRandomString(
35+
self::NONCE_LENGTH,
36+
Random::CHARS_DIGITS . Random::CHARS_LOWERS
37+
);
38+
39+
$policy = new FetchPolicy(
40+
'script-src',
41+
false,
42+
[],
43+
[],
44+
false,
45+
false,
46+
false,
47+
[$nonce],
48+
[]
49+
);
50+
51+
$this->dynamicCollector->add($policy);
52+
53+
return base64_encode($nonce);
54+
}
55+
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.8.3] - 2024-09-05
9+
### Changed
10+
- Adjusting the rule used to obtain expired orders and cancel them via Cron
11+
- Separate device fingerprint from SDK + add nonce to load script
12+
13+
### Added
14+
- Added logs to errors with MPClient or SDK requests
15+
816
## [1.8.2] - 2024-05-27
917
### Fixed
1018
- Fixed intermittent error when saving payment details

Cron/CancelCheckoutCredits.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace MercadoPago\AdbPayment\Cron;
1111

12+
use Magento\Framework\App\ResourceConnection;
1213
use Magento\Payment\Model\Method\Logger;
1314
use Magento\Sales\Model\Order;
1415
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
@@ -41,24 +42,32 @@ class CancelCheckoutCredits extends CancelCheckoutPro
4142
*/
4243
protected $collectionFactory;
4344

45+
/**
46+
* @var ResourceConnection
47+
*/
48+
protected $resource;
49+
4450
/**
4551
* Constructor.
4652
*
4753
* @param Logger $logger
4854
* @param FetchStatus $fetchStatus
4955
* @param ConfigCheckoutPro $configCheckoutPro
5056
* @param CollectionFactory $collectionFactory
57+
* @param ResourceConnection $resource;
5158
*/
5259
public function __construct(
5360
Logger $logger,
5461
FetchStatus $fetchStatus,
5562
ConfigCheckoutCredits $configCheckoutCredits,
56-
CollectionFactory $collectionFactory
63+
CollectionFactory $collectionFactory,
64+
ResourceConnection $resource
5765
) {
5866
$this->logger = $logger;
5967
$this->fetchStatus = $fetchStatus;
6068
$this->configCheckoutCredits = $configCheckoutCredits;
6169
$this->collectionFactory = $collectionFactory;
70+
$this->resource = $resource;
6271
}
6372

6473
/**
@@ -68,21 +77,21 @@ public function __construct(
6877
*/
6978
public function execute()
7079
{
71-
$expiration = $this->configCheckoutCredits->getExpiredPaymentDate();
72-
7380
$orders = $this->collectionFactory->create()
74-
->addFieldToFilter('state', Order::STATE_NEW)
75-
->addAttributeToFilter('created_at', [
76-
'lteq' => $expiration,
77-
]);
81+
->addFieldToFilter('state', Order::STATE_NEW);
7882

7983
$orders->getSelect()
8084
->join(
81-
['sop' => 'sales_order_payment'],
85+
['sop' => $this->getSalesOrderPaymentTableName()],
8286
'main_table.entity_id = sop.parent_id',
8387
['method']
8488
)
85-
->where('sop.method = ?', ConfigCheckoutCredits::METHOD);
89+
->where(
90+
new \Zend_Db_Expr(
91+
"sop.method = ? AND TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, CAST(JSON_EXTRACT(sop.additional_information, '$.date_of_expiration') AS DATETIME))) >= 0 "
92+
),
93+
ConfigCheckoutCredits::METHOD
94+
);
8695

8796
foreach ($orders as $order) {
8897
$orderId = $order->getEntityId();

Cron/CancelCheckoutPro.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright © MercadoPago. All rights reserved.
45
*
@@ -8,6 +9,7 @@
89

910
namespace MercadoPago\AdbPayment\Cron;
1011

12+
use Magento\Framework\App\ResourceConnection;
1113
use Magento\Payment\Model\Method\Logger;
1214
use Magento\Sales\Model\Order;
1315
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
@@ -39,24 +41,42 @@ class CancelCheckoutPro
3941
*/
4042
protected $collectionFactory;
4143

44+
/**
45+
* @var ResourceConnection
46+
*/
47+
protected $resource;
48+
4249
/**
4350
* Constructor.
4451
*
4552
* @param Logger $logger
4653
* @param FetchStatus $fetchStatus
4754
* @param ConfigCheckoutPro $configCheckoutPro
4855
* @param CollectionFactory $collectionFactory
56+
* @param ResourceConnection $resource;
4957
*/
5058
public function __construct(
5159
Logger $logger,
5260
FetchStatus $fetchStatus,
5361
ConfigCheckoutPro $configCheckoutPro,
54-
CollectionFactory $collectionFactory
62+
CollectionFactory $collectionFactory,
63+
ResourceConnection $resource
5564
) {
5665
$this->logger = $logger;
5766
$this->fetchStatus = $fetchStatus;
5867
$this->configCheckoutPro = $configCheckoutPro;
5968
$this->collectionFactory = $collectionFactory;
69+
$this->resource = $resource;
70+
}
71+
72+
/**
73+
* Get sales_order_payment table name.
74+
*
75+
* @return string
76+
*/
77+
public function getSalesOrderPaymentTableName()
78+
{
79+
return $this->resource->getTableName('sales_order_payment');
6080
}
6181

6282
/**
@@ -66,21 +86,18 @@ public function __construct(
6686
*/
6787
public function execute()
6888
{
69-
$expiration = $this->configCheckoutPro->getExpiredPaymentDate();
70-
7189
$orders = $this->collectionFactory->create()
72-
->addFieldToFilter('state', Order::STATE_NEW)
73-
->addAttributeToFilter('created_at', [
74-
'lteq' => $expiration,
75-
]);
90+
->addFieldToFilter('state', Order::STATE_NEW);
7691

7792
$orders->getSelect()
78-
->join(
79-
['sop' => 'sales_order_payment'],
80-
'main_table.entity_id = sop.parent_id',
81-
['method']
82-
)
83-
->where('sop.method = ?', ConfigCheckoutPro::METHOD);
93+
->join(
94+
['sop' => $this->getSalesOrderPaymentTableName()],
95+
'main_table.entity_id = sop.parent_id',
96+
['method']
97+
)
98+
->where(new \Zend_Db_Expr(
99+
"sop.method = ? AND TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, CAST(JSON_EXTRACT(sop.additional_information, '$.date_of_expiration') AS DATETIME))) >= 0 "
100+
), ConfigCheckoutPro::METHOD);
84101

85102
foreach ($orders as $order) {
86103
$orderId = $order->getEntityId();
@@ -100,7 +117,7 @@ public function execute()
100117
$order->cancel();
101118
$order->save();
102119
$this->logger->debug([
103-
'fetch' => 'Cancel Order Id '.$orderId,
120+
'fetch' => 'Cancel Order Id ' . $orderId,
104121
]);
105122
}
106123
}

Cron/FetchPaymentMethodsOffOrderStatus.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MercadoPago\AdbPayment\Cron;
44

5+
use Magento\Framework\App\ResourceConnection;
56
use Magento\Payment\Model\Method\Logger;
67
use Magento\Sales\Model\Order;
78
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
@@ -28,21 +29,39 @@ class FetchPaymentMethodsOffOrderStatus
2829
*/
2930
protected $collectionFactory;
3031

32+
/**
33+
* @var ResourceConnection
34+
*/
35+
protected $resource;
36+
3137
/**
3238
* Constructor.
3339
*
3440
* @param Logger $logger
3541
* @param FetchStatus $fetchStatus
3642
* @param CollectionFactory $collectionFactory
43+
* @param ResourceConnection $resource;
3744
*/
3845
public function __construct(
3946
Logger $logger,
4047
FetchStatus $fetchStatus,
41-
CollectionFactory $collectionFactory
48+
CollectionFactory $collectionFactory,
49+
ResourceConnection $resource
4250
) {
4351
$this->logger = $logger;
4452
$this->fetchStatus = $fetchStatus;
4553
$this->collectionFactory = $collectionFactory;
54+
$this->resource = $resource;
55+
}
56+
57+
/**
58+
* Get sales_order_payment table name.
59+
*
60+
* @return string
61+
*/
62+
public function getSalesOrderPaymentTableName()
63+
{
64+
return $this->resource->getTableName('sales_order_payment');
4665
}
4766

4867
/**
@@ -57,7 +76,7 @@ public function execute()
5776

5877
$orders->getSelect()
5978
->join(
60-
['sop' => 'sales_order_payment'],
79+
['sop' => $this->getSalesOrderPaymentTableName()],
6180
'main_table.entity_id = sop.parent_id',
6281
['method']
6382
)

Cron/FetchPixOrderStatus.php

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

99
namespace MercadoPago\AdbPayment\Cron;
1010

11+
use Magento\Framework\App\ResourceConnection;
1112
use Magento\Payment\Model\Method\Logger;
1213
use Magento\Sales\Model\Order;
1314
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
@@ -34,21 +35,39 @@ class FetchPixOrderStatus
3435
*/
3536
protected $collectionFactory;
3637

38+
/**
39+
* @var ResourceConnection
40+
*/
41+
protected $resource;
42+
3743
/**
3844
* Constructor.
3945
*
4046
* @param Logger $logger
4147
* @param FetchStatus $fetchStatus
4248
* @param CollectionFactory $collectionFactory
49+
* @param ResourceConnection $resource;
4350
*/
4451
public function __construct(
4552
Logger $logger,
4653
FetchStatus $fetchStatus,
47-
CollectionFactory $collectionFactory
54+
CollectionFactory $collectionFactory,
55+
ResourceConnection $resource
4856
) {
4957
$this->logger = $logger;
5058
$this->fetchStatus = $fetchStatus;
5159
$this->collectionFactory = $collectionFactory;
60+
$this->resource = $resource;
61+
}
62+
63+
/**
64+
* Get sales_order_payment table name.
65+
*
66+
* @return string
67+
*/
68+
public function getSalesOrderPaymentTableName()
69+
{
70+
return $this->resource->getTableName('sales_order_payment');
5271
}
5372

5473
/**
@@ -63,7 +82,7 @@ public function execute()
6382

6483
$orders->getSelect()
6584
->join(
66-
['sop' => 'sales_order_payment'],
85+
['sop' => $this->getSalesOrderPaymentTableName()],
6786
'main_table.entity_id = sop.parent_id',
6887
['method']
6988
)

0 commit comments

Comments
 (0)