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

Commit

Permalink
Merge pull request #81 from gmatsuoka/master
Browse files Browse the repository at this point in the history
Version 2.1.0
  • Loading branch information
mmitameli authored Jun 15, 2018
2 parents 0cb5367 + 7776822 commit b2b28cc
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 43 deletions.
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-component",
"version": "2.0.1",
"version": "2.1.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/Cron/OrderUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function _updateOrder($order, $statusOrder, $paymentOrder){
}else{
$order->setState($this->_statusHelper->_getAssignedState($statusOrder));
}

$order->addStatusToHistory($statusOrder, $this->_statusHelper->getMessage($statusOrder, $statusOrder), true);
$order->sendOrderUpdateEmail(true, $this->_statusHelper->getMessage($statusOrder, $paymentOrder));
$order->save();
Expand Down
48 changes: 27 additions & 21 deletions src/MercadoPago/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,20 @@ public function log($message, $name = "mercadopago", $array = null)
* @return \MercadoPago\Core\Lib\Api
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getApiInstance()
{
$params = func_num_args();
if ($params > 2 || $params < 1) {
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN'));
}
if ($params == 1) {
$api = new \MercadoPago\Core\Lib\Api(func_get_arg(0));
$api->set_platform(self::PLATFORM_OPENPLATFORM);
} else {
$api = new \MercadoPago\Core\Lib\Api(func_get_arg(0), func_get_arg(1));
$api->set_platform(self::PLATFORM_STD);
}
public function getApiInstance($access_or_client_id = null, $client_secret = null) {

if(is_null($access_or_client_id) && is_null($client_secret)){
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN'));
}

if ($access_or_client_id != null && $client_secret == null) {
$api = new \MercadoPago\Core\Lib\Api($access_or_client_id);
$api->set_platform(self::PLATFORM_OPENPLATFORM);
} else {
$api = new \MercadoPago\Core\Lib\Api($access_or_client_id, $client_secret);
$api->set_platform(self::PLATFORM_STD);
}

if ($this->_switcher->getWebsiteId() != 0) {
if ($this->scopeConfig->getValue('payment/mercadopago_standard/sandbox_mode', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $this->_switcher->getWebsiteId())) {
$api->sandbox_mode(true);
Expand Down Expand Up @@ -255,6 +256,11 @@ public function getApiInstance()
*/
public function isValidAccessToken($accessToken)
{

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

$mp = $this->getApiInstance($accessToken);
try {
$response = $mp->get("/v1/payment_methods");
Expand All @@ -279,14 +285,14 @@ public function isValidAccessToken($accessToken)
*/
public function isValidClientCredentials($clientId, $clientSecret)
{
$mp = $this->getApiInstance($clientId, $clientSecret);
try {
$mp->get_access_token();
} catch (\Exception $e) {
return false;
}

return true;
$mp = $this->getApiInstance($clientId, $clientSecret);
try {
$mp->get_access_token();
} catch (\Exception $e) {
return false;
}

return true;
}

/**
Expand Down
31 changes: 27 additions & 4 deletions src/MercadoPago/Core/Helper/StatusUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class StatusUpdate
*/
protected $_orderSender;


protected $_dataHelper;
protected $_coreHelper;

Expand Down Expand Up @@ -550,16 +549,40 @@ protected function _updateStatus($order, $status, $message, $statusDetail)
{
if ($order->getState() !== \Magento\Sales\Model\Order::STATE_COMPLETE) {
$statusOrder = $this->getStatusOrder($status, $statusDetail, $order->canCreditmemo());
$emailAlreadySent = false;
//get scope config
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$scopeConfig = $objectManager->create('\Magento\Framework\App\Config\ScopeConfigInterface');
$emailOrderCreate = $scopeConfig->getValue('payment/mercadopago/email_order_create', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

if($statusOrder == 'canceled'){
$order->cancel();
}else{
$order->setState($this->_getAssignedState($statusOrder));
}


//add comment to history
$order->addStatusToHistory($statusOrder, $message, true);
if (!$order->getEmailSent()){
$this->_orderSender->send($order, true, $message);

//ckeck is active send email when create order
if($emailOrderCreate){
if (!$order->getEmailSent()){
$this->_orderSender->send($order, true, $message);
$emailAlreadySent = true;
}
}

//if the email has not been sent check sent in status
if($emailAlreadySent === false){
// search the list of statuses that can send email
$statusEmail = $scopeConfig->getValue('payment/mercadopago/email_order_update', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$statusEmailList = explode(",", $statusEmail);

//check if the status is on the authorized list
if(in_array($status, $statusEmailList)){
$orderCommentSender = $objectManager->create('Magento\Sales\Model\Order\Email\Sender\OrderCommentSender');
$orderCommentSender->send($order, $notify = '1' , str_replace("<br/>", "", $message));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/Model/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function makeDefaultPreferencePaymentV1($paymentInfo = [], $quote = null,

$sponsorId = $this->_scopeConfig->getValue('payment/mercadopago/sponsor_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$this->_coreHelper->log("Sponsor_id", 'mercadopago-standard.log', $sponsorId);
if (!empty($sponsorId)) {
if (!empty($sponsorId) && strpos( $customerInfo['email'], "@testuser.com" ) === false) {
$this->_coreHelper->log("Sponsor_id identificado", 'mercadopago-custom.log', $sponsorId);
$preference['sponsor_id'] = (int)$sponsorId;
}
Expand Down
6 changes: 5 additions & 1 deletion src/MercadoPago/Core/Model/Custom/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ public function assignData(\Magento\Framework\DataObject $data)
$data = new \Magento\Framework\DataObject($data);
}

$infoForm = $data->getData('additional_data');
$infoForm = $data->getData();

if(isset($infoForm['additional_data'])){
$infoForm = $infoForm['additional_data'];
}

$this->_helperData->log("assigData: ". json_encode($infoForm), self::LOG_NAME);

Expand Down
12 changes: 8 additions & 4 deletions src/MercadoPago/Core/Model/CustomTicket/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,24 @@ public function assignData(\Magento\Framework\DataObject $data)

//get array info
$infoForm = $data->getData();


if(isset($infoForm['additional_data'])){
$infoForm = $infoForm['additional_data'];
}

$this->_helperData->log("info form", self::LOG_NAME, $infoForm);

$info = $this->getInfoInstance();
$info->setAdditionalInformation('payment_method', $infoForm['additional_data']['payment_method_ticket']);
$info->setAdditionalInformation('payment_method', $infoForm['payment_method_ticket']);

if (!empty($infoForm['coupon_code'])) {
$info->setAdditionalInformation('coupon_code', $infoForm['coupon_code']);
}

// Fields for new febraban rule
foreach ($this->fields_febraban as $key) {
if (isset($infoForm['additional_data'][$key])) {
$info->setAdditionalInformation($key, $infoForm['additional_data'][$key]);
if (isset($infoForm[$key])) {
$info->setAdditionalInformation($key, $infoForm[$key]);
}
}

Expand Down
37 changes: 37 additions & 0 deletions src/MercadoPago/Core/Model/System/Config/Source/ListStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace MercadoPago\Core\Model\System\Config\Source;

/**
* Class Installments
*
* @package MercadoPago\Core\Model\System\Config\Source
*/
class ListStatus
implements \Magento\Framework\Option\ArrayInterface
{

/**
* Return available installments array
* @return array
*/
public function toOptionArray()
{
$status = [];
$status[] = ['value' => "do_not_send", 'label' => __("Do not send")];
$status[] = ['value' => "pending", 'label' => __("pending")];
$status[] = ['value' => "approved", 'label' => __("approved")];
$status[] = ['value' => "authorized", 'label' => __("authorized")];
$status[] = ['value' => "in_process", 'label' => __("in_process")];
$status[] = ['value' => "in_mediation", 'label' => __("in_mediation")];
$status[] = ['value' => "rejected", 'label' => __("rejected")];
$status[] = ['value' => "cancelled", 'label' => __("cancelled")];
$status[] = ['value' => "refunded", 'label' => __("refunded")];
$status[] = ['value' => "charged_back", 'label' => __("charged_back")];

//force order by key
ksort($status);

return $status;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ public function toOptionArray()
$this->_switcher->getWebsiteId()
);
$meHelper = $this->coreHelper;


if (empty($accessToken) || (empty($clientId) && empty($clientSecret)) ) {
return $methods;
}

if (empty($accessToken) && !$meHelper->isValidClientCredentials($clientId, $clientSecret)) {
return $methods;
if (!$meHelper->isValidClientCredentials($clientId, $clientSecret)) {
return $methods;
}

//if accessToken is empty uses clientId and clientSecret to obtain it
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/module-core",
"description": "Mercado Pago payment method module",
"type": "magento2-module",
"version": "2.0.1",
"version": "2.1.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
21 changes: 21 additions & 0 deletions src/MercadoPago/Core/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@
<source_model>MercadoPago\Core\Model\System\Config\Source\Order\Status</source_model>
</field>


<field id="heading_email" translate="label" sortOrder="70" showInDefault="1" showInWebsite="1">
<label>Email Options</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Field\Heading</frontend_model>
<attribute type="shared">1</attribute>
</field>

<field id="email_order_create" translate="label" type="select" sortOrder="71" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Order creation email</label>
<comment>Email sent when the order is created does not mean that the payment has been approved</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>

<field id="email_order_update" translate="label" type="multiselect" sortOrder="72" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Order update email</label>
<comment>Select the statuses you want to send update emails to. This email is only sent when the order status is updated. It is not sent on the first status update because the order creation email is sent. If the order creation email is deactivated, then the email of the first order update will be sent</comment>
<source_model>MercadoPago\Core\Model\System\Config\Source\ListStatus</source_model>
</field>



<field id="heading_developer" translate="label" sortOrder="80" showInDefault="1" showInWebsite="1">
<label>Developer Options</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Field\Heading</frontend_model>
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="2.0.1">
<module name="MercadoPago_Core" setup_version="2.1.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
10 changes: 9 additions & 1 deletion src/MercadoPago/Core/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,12 @@
"Number Address required","Number Address required"
"City required","City required"
"State required","State required"
"Zipcode required","Zipcode required"
"Zipcode required","Zipcode required"


"========== Version 2.1.0 ==========","========== Version 2.1.0 =========="
"Order creation email","Order creation email"
"Order update email","Order update email"
"Do not send","Do not send"
"Email sent when the order is created does not mean that the payment has been approved","Email sent when the order is created does not mean that the payment has been approved"
"Select the statuses you want to send update emails to. This email is only sent when the order status is updated. It is not sent on the first status update because the order creation email is sent. If the order creation email is deactivated, then the email of the first order update will be sent","Select the statuses you want to send update emails to. This email is only sent when the order status is updated. It is not sent on the first status update because the order creation email is sent. If the order creation email is deactivated, then the email of the first order update will be sent"
9 changes: 8 additions & 1 deletion src/MercadoPago/Core/i18n/es_AR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,11 @@ Es un requisito que usted cuente con un certificado SSL, y que el formulario de
"Number Address required","Obligatorio completar el Número de dirrección"
"City required","Obligatorio completar el Ciudad"
"State required","Obligatorio completar el Estado"
"Zipcode required","Obligatorio completar el Código postal"
"Zipcode required","Obligatorio completar el Código postal"

"========== Version 2.1.0 ==========","========== Version 2.1.0 =========="
"Order creation email","Enviar email cuando se crea el pedido"
"Order update email","Enviar email cuando el pedido es actualizado"
"Do not send","No enviar"
"Email sent when the order is created does not mean that the payment has been approved","El email es enviado cuando se crea el pedido, no significa que el pago haya sido aprobado"
"Select the statuses you want to send update emails to. This email is only sent when the order status is updated. It is not sent on the first status update because the order creation email is sent. If the order creation email is deactivated, then the email of the first order update will be sent","Seleccione los estados a los que desea enviar emails de actualización. Este email solo se envía cuando se actualiza el estado del pedido. No se envía en la primera actualización de estado porque se envía el email de creación de pedido. Si el email de creación de pedido está desactivado, se enviará el email en la primera actualización de pedido"
9 changes: 8 additions & 1 deletion src/MercadoPago/Core/i18n/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,11 @@
"Number Address required","Obrigatório o preenchimento do Número residencial"
"City required","Obrigatório informar a Cidade"
"State required","Obrigatório informar o Estado"
"Zipcode required","Obrigatório informar o CEP"
"Zipcode required","Obrigatório informar o CEP"

"========== Version 2.1.0 ==========","========== Version 2.1.0 =========="
"Order creation email","Enviar email quando pedido é criado"
"Order update email","Enviar email quando pedido é atualizado"
"Do not send","Não enviar"
"Email sent when the order is created does not mean that the payment has been approved","E-mail enviado quando o pedido é criado, não significa que o pagamento foi aprovado"
"Select the statuses you want to send update emails to. This email is only sent when the order status is updated. It is not sent on the first status update because the order creation email is sent. If the order creation email is deactivated, then the email of the first order update will be sent","Selecione os status para os quais você deseja enviar e-mails de atualização. Este e-mail é enviado somente quando o status do pedido é atualizado. Ele não é enviado na primeira atualização de status porque o email de criação do pedido é enviado. Se o e-mail de criação do pedido for desativado, o e-mail da atualização do primeiro pedido será enviado"
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'MercadoPago_Core', __DIR__);
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'MercadoPago_Core', __DIR__);
2 changes: 1 addition & 1 deletion src/MercadoPago/MercadoEnvios/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"php": "~5.5.0|~5.6.0|~7.0.0"
},
"type": "magento2-module",
"version": "2.0.1",
"version": "2.1.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/MercadoEnvios/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_MercadoEnvios" setup_version="2.0.1">
<module name="MercadoPago_MercadoEnvios" setup_version="2.1.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit b2b28cc

Please sign in to comment.