-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
|
||
} |
Oops, something went wrong.