Skip to content

Commit

Permalink
Merge pull request #253 from PluginAndPartners/release/prestashop-4.11.3
Browse files Browse the repository at this point in the history
Release/prestashop 4.11.3
  • Loading branch information
AlberAlmeida authored Oct 11, 2022
2 parents 3528072 + 989f1b8 commit 4abd9d5
Show file tree
Hide file tree
Showing 29 changed files with 1,265 additions and 1,038 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## 📝 Description

> A description of the PR, usually this description is the same as the JIRA story/task.
> [#PSW-1234](jira.link.com)
## 🎯 Goals

> What and how the task were done.
> If applicable, a list of:
> - [ ] what need to do
> - [x] what it is doing
> - [x] and what was done
## 📸 Screenshots

> - Before and after, if is a fix
> - New screens of new features
> - Changes in all resolutions
## 🧰 How to reproduce

> - Step by step of how to test
> - What scopes need to be activated
> - External docs links
<!-- Optional items
## 🔗 Links
> - [link1.com](https://)
> - [link2.com](https://)
## 🔀 Related PRs
> - #123
> - #321
-->
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ 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).

## [4.11.3] - 2022-30-09

### Fixed
- Fixed php notice on order creation

- Error log changed to information log in notifications

- Removed tags used for translation and adapted related HTML tags

- Changed Json encode/decode functions from Tools to native functions

- Updated Tools::redirectLink to Tools::redirect

- Added validation for null, empty or invalid merchant_order_id

## [4.11.2] - 2022-16-08

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</a>
</p>

# Prestashop 1.6.x & 1.7.x - Mercado Pago Module (v4.11.2)
# Prestashop 1.6.x & 1.7.x - Mercado Pago Module (v4.11.3)

With the official module of Mercado Pago you will have an integration, hundreds of solutions and thousands of sales. Maximize your conversions and make your customers return to your store by increasing their confidence in the shopping experience.

Expand Down
2 changes: 1 addition & 1 deletion controllers/front/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function processWebhookNotification($transaction_id, $secure_key)
*/
public function getErrorResponse()
{
MPLog::generate('The notification does not have the necessary parameters to create an order', 'error');
MPLog::generate('The notification does not have the necessary parameters to create an order');
WebhookNotification::getNotificationResponse(
'The notification does not have the necessary parameters',
200
Expand Down
6 changes: 3 additions & 3 deletions controllers/front/standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function initContent()
$this->standardModalCheckout($preference);
}

Tools::redirectLink($createPreference['init_point']);
Tools::redirect($createPreference['init_point']);
}

$this->redirectError($preference, Tools::displayError());
Expand Down Expand Up @@ -115,7 +115,7 @@ public function standardModalCheckout($preference)
{
$backUrl = Tools::getValue('back_url');
if (isset($backUrl)) {
Tools::redirectLink($backUrl);
Tools::redirect($backUrl);
}

$preference->redirectError();
Expand All @@ -135,7 +135,7 @@ public function getResponse($preference, $code)
'preference' => $preference,
);

echo Tools::jsonEncode($response);
echo json_encode($response);
http_response_code($code);
exit();
}
Expand Down
22 changes: 16 additions & 6 deletions controllers/front/standardvalidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,30 @@ public function initContent()
$payment_ids = Tools::getValue('collection_id');
$cartId = Tools::getValue('cart_id');


if (isset($payment_ids) && $payment_ids != false && $payment_ids != 'null' && $typeReturn != 'failure') {
$payment_id = explode(',', $payment_ids)[0];
$this->redirectCheck($payment_id);

return;
}

if (isset($cartId)) {
if (isset($cartId) && $typeReturn != 'failure') {
$order = $this->mp_transaction->where('cart_id', '=', $cartId)->get();
$merchant = $this->mercadopago->getMerchantOrder($order['merchant_order_id']);
$payment_id = $merchant['payments'][0]['id'];
$merchant_order_id = $order['merchant_order_id'];

if ($merchant_order_id || $merchant_order_id === '0') {
$merchant_order = $this->mercadopago->getMerchantOrder($order['merchant_order_id']);
$payment_id = $merchant_order['payments'][0]['id'];

$this->redirectCheck($payment_id);
} else {
$this->redirectError();
}

$this->redirectCheck($payment_id);
return;
}

$this->redirectError();
}

/**
Expand All @@ -85,6 +94,7 @@ public function redirectCheck($payment_id)

$this->redirectOrderConfirmation($cart, $order);
}

$this->redirectError();
}

Expand Down Expand Up @@ -123,7 +133,7 @@ public function redirectOrderConfirmation($cart, $order)
$url .= '&id_order=' . $order->id;
$url .= '&id_module=' . $this->module->id;

return Tools::redirectLink($url);
return Tools::redirect($url);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/walletbutton.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getResponse($preference, $code)
'preference' => $preference,
);

echo Tools::jsonEncode($response);
echo json_encode($response);
http_response_code($code);
exit();
}
Expand Down
6 changes: 3 additions & 3 deletions includes/MPRestCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private static function setData($connect, $data, $content_type)
{
if ($content_type == 'application/json') {
if (gettype($data) == 'string') {
Tools::jsonDecode($data, true);
json_decode($data, true);
} else {
$data = Tools::jsonEncode($data);
$data = json_encode($data);
}

if (function_exists('json_last_error')) {
Expand Down Expand Up @@ -118,7 +118,7 @@ private static function exec($method, $uri, $data, $headers, $uri_base)
$api_http_code = curl_getinfo($connect, CURLINFO_HTTP_CODE);
$response = array(
'status' => $api_http_code,
'response' => Tools::jsonDecode($api_result, true),
'response' => json_decode($api_result, true),
);

curl_close($connect);
Expand Down
43 changes: 26 additions & 17 deletions includes/module/notification/AbstractNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,25 +381,15 @@ public function updatePrestashopOrder($cart, $order)
*/
public function saveCreateOrderData($cart)
{
$payments_id = is_array($this->payments_data['payments_id'])
? implode(',', $this->payments_data['payments_id'])
: $this->payments_data['payments_id'];
$payments_id = $this->verifyValue('payments_id');

$payments_type = is_array($this->payments_data['payments_type'])
? implode(',', $this->payments_data['payments_type'])
: $this->payments_data['payments_type'];
$payments_type = $this->verifyValue('payments_type');

$payments_method = is_array($this->payments_data['payments_method'])
? implode(',', $this->payments_data['payments_method'])
: $this->payments_data['payments_method'];
$payments_method = $this->verifyValue('payments_method');

$payments_status = is_array($this->payments_data['payments_status'])
? implode(',', $this->payments_data['payments_status'])
: $this->payments_data['payments_status'];
$payments_status = $this->verifyValue('payments_status');

$payments_amount = is_array($this->payments_data['payments_amount'])
? implode(',', $this->payments_data['payments_amount'])
: $this->payments_data['payments_amount'];
$payments_amount = $this->verifyValue('payments_amount');

$dataToCreate = [
"order_id" => $this->order_id,
Expand Down Expand Up @@ -531,7 +521,7 @@ public static function getNotificationResponse($message, $code)
"version" => MP_VERSION
);

echo Tools::jsonEncode($response);
echo json_encode($response);
return http_response_code($code);
}

Expand Down Expand Up @@ -570,7 +560,26 @@ public function generateLogs()
"order_state" => $this->order_state,
];

$encodedLogs = Tools::jsonEncode($logs);
$encodedLogs = json_encode($logs);
MPLog::generate('Order id ' . $this->order_id . ' notification logs: ' . $encodedLogs);
}

/**
* Verify value
*
* @param string $method
* @return string
*/
public function verifyValue($key)
{
if (!isset($this->payments_data[$key])) {
return null;
}

if (is_array($this->payments_data[$key])) {
return implode(',', $this->payments_data[$key]);
}

return $this->payments_data[$key];
}
}
2 changes: 1 addition & 1 deletion includes/module/preference/AbstractPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public function generateLogs($preference, $checkout)
"metadata" => array_diff_key($preference['metadata'], array_flip(['collector'])),
];

$encodedLogs = Tools::jsonEncode($logs);
$encodedLogs = json_encode($logs);
MPLog::generate($checkout . ' preference logs: ' . $encodedLogs);
}

Expand Down
2 changes: 1 addition & 1 deletion includes/module/preference/CustomPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function createPreference($cart, $custom_info)

//Generate preference
$this->generateLogs($preference, 'custom');
$preferenceEncoded = Tools::jsonEncode($preference);
$preferenceEncoded = json_encode($preference);

//Create preference
$createPreference = $this->mercadopago->createPayment($preferenceEncoded);
Expand Down
2 changes: 1 addition & 1 deletion includes/module/preference/PixPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function createPreference()
$payload['transaction_amount'] = $this->getAmount();

$this->generateLogs($payload, 'pix');
$payloadToJson = Tools::jsonEncode($payload);
$payloadToJson = json_encode($payload);

$createPreference = $this->mercadopago->createPayment($payloadToJson);
MPLog::generate('Cart ID ' . $this->cart->id . ' - Pix Preference created successfully');
Expand Down
6 changes: 3 additions & 3 deletions includes/module/preference/StandardPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function createPreference($cart)
$payload = $this->buildPreferencePayload($cart);

$this->generateLogs($payload, $cart);
$payloadToJson = Tools::jsonEncode($payload);
$payloadToJson = json_encode($payload);

$createPreference = $this->mercadopago->createPreference($payloadToJson);
MPLog::generate('Cart id ' . $cart->id . ' - Standard Preference created successfully');
Expand Down Expand Up @@ -82,7 +82,7 @@ public function buildPreferencePayload($cart, $discount = 0)
public function getInternalMetadata($cart)
{
$internalMetadataParent = parent::getInternalMetadata($cart);

$checkoutType = $this->settings['MERCADOPAGO_STANDARD_MODAL'] ? 'modal' : 'redirect';

$internalMetadataAdditional = array(
Expand All @@ -109,7 +109,7 @@ public function generateLogs($preference, $cart)
"metadata" => array_diff_key($preference['metadata'], array_flip(['collector'])),
);

$encodedLogs = Tools::jsonEncode($logs);
$encodedLogs = json_encode($logs);
MPLog::generate('standard preference logs: ' . $encodedLogs);
}
}
2 changes: 1 addition & 1 deletion includes/module/preference/TicketPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function createPreference($cart, $ticket_info)

//Generate preference
$this->generateLogs($preference, 'ticket');
$preferenceEncoded = Tools::jsonEncode($preference);
$preferenceEncoded = json_encode($preference);

//Create preference
$createPreference = $this->mercadopago->createPayment($preferenceEncoded);
Expand Down
4 changes: 2 additions & 2 deletions includes/module/preference/WalletButtonPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function createPreference($cart)
$payload = $this->buildPreferencePayload($cart, Configuration::get('MERCADOPAGO_CUSTOM_DISCOUNT'));

$this->generateLogs($payload, $cart);
$payloadToJson = Tools::jsonEncode($payload);
$payloadToJson = json_encode($payload);

$createPreference = $this->mercadopago->createPreference($payloadToJson);
MPLog::generate('Cart id ' . $cart->id . ' - Wallet Button Preference created successfully');
Expand Down Expand Up @@ -146,7 +146,7 @@ public function generateLogs($preference, $cart)
"metadata" => array_diff_key($preference['metadata'], array_flip(['collector'])),
);

$encodedLogs = Tools::jsonEncode($logs);
$encodedLogs = json_encode($logs);
MPLog::generate('wallet button preference logs: ' . $encodedLogs);
}
}
4 changes: 2 additions & 2 deletions mercadopago.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* International Registered Trademark & Property of MercadoPago
*/

define('MP_VERSION', '4.11.2');
define('MP_VERSION', '4.11.3');
define('MP_ROOT_URL', dirname(__FILE__));

if (!defined('_PS_VERSION_')) {
Expand Down Expand Up @@ -73,7 +73,7 @@ public function __construct()
$this->bootstrap = true;

//Always update, because prestashop doesn't accept version coming from another variable (MP_VERSION)
$this->version = '4.11.2';
$this->version = '4.11.3';
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);

parent::__construct();
Expand Down
Loading

0 comments on commit 4abd9d5

Please sign in to comment.