Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.8.5 #21

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Block/MpDeviceSessionId.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MpDeviceSessionId extends Template

private DynamicCollector $dynamicCollector;
private Random $random;

/**
/**
* @param Context $context
* @param DynamicCollector $dynamicCollector
* @param Random $random
Expand Down
5 changes: 3 additions & 2 deletions Block/Sales/Info/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public function date($date)
* Function getFormatedPrice
*
* @param float $price
* @param bool $includeContainer
*
* @return string
*/
public function getFormatedPrice($amount)
public function getFormatedPrice($amount, $includeContainer = true)
{
return $this->priceCurrency->convertAndFormat($amount);
return $this->priceCurrency->convertAndFormat($amount, $includeContainer);
}
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ 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.5] - 2024-10-30
### Changed
- Adjustments on maximum order amount when payment has financial cost
- Adjustments on partial refund
- Update binary mode default value
- Fixed financial cost amount exhibition on order view and success page with cards payment
- Improved logs on cancel orders with expirated preferences cron
- Updated text for congrats page on MLB "Lotérica" payment

## [1.8.4] - 2024-09-23
### Changed
- Rebranding of Mercado Credits
Expand Down
86 changes: 67 additions & 19 deletions Cron/CancelCheckoutPro.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,80 @@ public function execute()
->join(
['sop' => $this->getSalesOrderPaymentTableName()],
'main_table.entity_id = sop.parent_id',
['method']
['method', 'additional_information']
)
->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();
$amount = $order->getTotalDue();
$baseAmount = $order->getBaseTotalDue();
$payment = $order->getPayment();
$payment->setPreparedMessage(__('Order Canceled.'));
$payment->registerVoidNotification($amount);
$payment->setIsTransactionApproved(false);
$payment->setIsTransactionDenied(true);
$payment->setIsTransactionPending(false);
$payment->setIsInProcess(true);
$payment->setIsTransactionClosed(true);
$payment->setShouldCloseParentTransaction(true);
$payment->setAmountCanceled($amount);
$payment->setBaseAmountCanceled($baseAmount);
$order->cancel();
$order->save();

$this->logger->debug([
'Total orders to cancel: ' => $orders->count()
]);

$dateRange = [];
$orderId = null;

try {
$this->logger->debug([
'Cancel Start'
]);
foreach ($orders as $order) {
$orderAdditionalInformation = json_decode($order->getData('additional_information'));
$orderId = $order->getEntityId();
$amount = $order->getTotalDue();
$baseAmount = $order->getBaseTotalDue();
$payment = $order->getPayment();
$payment->setPreparedMessage(__('Order Canceled.'));
$payment->registerVoidNotification($amount);
$payment->setIsTransactionApproved(false);
$payment->setIsTransactionDenied(true);
$payment->setIsTransactionPending(false);
$payment->setIsInProcess(true);
$payment->setIsTransactionClosed(true);
$payment->setShouldCloseParentTransaction(true);
$payment->setAmountCanceled($amount);
$payment->setBaseAmountCanceled($baseAmount);
$order->cancel();
$order->save();

$dateRange[] = $orderAdditionalInformation->date_of_expiration;
$this->logger->debug([
'fetch' => 'Cancel Order Id ' . $orderId . ' successfully',
'order_date_of_expiration' => $orderAdditionalInformation->date_of_expiration
]);
}

$this->calculateExpirationRange($dateRange);
$this->logger->debug([
'Cancel Finish'
]);

} catch (\Exception $e) {
$this->logger->debug([
'fetch' => 'Cancel Order Id ' . $orderId,
'Cancel order execution error' => $e->getMessage(),
'Order Id' => $orderId
]);
}
}

/**
* Calculate expiration range date
*
* @param array $dateRange
* @return void
*/
private function calculateExpirationRange(array $dateRange): void
{
usort($dateRange, function ($a, $b) {
return strtotime($a) - strtotime($b);
});

$initialDate = reset($dateRange);
$endDate = end($dateRange);

$this->logger->debug([
'Orders expiration range: ' => "from: $initialDate to: $endDate"
]);
}
}
23 changes: 23 additions & 0 deletions Gateway/Config/ConfigCc.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class ConfigCc extends PaymentConfig
*/
public const PAYMENT_ACTION = 'payment_action';

/**
* Maximum Order Amount Total.
*/
public const MAX_ORDER_TOTAL = 'max_order_total';

/**
* @var Config
*/
Expand Down Expand Up @@ -329,4 +334,22 @@ public function getFingerPrintLink($storeId = null): string

return $this->fingerprint->getFingerPrintLink($mpSiteId);
}

/**
* Get Maximum order total
*
* @param int|null $storeId
*
* @return float
*/
public function getMaximumOrderTotal($storeId = null): float
{
$pathPattern = 'payment/%s/%s';

return (float)$this->scopeConfig->getValue(
sprintf($pathPattern, self::METHOD, self::MAX_ORDER_TOTAL),
ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
23 changes: 23 additions & 0 deletions Gateway/Config/ConfigCheckoutCredits.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class ConfigCheckoutCredits extends ConfigPro
*/
public const METHOD = 'mercadopago_adbpayment_checkout_credits';

/**
* Maximum Order Amount Total.
*/
public const MAX_ORDER_TOTAL = 'max_order_total';

/**
* @param ScopeConfigInterface $scopeConfig
* @param DateTime $date
Expand Down Expand Up @@ -58,4 +63,22 @@ public function getBannerText($textId, $storeId = null): string
$storeId
);
}

/**
* Get Maximum order total
*
* @param int|null $storeId
*
* @return float
*/
public function getMaximumOrderTotal($storeId = null): float
{
$pathPattern = 'payment/%s/%s';

return (float)$this->scopeConfig->getValue(
sprintf($pathPattern, self::METHOD, self::MAX_ORDER_TOTAL),
ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
22 changes: 22 additions & 0 deletions Gateway/Config/ConfigTwoCc.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class ConfigTwoCc extends PaymentConfig
*/
public const PAYMENT_ACTION = 'payment_action';

/**
* Maximum Order Amount Total.
*/
public const MAX_ORDER_TOTAL = 'max_order_total';

/**
* @var Config
*/
Expand Down Expand Up @@ -330,4 +335,21 @@ public function getFingerPrintLink($storeId = null): string
return $this->fingerprint->getFingerPrintLink($mpSiteId);
}

/**
* Get Maximum order total
*
* @param int|null $storeId
*
* @return float
*/
public function getMaximumOrderTotal($storeId = null): float
{
$pathPattern = 'payment/%s/%s';

return (float)$this->scopeConfig->getValue(
sprintf($pathPattern, self::METHOD, self::MAX_ORDER_TOTAL),
ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
6 changes: 3 additions & 3 deletions Gateway/Http/Client/CreateOrderPaymentCustomClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ public function placeRequest(TransferInterface $transferObject)
unset($request[CaptureAmountRequest::AMOUNT_TO_CAPTURE]);

$paymentInstance->setEntity($request);


if(isset($paymentInstance->payer->id)) {
$customHeaders[] = self::HEADER_CUSTOMER_ID . $paymentInstance->payer->id;
}

$paymentInstance->setCustomHeaders($customHeaders);

$clientHeaders = $paymentInstance->getLastHeaders();
Expand Down Expand Up @@ -313,4 +313,4 @@ public function placeRequest(TransferInterface $transferObject)

return $response;
}
}
}
5 changes: 5 additions & 0 deletions Gateway/Response/TxnIdPaymentMethodsOffHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ public function setAddtionalInformationMLB($payment, $response) {
self::MESSAGE_DOCUMENT,
'Enter the ID Document you used in the purchase'
);

$payment->setAdditionalInformation(
self::MESSAGE_INFO,
'To pay, please go to any lotérica or "Correspondente Caixa" branch. You will need the following code and the ID number used in the purchase.'
);
}
}
}
4 changes: 2 additions & 2 deletions Model/Adminhtml/Source/IsBinaryMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public function toOptionArray(): array
return [
[
'value' => 0,
'label' => __('Yes, Processed Order Synchronous'),
'label' => __('No, Processed Order Asynchronous'),
],
[
'value' => 1,
'label' => __('No, Processed Order Asynchronous'),
'label' => __('Yes, Processed Order Synchronous'),
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/FinanceCostManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FinanceCostManagement implements FinanceCostManagementInterface
* @var MpConfig
*/
protected $mpConfig;

/**
* @var Logger
*/
Expand Down
6 changes: 5 additions & 1 deletion Model/Notification/Refund/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ private function refund(RefundData $refundData): array
$payment->setTransactionId($refundData->getId());
$payment->setIsTransactionClosed(true);

if ($refundData->getAmount() < $creditMemo->getBaseGrandTotal()) {
$refundBalance = $this->order->getTotalPaid() - $this->order->getTotalRefunded();

if ($refundData->getAmount() < $creditMemo->getBaseGrandTotal() &&
$refundData->getAmount() < $refundBalance
) {
$creditMemo->setItems([]);
}

Expand Down
4 changes: 2 additions & 2 deletions Model/Ui/ConfigProviderCheckoutCredits.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function isActive()

/**
* Get images for payment method banner.
*
*
* @return array
*/
public function getImages()
Expand All @@ -197,7 +197,7 @@ public function getImages()

/**
* Get images for payment method banner.
*
*
* @return array
*/
public function getImagesByName($name)
Expand Down
Loading
Loading