Skip to content

Commit

Permalink
Merge pull request #423 from omise/release-v3.0.0
Browse files Browse the repository at this point in the history
Release v3.0.0
  • Loading branch information
aashishgurung authored Apr 3, 2023
2 parents b6ac4d0 + fd90fca commit 266dfc7
Show file tree
Hide file tree
Showing 39 changed files with 1,531 additions and 247 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Code Coverage

on:
push:
branches: [ 'master' ]
branches: [ 'master', 'develop' ]
pull_request:
branches: [ 'master' ]
branches: [ 'master', 'develop' ]

jobs:
coverage:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Magento Coding Standard
on:
pull_request:
branches: [ master ]
push:

jobs:
static:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Deploy to Staging
on:
push:
branches: [ 'master' ]
branches: [ 'develop' ]

jobs:
static:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: Unit Test

on:
push:
branches:
- master
branches: [ 'master', 'develop' ]
pull_request:
branches:
- master
branches: [ 'master', 'develop' ]

jobs:
unit-test:
Expand Down
139 changes: 139 additions & 0 deletions Block/Adminhtml/System/Config/CardFormCustomization/FormModal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php

namespace Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Filesystem\Driver\File;

class FormModal extends Field
{
public $request;
public $storeManager;
public $localFileSystem;
public $theme;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\Request\Http $http
* @param array $data
*/
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
Http $request,
array $data = []
) {
$this->storeManager = $storeManager;
$this->request = $request;
$this->localFileSystem = new File();
$this->theme = new Theme();
parent::__construct($context, $data);
}

/**
* get css
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function getCss(AbstractElement $element)
{
return $this->localFileSystem->fileGetContents(__DIR__ . '/css/style.css');
}

/**
* get javascript
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function getScript(AbstractElement $element)
{
$script = $this->addGlobalJsVariables([
'OMISE_CC_INPUT_ID' => $element->getId(),
'OMISE_CC_DESIGN' => $element->getData('value'),
'OMISE_CC_LIGHT_THEME' => json_encode($this->theme->getLightTheme()),
'OMISE_CC_DARK_THEME' => json_encode($this->theme->getDarkTheme()),
'OMISE_CC_INPUT_INHERIT_VALUE' => $element->getInherit(),
'OMISE_CC_INPUT_INHERIT_LABEL' => $this->_getInheritCheckboxLabel($element),
'OMISE_CC_INPUT_INHERIT_SHOULD_SHOW' => $this->_isInheritCheckboxRequired($element),
]);

$script .= $this->localFileSystem->fileGetContents(__DIR__ . '/js/script.js');
return $script;
}

/**
* add global javascript variables
*
* @param Array
*/
private function addGlobalJsVariables($array)
{
$script = '';
foreach ($array as $key => $value) {
$script .= sprintf('window.%s = `%s`;', $key, $value);
}
return $script;
}

/**
* get inherit input name (use website checkbox)
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*/
protected function getInheritCheckboxName($element)
{
$namePrefix = preg_replace('#\[value\](\[\])?$#', '', $element->getName());
return $namePrefix . '[inherit]';
}

/**
* get HTML
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function getHtml(AbstractElement $element)
{
$isCheckboxRequired = $this->_isInheritCheckboxRequired($element);
$value = $element->getData('value');
$id = $element->getId();
$name = $element->getName();
$html = sprintf(
"<input id='%s' name='%s' value='%s' type='hidden'>",
$id,
$name,
$value
);
if ($isCheckboxRequired) {
$html .= sprintf(
"<input id='%s' name='%s' value='%s' type='hidden'>",
$id . '_inherit',
$this->getInheritCheckboxName($element),
$element->getInherit()
);
}
$html .= $this->localFileSystem->fileGetContents(__DIR__ . '/form-modal.html');
return $html;
}

/**
* render HTML markup for given element
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
$html = '<style>' . $this->getCss($element) . '</style>';
$html .= $this->getHtml($element);
$html .= '<script>' . $this->getScript($element) . '</script>';
return $html;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization;

use Magento\Framework\Notification\MessageInterface;
use Omise\Payment\Model\Config\Cc as OmiseCcConfig;

class SecureFormBannerMessage implements MessageInterface
{

/**
* @var \Omise\Payment\Model\Config\Cc
*/
protected $omiseCcConfig;

/**
* @var Omise\Payment\Model\Customer
*/
protected $customer;

public function __construct(
OmiseCcConfig $omiseCcConfig
) {
$this->omiseCcConfig = $omiseCcConfig;
}

/**
* Retrieve unique system message identity
*
* @return string
*/
public function getIdentity()
{
return 'opn_payments_secure_form_message';
}

/**
* Whether the system message should be shown
*
* @return bool
*/
public function isDisplayed()
{
$secureForm = $this->omiseCcConfig->getSecureForm();
return $secureForm == 'yes' ? false : true;
}

/**
* Retrieve system message text
*
* @return \Magento\Framework\Phrase
*/
public function getText()
{
$defaultMessage = "<b>Opn Payments</b> : Update your plugin to the latest version to enable
Secure Form and maximize the security of your customers’ information.
You will need to re-customize the credit card checkout form after the upgrade.
<a target='blank' href='https://www.omise.co/magento-plugin'>
Learn how to enable Secure Form.</a>";

return $this->localize('secure_form_banner_message', $defaultMessage);
}

/**
* Retrieve system message severity
*
* @return int
*/
public function getSeverity()
{
return self::SEVERITY_CRITICAL;
}

/**
* localize using translation key
*
* @param string $key
* @param string $default
* @return string
*/
public function localize($key, $default)
{
$result = __($key);
return $result == $key ? $default : $result;
}
}
73 changes: 73 additions & 0 deletions Block/Adminhtml/System/Config/CardFormCustomization/Theme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Omise\Payment\Block\Adminhtml\System\Config\CardFormCustomization;

class Theme
{
public function getFormDesign($theme, $customDesign)
{
if (!empty($customDesign)) {
$result = json_decode($customDesign, true);
if (!$result) {
return $this->getDefaultFormDesign($theme);
}
return $result;
}
return $this->getDefaultFormDesign($theme);
}

public function getDefaultFormDesign($theme)
{
return (empty($theme) || $theme == 'light')
? $this->getLightTheme()
: $this->getDarkTheme();
}

public function getLightTheme()
{
return [
'font' => [
'name' => 'Poppins',
'size' => 16,
],
'input' => [
'height' => '44px',
'border_radius' => '4px',
'border_color' => '#ced3de',
'active_border_color' => '#1451cc',
'background_color' => '#ffffff',
'label_color' => '#212121',
'text_color' => '#212121',
'placeholder_color' => '#98a1b2',
],
'checkbox' => [
'text_color' => '#1c2433',
'theme_color' => '#1451cc',
]
];
}

public function getDarkTheme()
{
return [
'font' => [
'name' => 'Poppins',
'size' => 16,
],
'input' => [
'height' => '44px',
'border_radius' => '4px',
'border_color' => '#475266',
'active_border_color' => '#475266',
'background_color' => '#131926',
'label_color' => '#E6EAF2',
'text_color' => '#ffffff',
'placeholder_color' => '#DBDBDB',
],
'checkbox' => [
'text_color' => '#E6EAF2',
'theme_color' => '#1451CC',
]
];
}
}
Loading

0 comments on commit 266dfc7

Please sign in to comment.