Skip to content

Commit

Permalink
Init source MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
laptc committed Oct 24, 2018
1 parent d4792a5 commit 09f5531
Show file tree
Hide file tree
Showing 25 changed files with 1,124 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Api/StripeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magestore\WebposStripe\Api;

/**
* Interface StripeInterface
* @package Magestore\WebposStripe\Api
*/
interface StripeInterface
{
/**
* @return bool
*/
public function validateRequiredSDK();

/**
* @param string $key
* @return anyType
*/
public function getConfig($key = '');
}
37 changes: 37 additions & 0 deletions Api/StripeServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magestore\WebposStripe\Api;

/**
* Interface StripeServiceInterface
* @package Magestore\WebposStripe\Api
*/
interface StripeServiceInterface
{
/**
* @return bool
*/
public function isEnable();

/**
* @return string
*/
public function getConfigurationError();

/**
* @return bool
*/
public function canConnectToApi();

/**
* @param string $token
* @param string $amount
* @return string
*/
public function finishPayment($token, $amount);

}
32 changes: 32 additions & 0 deletions Block/Adminhtml/Config/Instruction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magestore\WebposStripe\Block\Adminhtml\Config;


class Instruction extends \Magento\Config\Block\System\Config\Form\Fieldset
{
/**
* {@inheritdoc}
*/
protected function _prepareLayout()
{
$this->addChild('stripe_setup_guide', 'Magestore\WebposStripe\Block\Adminhtml\Config\Setupguide');

return parent::_prepareLayout();
}

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
*
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return $this->getChildHtml('stripe_setup_guide');
}
}
26 changes: 26 additions & 0 deletions Block/Adminhtml/Config/Setupguide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magestore\WebposStripe\Block\Adminhtml\Config;


class Setupguide extends \Magento\Backend\Block\Template
{
/**
* @var string
*/
protected $_template = 'Magestore_WebposStripe::config/setupguide.phtml';

/**
* Get api test url
* @return string
*/
public function getTestApiUrl(){
return $this->getUrl('webposstripe/api/test');
}

}
8 changes: 8 additions & 0 deletions COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Magestore.com
*
* NOTICE OF LICENSE
* This source package is subject to the Magestore.com license that is available through the world-wide-web at this URL: http://www.magestore.com/license-agreement.html
* Please see LICENSE.txt
*
* DISCLAIMER
* Do not edit or add to any file of this package if you wish to upgrade this extension to newer version in the future.
54 changes: 54 additions & 0 deletions Controller/Adminhtml/AbstractAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magestore\WebposStripe\Controller\Adminhtml;

/**
* Class AbstractAction
* @package Magestore\WebposStripe\Controller\Adminhtml
*/
abstract class AbstractAction extends \Magento\Backend\App\Action
{
/**
* @var \Magestore\WebposStripe\Api\StripeServiceInterface
*/
protected $stripeService;

/**
* @var \Magento\Framework\Controller\ResultFactory
*/
protected $resultFactory;

/**
* @var \Magestore\WebposStripe\Helper\Data
*/
protected $helper;

/**
* AbstractAction constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param \Magestore\WebposStripe\Api\StripeServiceInterface $stripeService
* @param \Magestore\WebposStripe\Helper\Data $helper
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magestore\WebposStripe\Api\StripeServiceInterface $stripeService,
\Magestore\WebposStripe\Helper\Data $helper
){
parent::__construct($context);
$this->stripeService = $stripeService;
$this->helper = $helper;
$this->resultFactory = $context->getResultFactory();
}

/**
* @param $data
* @return mixed
*/
public function createJsonResult($data){
$resultJson = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON);
return $resultJson->setData($data);
}
}
36 changes: 36 additions & 0 deletions Controller/Adminhtml/Api/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magestore\WebposStripe\Controller\Adminhtml\Api;

/**
* Class Test
* @package Magestore\WebposStripe\Controller\Adminhtml\Api
*/
class Test extends \Magestore\WebposStripe\Controller\Adminhtml\AbstractAction
{
/**
* @return \Magento\Framework\Controller\Result\Json $resultJson
*/
public function execute()
{
$response = [
'url' => '',
'message' => '',
'success' => true
];
$isEnable = $this->stripeService->isEnable();
if ($isEnable) {
$connected = $this->stripeService->canConnectToApi();
$response['success'] = ($connected) ? true : false;
$response['message'] = ($connected) ? '' : __('Connection failed. Please contact admin to check the configuration of API.');
} else {
$message = $this->stripeService->getConfigurationError();
$response['success'] = false;
$response['message'] = __($message);
}
return $this->createJsonResult($response);
}
}
97 changes: 97 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* Copyright © 2018 Magestore. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magestore\WebposStripe\Helper;

/**
* Class Data
* @package Magestore\WebposStripe\Helper
*/
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;

/**
*
* @var \Magento\Framework\App\ObjectManager
*/
protected $_objectManager;

/**
* Data constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager
){
$this->_storeManager = $storeManager;
$this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
parent::__construct($context);
}

/**
* get store
*
* @return \Magento\Store\Api\Data\StoreInterface
*/
public function getStore(){
return $this->_storeManager->getStore();
}

/**
* get store config
*
* @param string $path
* @return string
*/
public function getStoreConfig($path){
return $this->scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* @return array
*/
public function getStripeConfig() {
$configData = array();
$configItems = array(
'enable',
'sort_order',
'publishable_key',
'api_key'
);
foreach ($configItems as $configItem) {
$configData[$configItem] = $this->getStoreConfig('webpos/payment/stripe/' . $configItem);
}
return $configData;
}

/**
* @return bool
*/
public function isEnableStripe(){
$enable = $this->getStoreConfig('webpos/payment/stripe/enable');
return ($enable == 1)?true:false;
}

/**
* @param $currency
* @return bool
*/
public function isZeroDecimal($currency)
{
return in_array(strtolower($currency), array(
'bif', 'djf', 'jpy', 'krw', 'pyg', 'vnd', 'xaf',
'xpf', 'clp', 'gnf', 'kmf', 'mga', 'rwf', 'vuv', 'xof'));
}

}
Loading

0 comments on commit 09f5531

Please sign in to comment.