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

Allow developers set custom base notification url for development and… #184

Open
wants to merge 1 commit into
base: feature/features-from-community-refund-and-config-observer
Choose a base branch
from
Open
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: 4 additions & 0 deletions src/MercadoPago/Core/Helper/ConfigData.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ class ConfigData
const PATH_ADVANCED_INTEGRATOR = 'payment/mercadopago/integrator_id';
const PATH_ADVANCED_EMAIL_CREATE = 'payment/mercadopago/email_order_create';
const PATH_ADVANCED_EMAIL_UPDATE = 'payment/mercadopago/email_order_update';
const PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL_ACTIVE = 'payment/mercadopago/custom_base_notification_url_active';
const PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL = 'payment/mercadopago/custom_base_notification_url';


}
34 changes: 33 additions & 1 deletion src/MercadoPago/Core/Model/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,20 @@ public function makeDefaultPreferencePaymentV1($paymentInfo = [], $quote = null,
];

$notification_url = $this->_urlBuilder->getUrl('mercadopago/notifications/custom', $notification_params);
if (isset($notification_url) && !strrpos($notification_url, 'localhost')) {

if (isset($notification_url) &&
!strrpos($notification_url, 'localhost')
) {
$preference['notification_url'] = $notification_url;
}


if($this->shouldUseCustomBaseNotificationUrl()) {
$preference['notification_url'] =
$this->getCustomBaseNotificationUrl() . '/' . 'mercadopago/notifications/custom?source_news=webhooks';
}


$preference['description'] = __(
"Order # %1 in store %2",
$order->getIncrementId(),
Expand Down Expand Up @@ -829,4 +839,26 @@ protected function getSiteId()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
));
} //end getSiteId()

/**
* @return bool|null
*/
protected function shouldUseCustomBaseNotificationUrl ()
{
return $this->_scopeConfig->getValue(
\MercadoPago\Core\Helper\ConfigData::PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string|null
*/
protected function getCustomBaseNotificationUrl() {
return $this->_scopeConfig->getValue(
\MercadoPago\Core\Helper\ConfigData::PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

}
27 changes: 27 additions & 0 deletions src/MercadoPago/Core/Model/Preference/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ protected function getNotificationUrl()
return;
}

if($this->shouldUseCustomBaseNotificationUrl()) {
$notification_url =
$this->getCustomBaseNotificationUrl() . '/' . self::NOTIFICATION_URL .'?source_news=ipn';
}

return $notification_url;
}

Expand All @@ -565,4 +570,26 @@ protected function getSiteId()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
));
}//end getSiteId()

/**
* @return bool|null
*/
protected function shouldUseCustomBaseNotificationUrl ()
{
return $this->_scopeConfig->getValue(
\MercadoPago\Core\Helper\ConfigData::PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string|null
*/
protected function getCustomBaseNotificationUrl() {
return $this->_scopeConfig->getValue(
\MercadoPago\Core\Helper\ConfigData::PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

}
28 changes: 28 additions & 0 deletions src/MercadoPago/Core/Model/Preference/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MercadoPago\Core\Model\Preference;

use Exception;
use Laminas\View\Helper\Url;
use Magento\Catalog\Helper\Image;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Api\Data\CustomerInterface;
Expand Down Expand Up @@ -686,6 +687,33 @@ protected function getNotificationUrl()
return;
}

if($this->shouldUseCustomBaseNotificationUrl()) {
$notification_url =
$this->getCustomBaseNotificationUrl() . '/' . self::NOTIFICATION_PATH .'?source_news=ipn';
}

return $notification_url;
}

/**
* @return bool|null
*/
protected function shouldUseCustomBaseNotificationUrl ()
{
return $this->scopeConfig->getValue(
\MercadoPago\Core\Helper\ConfigData::PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string|null
*/
protected function getCustomBaseNotificationUrl() {
return $this->scopeConfig->getValue(
\MercadoPago\Core\Helper\ConfigData::PATH_ADVANCED_CUSTOM_BASE_NOTIFICATION_URL,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

}//end class
18 changes: 18 additions & 0 deletions src/MercadoPago/Core/etc/adminhtml/system/advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@
<comment>A file named mercadopago.log will be created in your store's log folder (var/log). This file will contain the module debug, where it will help to understand the behavior of the module.</comment>
</field>

<field id="custom_base_notification_url_active" translate="label comment" type="select" sortOrder="95"
showInDefault="1" showInWebsite="1" showInStore="0">
<label>Use custom base notification url</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/mercadopago/custom_base_notification_url_active</config_path>
<comment>Use a fixed base notification URL for all methods. Please note, this option should only be used in development and testing environments.</comment>
</field>

<field id="custom_base_notification_url" translate="label comment" type="text" sortOrder="96" showInDefault="1" showInWebsite="1"
showInStore="0">
<label>Custom base notification url</label>
<validate>required-entry</validate>
<config_path>payment/mercadopago/custom_base_notification_url</config_path>
<depends>
<field id="custom_base_notification_url_active">1</field>
</depends>
</field>

<field id="version" translate="label" type="label" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Current Version</label>
<backend_model>MercadoPago\Core\Block\Adminhtml\System\Config\Version</backend_model>
Expand Down
1 change: 1 addition & 0 deletions src/MercadoPago/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<email_order_update>pending,approved,in_process,in_mediation,rejected,cancelled,refunded,charged_back
</email_order_update>
<logs>1</logs>
<custom_base_notification_url_active>0</custom_base_notification_url_active>
<model>MercadoPago\Core\Model\Core</model>
</mercadopago>
</payment>
Expand Down