Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FatchipRobert committed Feb 1, 2022
2 parents 32eb370 + 6fbe132 commit 81faba1
Show file tree
Hide file tree
Showing 99 changed files with 3,159 additions and 4,467 deletions.
13 changes: 13 additions & 0 deletions Api/CheckoutConfigInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace RatePAY\Payment\Api;

interface CheckoutConfigInterface
{
/**
* Return Ratepay checkout config
*
* @return \RatePAY\Payment\Service\V1\Data\CheckoutConfigResponse
*/
public function refreshCheckoutConfig();
}
30 changes: 30 additions & 0 deletions Api/Data/CheckoutConfigResponseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace RatePAY\Payment\Api\Data;

/**
* Response interface for checkout config
*/
interface CheckoutConfigResponseInterface
{
/**
* Returns if the request was a success
*
* @return bool
*/
public function getSuccess();

/**
* Return json checkout config
*
* @return string
*/
public function getCheckoutConfig();

/**
* Returns errormessage
*
* @return string
*/
public function getErrormessage();
}
13 changes: 13 additions & 0 deletions Api/InstallmentPlanInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ interface InstallmentPlanInterface
* @return \RatePAY\Payment\Service\V1\Data\InstallmentPlanResponse
*/
public function getInstallmentPlan($calcType, $calcValue, $grandTotal, $methodCode);

/**
* Return installment plan details
*
* @param string $calcType
* @param string $calcValue
* @param float $grandTotal
* @param string $methodCode
* @param string $billingCountryId
* @param string $currency
* @return \RatePAY\Payment\Service\V1\Data\InstallmentPlanResponse
*/
public function getInstallmentPlanBackend($calcType, $calcValue, $grandTotal, $methodCode, $billingCountryId, $currency);
}
132 changes: 132 additions & 0 deletions Block/Adminhtml/Config/Fieldset/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

namespace RatePAY\Payment\Block\Adminhtml\Config\Fieldset;

/**
* Ratepay payment logo fieldset
*/
class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
{
/**
* @var \Magento\Framework\Module\ModuleListInterface
*/
protected $moduleList;

/**
* @param \Magento\Backend\Block\Context $context
* @param \Magento\Backend\Model\Auth\Session $authSession
* @param \Magento\Framework\View\Helper\Js $jsHelper
* @param \Magento\Framework\Module\ModuleListInterface $moduleList,
* @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\Module\ModuleListInterface $moduleList,
array $data = []
) {
parent::__construct($context, $authSession, $jsHelper, $data);
$this->moduleList = $moduleList;

}

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

/**
* 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)
{
$htmlId = $element->getHtmlId();

$html = '<div class="config-heading" >';
$html .= ' <div class="button-container">';
$html .= ' <button type="button" class="button action-configure" id="'.$htmlId.'-head" onclick="ratepayToggleSolution.call(this, \''.$htmlId."', '".$this->getUrl('adminhtml/*/state').'\'); return false;">';
$html .= ' <span class="state-closed">' . __('Configure') . '</span>';
$html .= ' <span class="state-opened">' . __('Close') . '</span>';
$html .= ' </button>';
$html .= ' </div>';
$html .= ' <div class="heading">';
$html .= ' <strong>' . $element->getLegend() . '</strong>';
$html .= ' <span class="heading-intro">';
$html .= ' <div class="ratepay-logo"></div>';
$html .= ' <div class="payment-text">' . $element->getComment() . '</div>';
$html .= ' </span>';
$html .= ' <div class="config-alt"></div>';
$html .= ' </div>';
$html .= ' <div id="ratepay_version_number">'.__('Module version').': '.$this->moduleList->getOne('RatePAY_Payment')['setup_version'].'</div>';
$html .= '</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 '';
}

/**
* Get collapsed state on-load
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return false
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _isCollapseState($element)
{
return false;
}

/**
* Return extra Js.
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getExtraJs($element)
{
$script = "require(['jquery', 'prototype'], function(jQuery){
window.ratepayToggleSolution = function (id, url) {
var doScroll = false;
Fieldset.toggleCollapse(id, url);
jQuery('#ratepay_version_number').toggle();
if ($(this).hasClassName(\"open\")) {
\$$(\".with-button button.button\").each(function(anotherButton) {
if (anotherButton != this && $(anotherButton).hasClassName(\"open\")) {
$(anotherButton).click();
doScroll = true;
}
}.bind(this));
}
if (doScroll) {
var pos = Element.cumulativeOffset($(this));
window.scrollTo(pos[0], pos[1] - 45);
}
}
});";

return $this->_jsHelper->getScript($script);
}
}
105 changes: 105 additions & 0 deletions Block/Adminhtml/Config/Form/Field/ProfileConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace RatePAY\Payment\Block\Adminhtml\Config\Form\Field;

class ProfileConfig extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* Element factory
*
* @var \Magento\Framework\Data\Form\Element\Factory
*/
protected $elementFactory;

/**
* @var \Magento\Config\Model\Config\Source\Yesno
*/
protected $yesNo;

/**
* Constructor
*
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
* @param \Magento\Config\Model\Config\Source\Yesno $yesNo
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
\Magento\Config\Model\Config\Source\Yesno $yesNo,
array $data = []
) {
parent::__construct($context, $data);
$this->elementFactory = $elementFactory;
$this->yesNo = $yesNo;
}

/**
* Initialise form fields
*
* @return void
*/
protected function _construct()
{
$this->addColumn('profileId', ['label' => __('ProfileID')]);
$this->addColumn('securityCode', ['label' => __('Security Code')]);
$this->addColumn('sandbox', ['label' => __('Sandbox active')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add Profile');
parent::_construct();
}

/**
* Render array cell for prototypeJS template
*
* @param string $columnName
* @return string
*/
public function renderCellTemplate($columnName)
{
if ($columnName != 'sandbox') {
return parent::renderCellTemplate($columnName);
}
$aOptions = $this->yesNo->toOptionArray(); // add transction status action options to dropdown

$oElement = $this->elementFactory->create('select');
$oElement->setForm($this->getForm());
$oElement->setName($this->_getCellInputElementName($columnName));
$oElement->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName));
$oElement->setValues($aOptions);
return str_replace("\n", '', $oElement->getElementHtml());
}

/**
* Obtain existing data from form element
*
* Each row will be instance of \Magento\Framework\DataObject
*
* @return array
*/
public function getArrayRows()
{
$result = [];
/** @var \Magento\Framework\Data\Form\Element\AbstractElement */
$element = $this->getElement();
$aValue = $element->getValue(); // get values
if (is_array($aValue) === false) { // no array given? -> value from config.xml
$aValue = json_decode($aValue, true); // convert string to array
}
if ($aValue && is_array($aValue)) {
foreach ($aValue as $rowId => $row) {
$rowColumnValues = [];
foreach ($row as $key => $value) {
$row[$key] = $value;
$rowColumnValues[$this->_getCellInputElementId($rowId, $key)] = $row[$key]; // add value the row
}
$row['_id'] = $rowId;
$row['column_values'] = $rowColumnValues;
$result[$rowId] = new \Magento\Framework\DataObject($row);
$this->_prepareArrayRow($result[$rowId]);
}
}
return $result;
}
}
Loading

0 comments on commit 81faba1

Please sign in to comment.