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

Commit

Permalink
3.1.0: Added Payment Method Bank Transfer for Chile and Colombia
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatsuoka committed Mar 19, 2019
1 parent d90dd38 commit 9bae6cd
Show file tree
Hide file tree
Showing 29 changed files with 1,210 additions and 82 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": "3.0.0",
"version": "3.1.0",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
8 changes: 8 additions & 0 deletions src/MercadoPago/Core/Block/AbstractSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,34 @@ class AbstractSuccess
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_scopeConfig;


/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \MercadoPago\Core\Model\CoreFactory $coreFactory
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\MercadoPago\Core\Model\CoreFactory $coreFactory,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
array $data = []
)
{
$this->_coreFactory = $coreFactory;
$this->_orderFactory = $orderFactory;
$this->_checkoutSession = $checkoutSession;
$this->_scopeConfig = $scopeConfig;
parent::__construct(
$context,
$data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,83 @@
class Payment
extends \Magento\Config\Block\System\Config\Form\Fieldset
{

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;

/**
*
* @var \Magento\Config\Model\ResourceModel\Config
*/
protected $configResource;

/**
*
* @var \Magento\Backend\Block\Store\Switcher
*/
protected $switcher;

/**
* @param \Magento\Backend\Block\Context $context
* @param \Magento\Backend\Model\Auth\Session $authSession
* @param \Magento\Framework\View\Helper\Js $jsHelper
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Config\Model\ResourceModel\Config $configResource
* @param \Magento\Backend\Block\Store\Switcher $switcher
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Framework\View\Helper\Js $jsHelper,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Config\Model\ResourceModel\Config $configResource,
\Magento\Backend\Block\Store\Switcher $switcher,
array $data = []
)
{
parent::__construct($context, $authSession, $jsHelper, $data);
$this->scopeConfig = $scopeConfig;
$this->configResource = $configResource;
$this->switcher = $switcher;
}

/**
* Add custom css class
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*
* @return string
*/
protected function _getFrontendClass($element)
{
return parent::_getFrontendClass($element) . ' with-button';
}

/**
* Return header title part of html for payment solution
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*
* @return string
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _getHeaderTitleHtml($element)
{
$html = '<div class="config-heading meli" ><div class="heading"><strong id="meli-logo">' . $element->getLegend();
$html .= '</strong></div>';

$html .= '<div class="button-container meli-cards"><button type="button"'
. ' class="meli-payment-btn action-configure button'
. '" id="' . $element->getHtmlId()
. '-head" onclick="Fieldset.toggleCollapse(\'' . $element->getHtmlId() . '\', \''
. $this->getUrl('*/*/state') . '\'); return false;"><span class="state-closed">'
. __('Configure') . '</span><span class="state-opened">'
. __('Close') . '</span></button></div></div>';

return $html;
}


/**
* Return header comment part of html for payment solution
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getHeaderCommentHtml($element)
{
return '';
}
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element){
//get id element
$id = $element->getId();

//check is bank transfer
if(strpos($id, 'custom_checkout_bank_transfer') !== false){

//get country (Site id for Mercado Pago)
$siteId = strtoupper($this->scopeConfig->getValue(\MercadoPago\Core\Helper\ConfigData::PATH_SITE_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE));

//hide payment method if not Chile or Colombia
if($siteId != "MLC" && $siteId != "MCO"){

//get is active
$statusPaymentMethod = $this->scopeConfig->isSetFlag(\MercadoPago\Core\Helper\ConfigData::PATH_CUSTOM_BANK_TRANSFER_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
//check is active for disable
if($statusPaymentMethod){
$path = \MercadoPago\Core\Helper\ConfigData::PATH_CUSTOM_BANK_TRANSFER_ACTIVE;
$value = 0;

/**
* Get collapsed state on-load
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*
* @return false
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _isCollapseState($element)
{
return false;
if ($this->switcher->getWebsiteId() == 0) {
$this->configResource->saveConfig($path, $value, 'default', 0);
} else {
$this->configResource->saveConfig($path, $value, 'websites', $this->switcher->getWebsiteId());
}
}
return "";
}
}
return parent::render($element);
}

}
27 changes: 27 additions & 0 deletions src/MercadoPago/Core/Block/CustomBankTransfer/Success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace MercadoPago\Core\Block\CustomBankTransfer;

/**
* Class Success
*
* @package MercadoPago\Core\Block\CustomBankTransfer
*/

class Success
extends \MercadoPago\Core\Block\AbstractSuccess
{
/**
* Constructor
*/
protected function _construct()
{
parent::_construct();
$this->setTemplate('custom_bank_transfer/success.phtml');
}

public function getRedirectUserStatus(){
$redirectUser = $this->_scopeConfig->isSetFlag(\MercadoPago\Core\Helper\ConfigData::PATH_CUSTOM_BANK_TRANSFER_REDIRECT_PAYER);
return $redirectUser;
}

}
15 changes: 7 additions & 8 deletions src/MercadoPago/Core/Controller/Checkout/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public function __construct(
parent::__construct(
$context
);

}

/**
Expand Down Expand Up @@ -155,13 +154,13 @@ public function execute()
*/
public function getCheckoutHandle()
{
$handle = '';
$order = $this->_getOrder();
if (!empty($order->getId())) {
$handle = $order->getPayment()->getMethod();
}
$handle .= '_success';
$handle = '';
$order = $this->_getOrder();
if (!empty($order->getId())) {
$handle = $order->getPayment()->getMethod();
}
$handle .= '_success';

return $handle;
return $handle;
}
}
6 changes: 6 additions & 0 deletions src/MercadoPago/Core/Helper/ConfigData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class ConfigData
const PATH_CUSTOM_TICKET_COUPON = 'payment/mercadopago_customticket/coupon_mercadopago';
const PATH_CUSTOM_TICKET_BANNER = 'payment/mercadopago_customticket/banner_checkout';
const PATH_CUSTOM_EXCLUDE_PAYMENT_METHODS = 'payment/mercadopago_customticket/excluded_payment_methods';

//custom method bank transfer
const PATH_CUSTOM_BANK_TRANSFER_ACTIVE = 'payment/mercadopago_custom_bank_transfer/active';
const PATH_CUSTOM_BANK_TRANSFER_BANNER = 'payment/mercadopago_custom_bank_transfer/banner_checkout';
const PATH_CUSTOM_BANK_TRANSFER_REDIRECT_PAYER = 'payment/mercadopago_custom_bank_transfer/redirect_payer';


//order configuration
const PATH_ORDER_APPROVED = 'payment/mercadopago/order_status_approved';
Expand Down
17 changes: 17 additions & 0 deletions src/MercadoPago/Core/Model/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,23 @@ public function getPaymentMethods()

return $payment_methods;
}

/**
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getIdentificationTypes()
{
if (!$this->_accessToken) {
$this->_accessToken = $this->_scopeConfig->getValue(\MercadoPago\Core\Helper\ConfigData::PATH_ACCESS_TOKEN, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

$mp = $this->_coreHelper->getApiInstance($this->_accessToken);

$identificationTypes = $mp->get("/v1/identification_types");

return $identificationTypes;
}

/**
* @return mixed|string
Expand Down
Loading

0 comments on commit 9bae6cd

Please sign in to comment.