Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien SUAREZ committed Jan 25, 2017
0 parents commit 48b4a3e
Show file tree
Hide file tree
Showing 83 changed files with 3,986 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Api/GuestPaymentManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Monext\Payline\Api;

use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\PaymentInterface;

/**
* @api
*/
interface GuestPaymentManagementInterface
{
/**
* @param string $cartId
* @param string $email
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @return array
*/
public function saveCheckoutPaymentInformationFacade(
$cartId,
$email,
PaymentInterface $paymentMethod,
AddressInterface $billingAddress = null
);
}
24 changes: 24 additions & 0 deletions Api/PaymentManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Monext\Payline\Api;

use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\PaymentInterface;

/**
* @api
*/
interface PaymentManagementInterface
{
/**
* @param int $cartId
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
* @return array
*/
public function saveCheckoutPaymentInformationFacade(
$cartId,
PaymentInterface $paymentMethod,
AddressInterface $billingAddress = null
);
}
23 changes: 23 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/Contract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Monext\Payline\Block\Adminhtml\System\Config\Form\Field;

use Magento\Config\Block\System\Config\Form\Field;

class Contract extends Field
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (!$this->getTemplate()) {
$this->setTemplate('Monext_Payline::system/config/contract.phtml');
}
return $this;
}

protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return parent::_getElementHtml($element) . $this->_toHtml();
}
}

29 changes: 29 additions & 0 deletions Block/Adminhtml/System/Config/Form/Fieldset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Monext\Payline\Block\Adminhtml\System\Config\Form;

use Magento\Config\Block\System\Config\Form\Fieldset as BaseFieldset;

class Fieldset extends BaseFieldset
{
/**
* Return header comment part of html for fieldset
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _getHeaderCommentHtml($element)
{
$groupConfig = $element->getGroup();

if (empty($groupConfig['help_url']) || !$element->getComment()) {
return parent::_getHeaderCommentHtml($element);
}

$html = '<div class="comment">' .
__($element->getComment(), $groupConfig['help_url'])
. '</div>';

return $html;
}
}
56 changes: 56 additions & 0 deletions Block/WebPayment/WidgetIframeForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Monext\Payline\Block\WebPayment;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Monext\Payline\Helper\Constants as HelperConstants;
use Monext\Payline\Model\CartManagement as PaylineCartManagement;
use Payline\PaylineSDK;

class WidgetIframeForm extends Template
{
/**
* @var PaylineCartManagement
*/
protected $paylineCartManagement;

public function __construct(
Context $context,
PaylineCartManagement $paylineCartManagement,
array $data = []
)
{
parent::__construct($context, $data);
$this->paylineCartManagement = $paylineCartManagement;
}

public function getWidgetJsUrl()
{
if($this->_scopeConfig->getValue(HelperConstants::CONFIG_PATH_PAYLINE_GENERAL_ENVIRONMENT) == PaylineSDK::ENV_PROD) {
return 'https://payment.payline.com/scripts/widget-min.js';
} else {
return 'https://homologation-payment.payline.com/scripts/widget-min.js';
}
}

public function getWidgetCssUrl()
{
if($this->_scopeConfig->getValue(HelperConstants::CONFIG_PATH_PAYLINE_GENERAL_ENVIRONMENT) == PaylineSDK::ENV_PROD) {
return 'https://payment.payline.com/styles/widget-min.css';
} else {
return 'https://homologation-payment.payline.com/styles/widget-min.css';
}
}

public function getToken()
{
return $this->getRequest()->getParam('token');
}

public function getWidgetDisplay()
{
$quote = $this->paylineCartManagement->getCartByToken($this->getToken());
return $quote->getPayment()->getMethodInstance()->getConfigData('widget_display');
}
}
20 changes: 20 additions & 0 deletions Controller/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Monext\Payline\Controller;

use Magento\Framework\App\Action\Action as BaseAction;

abstract class Action extends BaseAction
{
protected function getToken()
{
$token = $this->getRequest()->getParam('paylinetoken');

if(empty($token)) {
$token = $this->getRequest()->getParam('token');
}

return $token;
}
}

39 changes: 39 additions & 0 deletions Controller/Adminhtml/Contract/Refresh.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Monext\Payline\Controller\Adminhtml\Contract;

use Magento\Backend\App\AbstractAction;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\RedirectFactory as ResultRedirectFactory;
use Monext\Payline\Model\ContractManagement;

class Refresh extends AbstractAction
{
/**
* @var ContractManagement
*/
protected $contractManagement;

/**
* @var ResultRedirectFactory
*/
protected $resultRedirectFactory;

public function __construct(
Context $context,
ContractManagement $contractManagement
)
{
parent::__construct($context);
$this->contractManagement = $contractManagement;
}

public function execute()
{
$this->contractManagement->refreshContracts();

$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setRefererUrl();
return $resultRedirect;
}
}
34 changes: 34 additions & 0 deletions Controller/WebPayment/CancelFromPaymentGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Monext\Payline\Controller\WebPayment;

use Magento\Framework\App\Action\Context;
use Monext\Payline\Controller\Action;
use Monext\Payline\Model\PaymentManagement as PaylinePaymentManagement;

class CancelFromPaymentGateway extends Action
{
/**
* @var PaylinePaymentManagement
*/
protected $paylinePaymentManagement;

public function __construct(
Context $context,
PaylinePaymentManagement $paylinePaymentManagement
)
{
parent::__construct($context);
$this->paylinePaymentManagement = $paylinePaymentManagement;
}

public function execute()
{
// TODO handle exception
$this->paylinePaymentManagement->handlePaymentGatewayCancelByToken($this->getToken());

$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('checkout');
return $resultRedirect;
}
}
55 changes: 55 additions & 0 deletions Controller/WebPayment/GuestReturnFromWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Monext\Payline\Controller\WebPayment;

use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\RawFactory as ResultRawFactory;
use Magento\Framework\View\Element\TemplateFactory;
use Monext\Payline\Controller\Action;
use Monext\Payline\Model\GuestCartManagement as PaylineGuestCartManagement;

class GuestReturnFromWidget extends Action
{
/**
* @var PaylineGuestCartManagement
*/
protected $paylineGuestCartManagement;

/**
* @var ResultRawFactory
*/
protected $resultRawFactory;

/**
* @var TemplateFactory
*/
protected $templateFactory;

public function __construct(
Context $context,
PaylineGuestCartManagement $paylineGuestCartManagement,
ResultRawFactory $resultRawFactory,
TemplateFactory $templateFactory
)
{
parent::__construct($context);
$this->resultRawFactory = $resultRawFactory;
$this->paylineGuestCartManagement = $paylineGuestCartManagement;
$this->templateFactory = $templateFactory;
}

public function execute()
{
// TODO CatchException
$this->paylineGuestCartManagement->placeOrderByToken($this->getToken());

$resultRaw = $this->resultRawFactory->create();

$block = $this->templateFactory->create();
$block->setTemplate('Monext_Payline::web_payment/widget_iframe_success.phtml');
$resultRaw->setContents($block->toHtml());

return $resultRaw;
}
}

43 changes: 43 additions & 0 deletions Controller/WebPayment/LoadWidgetIframeForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Monext\Payline\Controller\WebPayment;

use Magento\Framework\App\Action\Context;
use Magento\Framework\Controller\Result\RawFactory as ResultRawFactory;
use Monext\Payline\Controller\Action;
use Monext\Payline\Block\WebPayment\WidgetIframeFormFactory;

class LoadWidgetIframeForm extends Action
{
/**
* @var ResultRawFactory
*/
protected $resultRawFactory;

/**
* @var WidgetIframeFormFactory
*/
protected $widgetIframeFormFactory;

public function __construct(
Context $context,
ResultRawFactory $resultRawFactory,
WidgetIframeFormFactory $widgetIframeFormFactory
)
{
parent::__construct($context);
$this->resultRawFactory = $resultRawFactory;
$this->widgetIframeFormFactory = $widgetIframeFormFactory;
}

public function execute()
{
$resultRaw = $this->resultRawFactory->create();

$block = $this->widgetIframeFormFactory->create();
$block->setTemplate('Monext_Payline::web_payment/widget_iframe_form.phtml');
$resultRaw->setContents($block->toHtml());

return $resultRaw;
}
}
Loading

0 comments on commit 48b4a3e

Please sign in to comment.