Skip to content

Commit

Permalink
Merge pull request #18 from mercadopago/release/1.8.3
Browse files Browse the repository at this point in the history
v.1.8.3
  • Loading branch information
dmsantosd authored Sep 5, 2024
2 parents 2da109a + cf447d2 commit e456d2d
Show file tree
Hide file tree
Showing 37 changed files with 721 additions and 253 deletions.
55 changes: 55 additions & 0 deletions Block/MpDeviceSessionId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace MercadoPago\AdbPayment\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Math\Random;
use Magento\Csp\Model\Collector\DynamicCollector;
use Magento\Csp\Model\Policy\FetchPolicy;

class MpDeviceSessionId extends Template
{
private const NONCE_LENGTH = 32;

private DynamicCollector $dynamicCollector;
private Random $random;

/**
* @param Context $context
* @param DynamicCollector $dynamicCollector
* @param Random $random
* @param array $data
*/
public function __construct(Context $context, DynamicCollector $dynamicCollector, Random $random, array $data = [])
{
parent::__construct($context, $data);

$this->dynamicCollector = $dynamicCollector;
$this->random = $random;
}

public function getNonce(): string
{
$nonce = $this->random->getRandomString(
self::NONCE_LENGTH,
Random::CHARS_DIGITS . Random::CHARS_LOWERS
);

$policy = new FetchPolicy(
'script-src',
false,
[],
[],
false,
false,
false,
[$nonce],
[]
);

$this->dynamicCollector->add($policy);

return base64_encode($nonce);
}
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.8.3] - 2024-09-05
### Changed
- Adjusting the rule used to obtain expired orders and cancel them via Cron
- Separate device fingerprint from SDK + add nonce to load script

### Added
- Added logs to errors with MPClient or SDK requests

## [1.8.2] - 2024-05-27
### Fixed
- Fixed intermittent error when saving payment details
Expand Down
27 changes: 18 additions & 9 deletions Cron/CancelCheckoutCredits.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace MercadoPago\AdbPayment\Cron;

use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
Expand Down Expand Up @@ -41,24 +42,32 @@ class CancelCheckoutCredits extends CancelCheckoutPro
*/
protected $collectionFactory;

/**
* @var ResourceConnection
*/
protected $resource;

/**
* Constructor.
*
* @param Logger $logger
* @param FetchStatus $fetchStatus
* @param ConfigCheckoutPro $configCheckoutPro
* @param CollectionFactory $collectionFactory
* @param ResourceConnection $resource;
*/
public function __construct(
Logger $logger,
FetchStatus $fetchStatus,
ConfigCheckoutCredits $configCheckoutCredits,
CollectionFactory $collectionFactory
CollectionFactory $collectionFactory,
ResourceConnection $resource
) {
$this->logger = $logger;
$this->fetchStatus = $fetchStatus;
$this->configCheckoutCredits = $configCheckoutCredits;
$this->collectionFactory = $collectionFactory;
$this->resource = $resource;
}

/**
Expand All @@ -68,21 +77,21 @@ public function __construct(
*/
public function execute()
{
$expiration = $this->configCheckoutCredits->getExpiredPaymentDate();

$orders = $this->collectionFactory->create()
->addFieldToFilter('state', Order::STATE_NEW)
->addAttributeToFilter('created_at', [
'lteq' => $expiration,
]);
->addFieldToFilter('state', Order::STATE_NEW);

$orders->getSelect()
->join(
['sop' => 'sales_order_payment'],
['sop' => $this->getSalesOrderPaymentTableName()],
'main_table.entity_id = sop.parent_id',
['method']
)
->where('sop.method = ?', ConfigCheckoutCredits::METHOD);
->where(
new \Zend_Db_Expr(
"sop.method = ? AND TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, CAST(JSON_EXTRACT(sop.additional_information, '$.date_of_expiration') AS DATETIME))) >= 0 "
),
ConfigCheckoutCredits::METHOD
);

foreach ($orders as $order) {
$orderId = $order->getEntityId();
Expand Down
45 changes: 31 additions & 14 deletions Cron/CancelCheckoutPro.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright © MercadoPago. All rights reserved.
*
Expand All @@ -8,6 +9,7 @@

namespace MercadoPago\AdbPayment\Cron;

use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
Expand Down Expand Up @@ -39,24 +41,42 @@ class CancelCheckoutPro
*/
protected $collectionFactory;

/**
* @var ResourceConnection
*/
protected $resource;

/**
* Constructor.
*
* @param Logger $logger
* @param FetchStatus $fetchStatus
* @param ConfigCheckoutPro $configCheckoutPro
* @param CollectionFactory $collectionFactory
* @param ResourceConnection $resource;
*/
public function __construct(
Logger $logger,
FetchStatus $fetchStatus,
ConfigCheckoutPro $configCheckoutPro,
CollectionFactory $collectionFactory
CollectionFactory $collectionFactory,
ResourceConnection $resource
) {
$this->logger = $logger;
$this->fetchStatus = $fetchStatus;
$this->configCheckoutPro = $configCheckoutPro;
$this->collectionFactory = $collectionFactory;
$this->resource = $resource;
}

/**
* Get sales_order_payment table name.
*
* @return string
*/
public function getSalesOrderPaymentTableName()
{
return $this->resource->getTableName('sales_order_payment');
}

/**
Expand All @@ -66,21 +86,18 @@ public function __construct(
*/
public function execute()
{
$expiration = $this->configCheckoutPro->getExpiredPaymentDate();

$orders = $this->collectionFactory->create()
->addFieldToFilter('state', Order::STATE_NEW)
->addAttributeToFilter('created_at', [
'lteq' => $expiration,
]);
->addFieldToFilter('state', Order::STATE_NEW);

$orders->getSelect()
->join(
['sop' => 'sales_order_payment'],
'main_table.entity_id = sop.parent_id',
['method']
)
->where('sop.method = ?', ConfigCheckoutPro::METHOD);
->join(
['sop' => $this->getSalesOrderPaymentTableName()],
'main_table.entity_id = sop.parent_id',
['method']
)
->where(new \Zend_Db_Expr(
"sop.method = ? AND TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, CAST(JSON_EXTRACT(sop.additional_information, '$.date_of_expiration') AS DATETIME))) >= 0 "
), ConfigCheckoutPro::METHOD);

foreach ($orders as $order) {
$orderId = $order->getEntityId();
Expand All @@ -100,7 +117,7 @@ public function execute()
$order->cancel();
$order->save();
$this->logger->debug([
'fetch' => 'Cancel Order Id '.$orderId,
'fetch' => 'Cancel Order Id ' . $orderId,
]);
}
}
Expand Down
23 changes: 21 additions & 2 deletions Cron/FetchPaymentMethodsOffOrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MercadoPago\AdbPayment\Cron;

use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
Expand All @@ -28,21 +29,39 @@ class FetchPaymentMethodsOffOrderStatus
*/
protected $collectionFactory;

/**
* @var ResourceConnection
*/
protected $resource;

/**
* Constructor.
*
* @param Logger $logger
* @param FetchStatus $fetchStatus
* @param CollectionFactory $collectionFactory
* @param ResourceConnection $resource;
*/
public function __construct(
Logger $logger,
FetchStatus $fetchStatus,
CollectionFactory $collectionFactory
CollectionFactory $collectionFactory,
ResourceConnection $resource
) {
$this->logger = $logger;
$this->fetchStatus = $fetchStatus;
$this->collectionFactory = $collectionFactory;
$this->resource = $resource;
}

/**
* Get sales_order_payment table name.
*
* @return string
*/
public function getSalesOrderPaymentTableName()
{
return $this->resource->getTableName('sales_order_payment');
}

/**
Expand All @@ -57,7 +76,7 @@ public function execute()

$orders->getSelect()
->join(
['sop' => 'sales_order_payment'],
['sop' => $this->getSalesOrderPaymentTableName()],
'main_table.entity_id = sop.parent_id',
['method']
)
Expand Down
23 changes: 21 additions & 2 deletions Cron/FetchPixOrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace MercadoPago\AdbPayment\Cron;

use Magento\Framework\App\ResourceConnection;
use Magento\Payment\Model\Method\Logger;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
Expand All @@ -34,21 +35,39 @@ class FetchPixOrderStatus
*/
protected $collectionFactory;

/**
* @var ResourceConnection
*/
protected $resource;

/**
* Constructor.
*
* @param Logger $logger
* @param FetchStatus $fetchStatus
* @param CollectionFactory $collectionFactory
* @param ResourceConnection $resource;
*/
public function __construct(
Logger $logger,
FetchStatus $fetchStatus,
CollectionFactory $collectionFactory
CollectionFactory $collectionFactory,
ResourceConnection $resource
) {
$this->logger = $logger;
$this->fetchStatus = $fetchStatus;
$this->collectionFactory = $collectionFactory;
$this->resource = $resource;
}

/**
* Get sales_order_payment table name.
*
* @return string
*/
public function getSalesOrderPaymentTableName()
{
return $this->resource->getTableName('sales_order_payment');
}

/**
Expand All @@ -63,7 +82,7 @@ public function execute()

$orders->getSelect()
->join(
['sop' => 'sales_order_payment'],
['sop' => $this->getSalesOrderPaymentTableName()],
'main_table.entity_id = sop.parent_id',
['method']
)
Expand Down
Loading

0 comments on commit e456d2d

Please sign in to comment.