Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
v3.15.0 🚀🚀🚀 (#191)
Browse files Browse the repository at this point in the history
* feat(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* fix(PPWP-377): unified calls

* added payment places method

* comments removed

* refactored access token validation

* fixed ternary if structure

* fixed instantiation of access token

* 🐛 Fix the PR cover checker when there is no test (#189)

This fixes an issue that is workflow failure when the pull request does not contain tests and Added hotfix branch filter to check tests

* feat(PPWP-421): paycash front-end

* feat(PPWP-422): paycash admin

* fix(helper): 🐛 fixed float to int convertion

* feat(bin): ✨ new command sync with container

* improv: init tests

* improv: changing chmod command

* build: 📦 new patch version of mercardo pago for magento 2 v3.12.3

* getMercadoPagoPaymentMethods testing

* fix(ppwp-337): fixing exception testing

* testing config provider and api

* testing PaymentMethodsTicket

* feat(ppwp-377): testing custom config provider

* refactored constants

* refactored model test classes

* refactored helper test classes

* added annotation for Code Coverage Ignore

* fixed test variables

* fixed html structure of ticket

* feat(ppwp-377): adding metadata payment_option_id

* fixing data tests

* removed exception to access token

* hotfix(PLUG-1533): fixing refund error handling

* fixing pr coverage checker

* testing pr coverage checker

* fixing pr coverage checker

* hotfix: fixed js - undefined variable

* feat(PPWP-569): initial commit

* build: 📦 new minor version of mercardo pago for magento 2 v3.13.0

* build(v3.13.0): 📦 updated readme

* expiration date mask and validations

* PPWP-569: inserted translations for titles

* PPWP-569: added space between fields

* improv(PPWP-611): dinamically validating bank transfer on admin page

* implementing cache

* PPWP-611: payment unit tests

* PPWP-611: fixed abstractElementMock

* fix(wallet button): 🐛 create order even with cho pro disabled

* fixing cache

* separating cache values with constants

* PPWP-611: refactored test directory

* PPWP-570: added translation

* PPWP-569: inserted style in title

* PPWP-569: fixed cache for new installs

* PPWP-569: fixed cache for new installs

* feature(ppwp-630): new front-end definitions

* removing cache from bank_transfer validation

* fixing payment fieldset and removing debit text

* Update ConfigObserver.php (#183)

Changing protocol for banners to use https

* Fix refund: cuando el response de la API de MP es un {status:400,response:{error:bad_request,status:400}}, no se tiene que generar el creditmemo (#180)

Co-authored-by: Fernando Lira <[email protected]>

* improv(ppwp-531): adding mlu to available lists

* adding payment methods validation using API

* removing old validation

* improving cache and applying rules to other checkouts

* fixing pix rules

* disabling invalid payments

* clearing config activation flag caching

* testing new methods

* fixing cache code coverage

* fixing observer code coverage

* fixing exception syntax

* code enhancement

* fixing prefix issue

* fix(ticket): 🐛 changed str_contains to strpos

* build(v3.14.0): 📦 updated version files and changelog

* build(v3.14.0): 📦 updated changelog

* fix: treating paymentId on disablePayment function

* Upgrade New Logo MP Magento 2

* hotfix: prevent "missing required argument $data" exception (#187)

Co-authored-by: Ivan Augusto <[email protected]>

* build(v3.14.1): 📦 new version v3.14.1

* build(v3.14.1): 📦 updated mercado pago's minilogo image

* build(v3.14.2): 📦 Create a new version

* build(v3.14.2): 📦 Migrate to db_schema

* build(v3.14.2): 📦 link img desktop logo mercado pago

* build(v3.14.2): 📦 add release to skipped branch

* build(v3.14.2): 📦 add parameters :P

* hotfix(PLUG-1713): treating invalid credentials

* changing test files

* set observers as no has converage

* Adjusted logos from checkouts (#219)

* build(v3.14.1): 📦 new version v3.14.1

* build(v3.14.1): 📦 updated mercado pago's minilogo image

* build(v3.14.2): 📦 Create a new version

* build(v3.14.2): 📦 Migrate to db_schema

* build(v3.14.2): 📦 link img desktop logo mercado pago

* build(v3.14.2): 📦 add release to skipped branch

* build(v3.14.2): 📦 add parameters :P

* feat: update logos from cho pro

* feat: update logos from cho ticket

* feat: update logos from cho custom

* feat: fix credit card js

* fix: fixed create payments with issuer

Co-authored-by: Fernando Lira <[email protected]>
Co-authored-by: Fernando Lira <[email protected]>

* Fixed sending email for new order in pending status

* Changed position of additional information method

* Code centered in only one method

* hotfix: link ticket options labels to they checkboxes (#190)

Co-authored-by: Ivan Augusto <[email protected]>
Co-authored-by: Fernando Lira <[email protected]>

* Added cvv validation for cho custom (#222)

* feat: added cvv validation for cho custom

* feat: added cvv validation for cho custom

* Fixed some accentuation in pt_BR translations

* feat: cho ticket logo adjustments (#223)

* Fixed some other accentuation in pt_BR translations and 'partually' in label

* Fixed title text

* Fixed text

* Returning removed text pt-br (número)

* build(v3.15.0): 📦 new version

Co-authored-by: Gustavo Brito <[email protected]>
Co-authored-by: sleaof <[email protected]>
Co-authored-by: Douglas <[email protected]>
Co-authored-by: Manuel Eduardo Cánepa Cihuelo <[email protected]>
Co-authored-by: lc-mayoul <[email protected]>
Co-authored-by: hugodamm <[email protected]>
Co-authored-by: Code Slicer <[email protected]>
Co-authored-by: Ivan Augusto <[email protected]>
Co-authored-by: Hugo Damm <[email protected]>
Co-authored-by: Giovanni Cavallari <[email protected]>
Co-authored-by: katelucena-meli <[email protected]>
Co-authored-by: AlberAlmeida <[email protected]>
  • Loading branch information
13 people authored Mar 22, 2022
1 parent e79af20 commit 0b5d4e0
Show file tree
Hide file tree
Showing 29 changed files with 354 additions and 133 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ 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).

## [3.15.0] - 2022-03-21

### Fixed
- Checkout payment's logos changed
- Send mail to pending payments orders to CHO API and CHO PRO (new implementation)
- Credit card payments with issuers fixed
- Invalid credentials flow fixed
- Community PR's with same features
- Fixed CVV validation

## [3.14.2] - 2022-01-26

### 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>

# Magento 2 - Mercado Pago Module (v3.14.2)
# Magento 2 - Mercado Pago Module (v3.15.0)

The Mercado Pago plugin for Magento 2 allows you to expand the functionalities of your online store and offer a unique payment experience for your customers.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"type": "magento2-module",
"version": "3.14.2",
"version": "3.15.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ public function render(AbstractElement $element)
return parent::render($element);
}

public function getPaymentMethods()
public function getPaymentMethods($accessToken)
{
$accessToken = $this->coreHelper->getAccessToken();

$paymentMethods = $this->coreHelper->getMercadoPagoPaymentMethods($accessToken);

return $paymentMethods;
Expand Down Expand Up @@ -177,14 +175,16 @@ protected function disablePayment($paymentId)
*/
protected function hideInvalidCheckoutOptions($paymentId)
{
if (!$this->coreHelper->getAccessToken()) {
$accessToken = $this->coreHelper->getAccessToken();

if (!$this->coreHelper->isValidAccessToken($accessToken)) {
return true;
}

$cacheKey = Cache::VALID_PAYMENT_METHODS;
$validCheckoutOptions = json_decode($this->cache->getFromCache($cacheKey));
if (!$validCheckoutOptions) {
$validCheckoutOptions = $this->getAvailableCheckoutOptions();
$validCheckoutOptions = $this->getAvailableCheckoutOptions($accessToken);
$this->cache->saveCache($cacheKey, json_encode($validCheckoutOptions));
}

Expand All @@ -199,11 +199,11 @@ protected function hideInvalidCheckoutOptions($paymentId)
* @param string $accessToken
* @return array
*/
public function getAvailableCheckoutOptions()
public function getAvailableCheckoutOptions($accessToken)
{
try {
$availableCheckouts = array();
$paymentMethods = $this->getPaymentMethods();
$paymentMethods = $this->getPaymentMethods($accessToken);

foreach ($paymentMethods['response'] as $paymentMethod) {
switch (strtolower($paymentMethod['payment_type_id'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function updateOrder($order, $data)
$data['payments'][$data['statusFinal']['key']]['transaction_details']['total_paid_amount'] =
$data['statusFinal']['totals']['totalApproved'];
}

$payment = $data['payments'][$data['statusFinal']['key']];
$orderPayment = $order->getPayment();
$orderPayment->setAdditionalInformation("paymentResponse", $payment);
Expand All @@ -246,6 +246,7 @@ public function updateOrder($order, $data)
if ($this->checkStatusAlreadyUpdated($order, $data)) {
$message = "[Already updated] " . $this->getMessage($payment);
$this->_dataHelper->log($message, 'mercadopago-basic.log');
$this->sendEmailCreateOrUpdate($order, $message);
return ['text' => $message, 'code' => Response::HTTP_OK];
}

Expand Down
38 changes: 7 additions & 31 deletions src/MercadoPago/Core/Model/Notifications/Topics/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public function updateStatusOrderByPayment($payment)
$orderPayment = $order->getPayment();
$orderPayment->setAdditionalInformation('paymentResponse', $payment);
$order->save();
$this->sendEmailCreateOrUpdate($order, $message);

$messageHttp = 'Mercado Pago - Status has already been updated.';
return [
Expand All @@ -139,18 +140,18 @@ public function updateStatusOrderByPayment($payment)

$order = self::setStatusAndComment($order, $newOrderStatus, $message);

$responseInvoice = false;
if ($payment['status'] == 'approved') {
$responseInvoice = $this->createInvoice($order, $message);
$this->addCardInCustomer($payment);
}

$this->updateAdditionalInformation($order, $payment);

$order->save();

$this->sendEmailCreateOrUpdate($order, $message);

$responseInvoice = false;
if ($payment['status'] == 'approved') {
$responseInvoice = $this->createInvoice($order, $message);
$this->addCardInCustomer($payment);
}

$messageHttp = 'Mercado Pago - Status successfully updated.';
return [
'httpStatus' => Response::HTTP_OK,
Expand Down Expand Up @@ -184,31 +185,6 @@ public function checkStatusAlreadyUpdated($paymentResponse, $order)
return $orderUpdated;
} //end checkStatusAlreadyUpdated()

/**
* @param $order
* @param $message
*/
public function sendEmailCreateOrUpdate($order, $message)
{
$emailOrderCreate = $this->_scopeConfig->getValue(ConfigData::PATH_ADVANCED_EMAIL_CREATE, ScopeInterface::SCOPE_STORE);
$emailAlreadySent = false;

if ($emailOrderCreate) {
if (!$order->getEmailSent()) {
$this->_orderSender->send($order, true);
$emailAlreadySent = true;
}
}

if ($emailAlreadySent === false) {
$statusEmail = $this->_scopeConfig->getValue(ConfigData::PATH_ADVANCED_EMAIL_UPDATE, ScopeInterface::SCOPE_STORE);
$statusEmailList = explode(',', $statusEmail);
if (in_array($order->getStatus(), $statusEmailList)) {
$this->_orderCommentSender->send($order, $notify = '1', str_replace('<br/>', '', $message));
}
}
} //end sendEmailCreateOrUpdate()

/**
* @param $order
* @param $message
Expand Down
33 changes: 25 additions & 8 deletions src/MercadoPago/Core/Model/Notifications/Topics/TopicsAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,6 @@ public function updateStatus($order, $payment, $message)
$emailAlreadySent = true;
}
}

if ($emailAlreadySent === false) {
$statusEmail = $this->_scopeConfig->getValue(ConfigData::PATH_ADVANCED_EMAIL_UPDATE, ScopeInterface::SCOPE_STORE);
$statusEmailList = explode(",", $statusEmail);
if (in_array($payment['status'], $statusEmailList)) {
$this->_orderSender->send($order, $notify = '1', str_replace("<br/>", "", $message));
}
}
}

$this->_dataHelper->log("Update order", 'mercadopago-basic.log', $order->getData());
Expand Down Expand Up @@ -526,6 +518,31 @@ public function _createInvoice($order)
return false;
}

/**
* @param $order
* @param $message
*/
public function sendEmailCreateOrUpdate($order, $message)
{
$emailOrderCreate = $this->_scopeConfig->getValue(ConfigData::PATH_ADVANCED_EMAIL_CREATE, ScopeInterface::SCOPE_STORE);
$emailAlreadySent = false;

if ($emailOrderCreate) {
if (!$order->getEmailSent()) {
$this->_orderSender->send($order, true);
$emailAlreadySent = true;
}
}

if ($emailAlreadySent === false) {
$statusEmail = $this->_scopeConfig->getValue(ConfigData::PATH_ADVANCED_EMAIL_UPDATE, ScopeInterface::SCOPE_STORE);
$statusEmailList = explode(',', $statusEmail);
if (in_array($order->getStatus(), $statusEmailList)) {
$this->_orderCommentSender->send($order, $notify = '1', str_replace('<br/>', '', $message));
}
}
} //end sendEmailCreateOrUpdate()

/**
* @return false|string|string[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public function toOptionArray()
} catch (\Exception $e) {
$this->coreHelper->log("PaymentMethodsTicket:: An error occurred at the time of obtaining the ticket payment methods: " . $e);
}
return [];
return ['methods' => $methods];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace MercadoPago\Core\Model\System\Config\Source;

use Exception;
use Magento\Backend\Block\Store\Switcher;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Option\ArrayInterface;
use Magento\Store\Model\ScopeInterface;
use MercadoPago\Core\Helper\ConfigData;
use MercadoPago\Core\Helper\Data;
use MercadoPago\Core\Lib\RestClient;

/**
* Class PaymentMethods
*
* @package MercadoPago\Core\Model\System\Config\Source
*/
class PaymentMethodsTicket implements ArrayInterface
{

/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;

/**
* @var Data
*/
protected $coreHelper;

protected $_switcher;


/**
* PaymentMethodsTicket constructor.
*
* @param ScopeConfigInterface $scopeConfig
* @param Data $coreHelper
* @param Switcher $switcher
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
Data $coreHelper,
Switcher $switcher
) {
$this->scopeConfig = $scopeConfig;
$this->coreHelper = $coreHelper;
$this->_switcher = $switcher;
} //end __construct()


/**
* Return available payment methods
*
* @return array
*/
public function toOptionArray()
{
$methods = [];

// default empty value
$methods[] = [
'value' => '',
'label' => __('Accept all payment methods'),
];
$accessToken = $this->scopeConfig->getValue(ConfigData::PATH_ACCESS_TOKEN, ScopeInterface::SCOPE_WEBSITE, $this->_switcher->getWebsiteId());

if (empty($accessToken)) {
return $methods;
}

$this->coreHelper->log('GET /v1/payment_methods', 'mercadopago');

try {
$response = RestClient::get('/v1/payment_methods', null, ['Authorization: Bearer ' . $accessToken]);
} catch (Exception $e) {
$this->coreHelper->log('PaymentMethodsTicket:: An error occurred at the time of obtaining the ticket payment methods: ' . $e);
return [];
}

if (isset($response['error']) || (isset($response['status']) && ($response['status'] != '200' && $response['status'] != '201'))) {
return $methods;
}

$response = $response['response'];

foreach ($response as $pm) {
if ((isset($pm['payment_type_id']) && $pm['payment_type_id'] == 'ticket') || $pm['payment_type_id'] == 'atm') {
$methods[] = [
'value' => $pm['id'],
'label' => __($pm['name']),
];
}
}

$this->coreHelper->log('PaymentMethodsTicket:: Displayed', 'mercadopago', $methods);

return $methods;
} //end toOptionArray()
}//end class
6 changes: 3 additions & 3 deletions src/MercadoPago/Core/Observer/ConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class ConfigObserver implements ObserverInterface
*/
private $banners = [
"mercadopago_custom" => [
"MLA" => "http://imgmp.mlstatic.com/org-img/banners/ar/medios/online/468X60.jpg",
"MLB" => "http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg",
"MLA" => "https://imgmp.mlstatic.com/org-img/banners/ar/medios/online/468X60.jpg",
"MLB" => "https://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg",
"MCO" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
"MLM" => "http://imgmp.mlstatic.com/org-img/banners/mx/medios/MLM_468X60.JPG",
"MLM" => "https://imgmp.mlstatic.com/org-img/banners/mx/medios/MLM_468X60.JPG",
"MLC" => "https://secure.mlstatic.com/developers/site/cloud/banners/cl/468x60.gif",
"MLV" => "https://imgmp.mlstatic.com/org-img/banners/ve/medios/468X60.jpg",
"MPE" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
Expand Down
8 changes: 7 additions & 1 deletion src/MercadoPago/Core/Observer/RefundObserverBeforeSave.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Class RefundObserverBeforeSave
*
* @package MercadoPago\Core\Observer
*
* @codeCoverageIgnore
*/
class RefundObserverBeforeSave implements ObserverInterface
{
Expand Down Expand Up @@ -137,7 +139,11 @@ protected function creditMemoRefundBeforeSave($order, $creditMemo)
$responseRefund = $mp->post("/v1/payments/$paymentID/refunds", $params);
}

if (!is_null($responseRefund) && ($responseRefund['status'] == 200 || $responseRefund['status'] == 201)) {
if (is_null($responseRefund)) {
$this->throwRefundException(__("Could not process the refund, The Mercado Pago API returned an unexpected error. Check the log files."));
}

if ($responseRefund['status'] == 200 || $responseRefund['status'] == 201) {
$successMessageRefund = "Mercado Pago - " . __('Refund of %1 was processed successfully.', $amountRefund);
$this->messageManager->addSuccessMessage($successMessageRefund);
$this->dataHelper->log("RefundObserverBeforeSave::creditMemoRefundBeforeSave - " . $successMessageRefund, 'mercadopago-custom.log', $responseRefund);
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mercadopago/core",
"description": "Mercado Pago Magento 2 Plugin",
"type": "magento2-module",
"version": "3.14.2",
"version": "3.15.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</field>

<field id="order_status_partially_refunded" translate="label" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Order status when payment is partually refunded</label>
<label>Order status when payment is partially refunded</label>
<source_model>MercadoPago\Core\Model\System\Config\Source\Order\Status</source_model>
<config_path>payment/mercadopago/order_status_partially_refunded</config_path>
</field>
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MercadoPago_Core" setup_version="3.14.2">
<module name="MercadoPago_Core" setup_version="3.15.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/i18n/es_AR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Order status when payment is chargeback","Estado de la orden cuando el pago resulta chargeback"
"Order status when payment is in_mediation","Estado de la orden cuando el pago resulta in_mediation"
"Order status when payment is refunded","Estado de la orden cuando el pago resulta refunded"
"Order status when payment is partually refunded","Estado de la orden cuando el pago resulta partially_refunded"
"Order status when payment is partially refunded","Estado de la orden cuando el pago resulta partially_refunded"
"API Integration","Integración de API"
"Refund payment","Devolución de pagos"
"Enable payment refund when a Credit Memo is created, the refund will occur if the payment is Approved.","Habilitar la devolución de pagos cuando se crea una Credit Memo. La devolución ocurrirá si el pago resultó aprobado."
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/i18n/es_CL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Order status when payment is chargeback","Estado de la orden cuando el pago resulta chargeback"
"Order status when payment is in_mediation","Estado de la orden cuando el pago resulta in_mediation"
"Order status when payment is refunded","Estado de la orden cuando el pago resulta refunded"
"Order status when payment is partually refunded","Estado de la orden cuando el pago resulta partially_refunded"
"Order status when payment is partially refunded","Estado de la orden cuando el pago resulta partially_refunded"
"API Integration","Integración de API"
"Refund payment","Devolución de pagos"
"Enable payment refund when a Credit Memo is created, the refund will occur if the payment is Approved.","Habilitar la devolución de pagos cuando se crea una Credit Memo. La devolución ocurrirá si el pago resultó aprobado."
Expand Down
Loading

0 comments on commit 0b5d4e0

Please sign in to comment.