From 59f4313fc990ac211f4ac1e8c12fc5fd9b328281 Mon Sep 17 00:00:00 2001 From: Gopinath Date: Mon, 10 Apr 2017 20:08:50 +0530 Subject: [PATCH] M2 plugin converted to support magento marketplace --- .../System/Config/Form/Field/Extension.php | 4 +- .../Core/Block => Block}/Form/Bitpay.php | 0 .../Bitpay/Core/Block => Block}/Iframe.php | 5 -- .../code/Bitpay/Core/Block => Block}/Info.php | 8 +- .../Iframe/Index.php | 0 .../Controller => Controller}/Index/Index.php | 0 .../Invoice/Index.php | 0 .../Controller => Controller}/Ipn/Index.php | 14 +++- .../Bitpay/Core/Helper => Helper}/Data.php | 13 ++-- .../Bitpay/Core/Logger => Logger}/Handler.php | 0 .../Bitpay/Core/Logger => Logger}/Logger.php | 0 .../Bitpay/Core/Model => Model}/Config.php | 0 .../Config/Backend/PairingCode.php | 2 +- .../Model => Model}/Config/Source/Network.php | 0 .../Config/Source/TransactionSpeed.php | 0 .../Core/Model => Model}/ConfigProvider.php | 0 .../Bitpay/Core/Model => Model}/Invoice.php | 12 +-- {app/code/Bitpay/Core/Model => Model}/Ipn.php | 4 +- Model/MagentoStorage.php | 62 ++++++++++++++++ .../Core/Model => Model}/Method/Bitcoin.php | 14 ++-- .../Core/Model => Model}/Order/Payment.php | 0 .../Order/Payment/State/AuthorizeCommand.php | 0 .../Model => Model}/ResourceModel/Invoice.php | 0 .../ResourceModel/Invoice/Collection.php | 0 .../Model => Model}/ResourceModel/Ipn.php | 0 .../ResourceModel/Ipn/Collection.php | 0 .../Observer => Observer}/Bitpayemail.php | 0 .../Core/Setup => Setup}/InstallSchema.php | 0 .../Core/Setup => Setup}/UpgradeSchema.php | 0 app/code/Bitpay/Core/composer.json | 27 ------- composer.json | 6 ++ .../Core/etc => etc}/adminhtml/system.xml | 0 {app/code/Bitpay/Core/etc => etc}/config.xml | 0 {app/code/Bitpay/Core/etc => etc}/di.xml | 0 .../Bitpay/Core/etc => etc}/frontend/di.xml | 0 .../Core/etc => etc}/frontend/events.xml | 0 .../Core/etc => etc}/frontend/routes.xml | 0 {app/code/Bitpay/Core/etc => etc}/module.xml | 0 {app/code/Bitpay/Core/etc => etc}/payment.xml | 0 .../Bitpay/Storage/MagentoStorage.php | 73 ------------------- .../Core/registration.php => registration.php | 0 .../templates/bitpay/info/default.phtml | 2 +- .../frontend/layout/bitpay_invoice_index.xml | 0 .../frontend/layout/checkout_index_index.xml | 0 .../templates/bitpay/form/bitpay.phtml | 2 +- .../frontend/templates/bitpay/iframe.phtml | 0 .../templates/bitpay/info/default.phtml | 0 .../frontend/templates/bitpay/json.phtml | 0 .../web/js/action/set-payment-method.js | 0 .../frontend/web/js/view/payment/bitpay.js | 0 .../js/view/payment/method-renderer/bitpay.js | 0 .../frontend/web/template/payment/bitpay.html | 0 52 files changed, 107 insertions(+), 141 deletions(-) rename {app/code/Bitpay/Core/Block => Block}/Adminhtml/System/Config/Form/Field/Extension.php (82%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Block => Block}/Form/Bitpay.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Block => Block}/Iframe.php (99%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Block => Block}/Info.php (76%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Controller => Controller}/Iframe/Index.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Controller => Controller}/Index/Index.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Controller => Controller}/Invoice/Index.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Controller => Controller}/Ipn/Index.php (95%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Helper => Helper}/Data.php (97%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Logger => Logger}/Handler.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Logger => Logger}/Logger.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Config.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Config/Backend/PairingCode.php (94%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Config/Source/Network.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Config/Source/TransactionSpeed.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/ConfigProvider.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Invoice.php (91%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Ipn.php (95%) mode change 100755 => 100644 create mode 100644 Model/MagentoStorage.php rename {app/code/Bitpay/Core/Model => Model}/Method/Bitcoin.php (96%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/Order/Payment.php (100%) rename {app/code/Bitpay/Core/Model => Model}/Order/Payment/State/AuthorizeCommand.php (100%) rename {app/code/Bitpay/Core/Model => Model}/ResourceModel/Invoice.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/ResourceModel/Invoice/Collection.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/ResourceModel/Ipn.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Model => Model}/ResourceModel/Ipn/Collection.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Observer => Observer}/Bitpayemail.php (100%) rename {app/code/Bitpay/Core/Setup => Setup}/InstallSchema.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/Setup => Setup}/UpgradeSchema.php (100%) mode change 100755 => 100644 delete mode 100755 app/code/Bitpay/Core/composer.json rename {app/code/Bitpay/Core/etc => etc}/adminhtml/system.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/etc => etc}/config.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/etc => etc}/di.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/etc => etc}/frontend/di.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/etc => etc}/frontend/events.xml (100%) rename {app/code/Bitpay/Core/etc => etc}/frontend/routes.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/etc => etc}/module.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/etc => etc}/payment.xml (100%) mode change 100755 => 100644 delete mode 100755 lib/internal/Bitpay/Storage/MagentoStorage.php rename app/code/Bitpay/Core/registration.php => registration.php (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/adminhtml/templates/bitpay/info/default.phtml (90%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/layout/bitpay_invoice_index.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/layout/checkout_index_index.xml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/templates/bitpay/form/bitpay.phtml (94%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/templates/bitpay/iframe.phtml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/templates/bitpay/info/default.phtml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/templates/bitpay/json.phtml (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/web/js/action/set-payment-method.js (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/web/js/view/payment/bitpay.js (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/web/js/view/payment/method-renderer/bitpay.js (100%) mode change 100755 => 100644 rename {app/code/Bitpay/Core/view => view}/frontend/web/template/payment/bitpay.html (100%) mode change 100755 => 100644 diff --git a/app/code/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php b/Block/Adminhtml/System/Config/Form/Field/Extension.php old mode 100755 new mode 100644 similarity index 82% rename from app/code/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php rename to Block/Adminhtml/System/Config/Form/Field/Extension.php index 747dd71..e70ecb1 --- a/app/code/Bitpay/Core/Block/Adminhtml/System/Config/Form/Field/Extension.php +++ b/Block/Adminhtml/System/Config/Form/Field/Extension.php @@ -23,8 +23,8 @@ protected function _getElementHtml(AbstractElement $element) { if (false === isset($element) || true === empty($element)) { $helper = \Magento\Framework\App\ObjectManager::getInstance()->get('Bitpay\Core\Helper\Data'); - $helper->debugData('[ERROR] In Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Extension::_getElementHtml(): Missing or invalid $element parameter passed to function.'); - throw new \Exception('In Bitpay_Core_Block_Adminhtml_System_Config_Form_Field_Extension::_getElementHtml(): Missing or invalid $element parameter passed to function.'); + $helper->debugData('[ERROR] In Bitpay\Core\Block\Adminhtml\System\Config\Form\Field\Extension::_getElementHtml(): Missing or invalid $element parameter passed to function.'); + throw new \Exception('In Bitpay\Core\Block\Adminhtml\System\Config\Form\Field\Extension::_getElementHtml(): Missing or invalid $element parameter passed to function.'); } $config = $element->getFieldConfig(); diff --git a/app/code/Bitpay/Core/Block/Form/Bitpay.php b/Block/Form/Bitpay.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Block/Form/Bitpay.php rename to Block/Form/Bitpay.php diff --git a/app/code/Bitpay/Core/Block/Iframe.php b/Block/Iframe.php old mode 100755 new mode 100644 similarity index 99% rename from app/code/Bitpay/Core/Block/Iframe.php rename to Block/Iframe.php index 67d938b..d0296f5 --- a/app/code/Bitpay/Core/Block/Iframe.php +++ b/Block/Iframe.php @@ -82,9 +82,4 @@ public function isTestMode() { return false; } - - - - - } diff --git a/app/code/Bitpay/Core/Block/Info.php b/Block/Info.php old mode 100755 new mode 100644 similarity index 76% rename from app/code/Bitpay/Core/Block/Info.php rename to Block/Info.php index 2f11b54..152a8b9 --- a/app/code/Bitpay/Core/Block/Info.php +++ b/Block/Info.php @@ -23,15 +23,15 @@ public function getBitpayInvoiceUrl() $bitpayModelInvoice = \Magento\Framework\App\ObjectManager::getInstance()->get('\Bitpay\Core\Model\Invoice'); if (false === isset($order) || true === empty($order)) { - $bitpayHelper->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); - throw new \Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the order.'); + $bitpayHelper->debugData('[ERROR] In Bitpay\Core\Block\Info::getBitpayInvoiceUrl(): could not obtain the order.'); + throw new \Exception('In Bitpay\Core\Block\Info::getBitpayInvoiceUrl(): could not obtain the order.'); } $incrementId = $order->getIncrementId(); if (false === isset($incrementId) || true === empty($incrementId)) { - $bitpayHelper->debugData('[ERROR] In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); - throw new \Exception('In Bitpay_Core_Block_Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); + $bitpayHelper->debugData('[ERROR] In Bitpay\Core\Block\Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); + throw new \Exception('In Bitpay\Core\Block\Info::getBitpayInvoiceUrl(): could not obtain the incrementId.'); } $bitpayInvoice = $bitpayModelInvoice->load($incrementId, 'increment_id'); diff --git a/app/code/Bitpay/Core/Controller/Iframe/Index.php b/Controller/Iframe/Index.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Controller/Iframe/Index.php rename to Controller/Iframe/Index.php diff --git a/app/code/Bitpay/Core/Controller/Index/Index.php b/Controller/Index/Index.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Controller/Index/Index.php rename to Controller/Index/Index.php diff --git a/app/code/Bitpay/Core/Controller/Invoice/Index.php b/Controller/Invoice/Index.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Controller/Invoice/Index.php rename to Controller/Invoice/Index.php diff --git a/app/code/Bitpay/Core/Controller/Ipn/Index.php b/Controller/Ipn/Index.php old mode 100755 new mode 100644 similarity index 95% rename from app/code/Bitpay/Core/Controller/Ipn/Index.php rename to Controller/Ipn/Index.php index 290145a..2f8224f --- a/app/code/Bitpay/Core/Controller/Ipn/Index.php +++ b/Controller/Ipn/Index.php @@ -17,13 +17,15 @@ class Index extends \Magento\Framework\App\Action\Action { protected $_orderModel; protected $_bitpayInvoiceModel; + protected $_bitpayPaymentModel; - public function __construct(\Magento\Framework\App\Action\Context $context, \Bitpay\Core\Helper\Data $_bitpayHelper, \Bitpay\Core\Model\Ipn $_bitpayModel, \Magento\Sales\Model\Order $_orderModel, \Bitpay\Core\Model\Invoice $_bitpayInvoiceModel) { + public function __construct(\Magento\Framework\App\Action\Context $context, \Bitpay\Core\Helper\Data $_bitpayHelper, \Bitpay\Core\Model\Ipn $_bitpayModel, \Magento\Sales\Model\Order $_orderModel, \Bitpay\Core\Model\Invoice $_bitpayInvoiceModel, \Bitpay\Core\Model\Order\Payment $_bitpayPaymentModel) { parent::__construct($context); $this -> _bitpayHelper = $_bitpayHelper; $this -> _bitpayModel = $_bitpayModel; $this -> _orderModel = $_orderModel; $this -> _bitpayInvoiceModel = $_bitpayInvoiceModel; + $this -> _bitpayPaymentModel = $_bitpayPaymentModel; } /** @@ -132,10 +134,14 @@ public function execute() { // Update the order to notifiy that it has been paid $transactionSpeed = \Magento\Framework\App\ObjectManager::getInstance() -> create('Magento\Framework\App\Config\ScopeConfigInterface') -> getValue('payment/bitpay/speed'); - $this -> _bitpayHelper -> debugData('am here'.$ipn -> status); + if ($ipn -> status === 'paid' || $ipn -> status === 'confirmed') { - - $payment = \Magento\Framework\App\ObjectManager::getInstance() -> create('Magento\Sales\Model\Order\Payment') -> setOrder($order); + try{ + $payment = $this -> _bitpayPaymentModel-> setOrder($order); + } + catch(\Exception $e){ + $this -> _bitpayHelper -> debugData("[ERROR] In \Bitpay\Core\Controller\Ipn::indexAction():".$e->getMessage()); + } if (true === isset($payment) && false === empty($payment)) { if ($ipn -> status === 'confirmed') { diff --git a/app/code/Bitpay/Core/Helper/Data.php b/Helper/Data.php old mode 100755 new mode 100644 similarity index 97% rename from app/code/Bitpay/Core/Helper/Data.php rename to Helper/Data.php index d25cceb..7bdce81 --- a/app/code/Bitpay/Core/Helper/Data.php +++ b/Helper/Data.php @@ -20,6 +20,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper protected $_directory_list; protected $logger; protected $config; + protected $magento_st; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface @@ -29,13 +30,14 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper /** * @param \Magento\Framework\App\Helper\Context $context */ - public function __construct(\Magento\Framework\App\Helper\Context $context,\Bitpay\Core\Model\Method\Bitcoin $bitpayModel,\Magento\Framework\App\Filesystem\DirectoryList $directory_list,\Bitpay\Core\Logger\Logger $logger,\Magento\Config\Model\ResourceModel\Config $config) + public function __construct(\Magento\Framework\App\Helper\Context $context,\Bitpay\Core\Model\Method\Bitcoin $bitpayModel,\Magento\Framework\App\Filesystem\DirectoryList $directory_list,\Bitpay\Core\Logger\Logger $logger,\Magento\Config\Model\ResourceModel\Config $config, \Bitpay\Core\Model\MagentoStorage $magento_st) { $this->_bitpayModel = $bitpayModel; $this->directory_list = $directory_list; $this->logger = $logger; $this->config = $config; + $this->magento_st=$magento_st; parent::__construct($context); } @@ -44,9 +46,8 @@ public function __construct(\Magento\Framework\App\Helper\Context $context,\Bitp */ public function debugData($debugData) { - if (true === isset($debugData) && false === empty($debugData)) { + if($this->isDebug() && !empty($debugData)) $this->logger->debug($debugData); - } } /** @@ -96,8 +97,8 @@ public function getRedirectUrl() public function registerAutoloader() { if (true === empty($this->_autoloaderRegistered)) { - $base = $this->directory_list->getPath('lib_internal'); - $autoloader_filename = $base.'/Bitpay/Autoloader.php'; + $base = $this->directory_list->getRoot(); + $autoloader_filename = $base.'/vendor/bitpay/php-client/src/Bitpay/Autoloader.php'; if (true === is_file($autoloader_filename) && true === is_readable($autoloader_filename)) { require_once $autoloader_filename; \Bitpay\Autoloader::register(); @@ -345,7 +346,7 @@ public function getKeyManager() $this->registerAutoloader(); } - $this->_keyManager = new \Bitpay\KeyManager(new \Bitpay\Storage\MagentoStorage()); + $this->_keyManager = new \Bitpay\KeyManager($this->magento_st); if (false === isset($this->_keyManager) || true === empty($this->_keyManager)) { $this->debugData('[ERROR] In \Bitpay\Core\Helper\Data::getKeyManager(): could not create new BitPay KeyManager object. Cannot continue!'); diff --git a/app/code/Bitpay/Core/Logger/Handler.php b/Logger/Handler.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Logger/Handler.php rename to Logger/Handler.php diff --git a/app/code/Bitpay/Core/Logger/Logger.php b/Logger/Logger.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Logger/Logger.php rename to Logger/Logger.php diff --git a/app/code/Bitpay/Core/Model/Config.php b/Model/Config.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/Config.php rename to Model/Config.php diff --git a/app/code/Bitpay/Core/Model/Config/Backend/PairingCode.php b/Model/Config/Backend/PairingCode.php old mode 100755 new mode 100644 similarity index 94% rename from app/code/Bitpay/Core/Model/Config/Backend/PairingCode.php rename to Model/Config/Backend/PairingCode.php index eb036e2..f06185a --- a/app/code/Bitpay/Core/Model/Config/Backend/PairingCode.php +++ b/Model/Config/Backend/PairingCode.php @@ -50,7 +50,7 @@ public function save() return; } - $this->helper->debugData('[INFO] In Bitpay_Core_Model_Config_PairingCode::save(): attempting to pair with BitPay with pairing code ' . $pairingCode); + $this->helper->debugData('[INFO] In Bitpay\Core\Model\Config\PairingCode::save(): attempting to pair with BitPay with pairing code ' . $pairingCode); try { $this->helper->sendPairingRequest($pairingCode); } catch (\Exception $e) { diff --git a/app/code/Bitpay/Core/Model/Config/Source/Network.php b/Model/Config/Source/Network.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/Config/Source/Network.php rename to Model/Config/Source/Network.php diff --git a/app/code/Bitpay/Core/Model/Config/Source/TransactionSpeed.php b/Model/Config/Source/TransactionSpeed.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/Config/Source/TransactionSpeed.php rename to Model/Config/Source/TransactionSpeed.php diff --git a/app/code/Bitpay/Core/Model/ConfigProvider.php b/Model/ConfigProvider.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/ConfigProvider.php rename to Model/ConfigProvider.php diff --git a/app/code/Bitpay/Core/Model/Invoice.php b/Model/Invoice.php old mode 100755 new mode 100644 similarity index 91% rename from app/code/Bitpay/Core/Model/Invoice.php rename to Model/Invoice.php index cc4ffff..119100e --- a/app/code/Bitpay/Core/Model/Invoice.php +++ b/Model/Invoice.php @@ -52,8 +52,8 @@ public function prepareWithBitpayInvoice($invoice,$order) $objectmanager = \Magento\Framework\App\ObjectManager::getInstance(); $helper = $objectmanager->get('\Bitpay\Core\Helper\Data'); if (false === isset($invoice) || true === empty($invoice)) { - $helper->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); - throw new \Exception('In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + $helper->debugData('[ERROR] In Bitpay\Core\Model\Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + throw new \Exception('In Bitpay\Core\Model\Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); } $objectmanager->create('\Bitpay\Core\Model\Invoice')->setData( array( @@ -75,8 +75,8 @@ public function prepareWithBitpayInvoice($invoice,$order) ); if (false === isset($order) || true === empty($order)) { - $helper->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); - throw new \Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + $helper->debugData('[ERROR] In Bitpay\Core\Model\Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + throw new \Exception('In Bitpay\Core\Model\Invoice::prepateWithOrder(): Missing or empty $order parameter.'); } $this->setData( @@ -99,8 +99,8 @@ public function prepareWithOrder($order) $objectmanager = \Magento\Framework\App\ObjectManager::getInstance(); $helper = $objectmanager->get('\Bitpay\Core\Helper\Data'); if (false === isset($order) || true === empty($order)) { - $helper->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); - throw new \Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + $helper->debugData('[ERROR] In Bitpay\Core\Model\Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + throw new \Exception('In Bitpay\Core\Model\Invoice::prepateWithOrder(): Missing or empty $order parameter.'); } $this->setData( diff --git a/app/code/Bitpay/Core/Model/Ipn.php b/Model/Ipn.php old mode 100755 new mode 100644 similarity index 95% rename from app/code/Bitpay/Core/Model/Ipn.php rename to Model/Ipn.php index 2857dff..616dd30 --- a/app/code/Bitpay/Core/Model/Ipn.php +++ b/Model/Ipn.php @@ -59,14 +59,14 @@ function GetStatusReceived($quoteId, $statuses) { $order = $objectmanager -> get('\Magento\Sales\Model\Order') -> load($quoteId, 'quote_id'); if (!$order) { - $objectmanager -> get('\Bitpay\Core\Helper\Data') -> debugData('[DEBUG] Bitpay_Core_Model_Ipn::GetStatusReceived(), order not found for quoteId'); + $objectmanager -> get('\Bitpay\Core\Helper\Data') -> debugData('[DEBUG] Bitpay\Core\Model\Ipn::GetStatusReceived(), order not found for quoteId'); return false; } $orderIncrementId = $order -> getIncrementId(); if (false === isset($orderIncrementId) || true === empty($orderIncrementId)) { - $objectmanager -> get('\Bitpay\Core\Helper\Data') -> debugData('[DEBUG] Bitpay_Core_Model_Ipn::GetStatusReceived(), orderId not found for quoteId' . $orderIncrementId); + $objectmanager -> get('\Bitpay\Core\Helper\Data') -> debugData('[DEBUG] Bitpay\Core\Model\Ipn::GetStatusReceived(), orderId not found for quoteId' . $orderIncrementId); return false; } $collection = $objectmanager->create('\Bitpay\Core\Model\Ipn')->getCollection();//$this -> _ipnCollectionFactory -> load(); diff --git a/Model/MagentoStorage.php b/Model/MagentoStorage.php new file mode 100644 index 0000000..e60ef8f --- /dev/null +++ b/Model/MagentoStorage.php @@ -0,0 +1,62 @@ + _keys[$key -> getId()] = $key; + + $data = serialize($key); + + $encryptedData = \Magento\Framework\App\ObjectManager::getInstance() -> get('\Magento\Framework\Encryption\EncryptorInterface') -> encrypt($data); + $config = \Magento\Framework\App\ObjectManager::getInstance() -> get('\Magento\Config\Model\ResourceModel\Config'); + $store = \Magento\Framework\App\ObjectManager::getInstance() -> get('\Magento\Store\Model\StoreManagerInterface'); + $helper = \Magento\Framework\App\ObjectManager::getInstance() -> get('\Bitpay\Core\Helper\Data'); + + if (true === isset($config) && false === empty($config)) { + $config -> saveConfig($key -> getId(), $encryptedData, $store -> getStore() -> getCode(), 0); + } else { + $helper -> debugData('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); + throw new \Exception('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); + } + } + + /** + * @inheritdoc + */ + public function load($id) { + if (true === isset($id) && true === isset($this -> _keys[$id])) { + return $this -> _keys[$id]; + } + $helper = \Magento\Framework\App\ObjectManager::getInstance() -> get('\Bitpay\Core\Helper\Data'); + $storeconfig = \Magento\Framework\App\ObjectManager::getInstance() -> get('\Magento\Framework\App\Config\ScopeConfigInterface'); + $entity = $storeconfig -> getValue($id); + + /** + * Not in database + */ + if (false === isset($entity) || true === empty($entity)) { + $helper -> debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); + throw new \Exception('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); + } + + $decodedEntity = unserialize(\Magento\Framework\App\ObjectManager::getInstance() -> get('\Magento\Framework\Encryption\EncryptorInterface') -> decrypt($entity)); + + if (false === isset($decodedEntity) || true === empty($decodedEntity)) { + $helper -> debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); + throw new \Exception('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); + } + + $helper -> debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' successfully decrypted & unserialized the entity ' . $entity . '.'); + + return $decodedEntity; + } + +} diff --git a/app/code/Bitpay/Core/Model/Method/Bitcoin.php b/Model/Method/Bitcoin.php old mode 100755 new mode 100644 similarity index 96% rename from app/code/Bitpay/Core/Model/Method/Bitcoin.php rename to Model/Method/Bitcoin.php index 85f335a..6a38502 --- a/app/code/Bitpay/Core/Model/Method/Bitcoin.php +++ b/Model/Method/Bitcoin.php @@ -167,7 +167,7 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null) /** * @param Mage_Sales_Model_Order_Payment $payment * @param float $amount - * @return Bitpay_Core_Model_PaymentMethod + * @return Bitpay\Core\Model\PaymentMethod */ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount,$iframe = false) { @@ -207,19 +207,15 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount $order = $payment->getOrder(); - - // $mirrorInvoice = $this->invoiceFactory->create()->prepareWithBitpayInvoice($bitpayInvoice,$order)->save();//->prepareWithOrder(array('increment_id' => $order->getIncrementId(), 'quote_id'=> $quote->getId()));//->save(); - // throw new \Magento\Framework\Exception\LocalizedException("Error Processing Request"); - // $this->getHelper()->debugData(json_encode($mirrorInvoice->getData())); if (false === isset($bitpayInvoice) || true === empty($bitpayInvoice)) { - $this->getHelper()->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); - throw new \Exception('In Bitpay_Core_Model_Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + $this->getHelper()->debugData('[ERROR] In Bitpay\Core\Model\Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); + throw new \Exception('In Bitpay\Core\Model\Invoice::prepareWithBitpayInvoice(): Missing or empty $invoice parameter.'); } if (false === isset($order) || true === empty($order)) { - $this->getHelper()->debugData('[ERROR] In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); - throw new \Exception('In Bitpay_Core_Model_Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + $this->getHelper()->debugData('[ERROR] In Bitpay\Core\Model\Invoice::prepateWithOrder(): Missing or empty $order parameter.'); + throw new \Exception('In Bitpay\Core\Model\Invoice::prepateWithOrder(): Missing or empty $order parameter.'); } $id = $invoice->getId(); diff --git a/app/code/Bitpay/Core/Model/Order/Payment.php b/Model/Order/Payment.php similarity index 100% rename from app/code/Bitpay/Core/Model/Order/Payment.php rename to Model/Order/Payment.php diff --git a/app/code/Bitpay/Core/Model/Order/Payment/State/AuthorizeCommand.php b/Model/Order/Payment/State/AuthorizeCommand.php similarity index 100% rename from app/code/Bitpay/Core/Model/Order/Payment/State/AuthorizeCommand.php rename to Model/Order/Payment/State/AuthorizeCommand.php diff --git a/app/code/Bitpay/Core/Model/ResourceModel/Invoice.php b/Model/ResourceModel/Invoice.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/ResourceModel/Invoice.php rename to Model/ResourceModel/Invoice.php diff --git a/app/code/Bitpay/Core/Model/ResourceModel/Invoice/Collection.php b/Model/ResourceModel/Invoice/Collection.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/ResourceModel/Invoice/Collection.php rename to Model/ResourceModel/Invoice/Collection.php diff --git a/app/code/Bitpay/Core/Model/ResourceModel/Ipn.php b/Model/ResourceModel/Ipn.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/ResourceModel/Ipn.php rename to Model/ResourceModel/Ipn.php diff --git a/app/code/Bitpay/Core/Model/ResourceModel/Ipn/Collection.php b/Model/ResourceModel/Ipn/Collection.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Model/ResourceModel/Ipn/Collection.php rename to Model/ResourceModel/Ipn/Collection.php diff --git a/app/code/Bitpay/Core/Observer/Bitpayemail.php b/Observer/Bitpayemail.php similarity index 100% rename from app/code/Bitpay/Core/Observer/Bitpayemail.php rename to Observer/Bitpayemail.php diff --git a/app/code/Bitpay/Core/Setup/InstallSchema.php b/Setup/InstallSchema.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Setup/InstallSchema.php rename to Setup/InstallSchema.php diff --git a/app/code/Bitpay/Core/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/Setup/UpgradeSchema.php rename to Setup/UpgradeSchema.php diff --git a/app/code/Bitpay/Core/composer.json b/app/code/Bitpay/Core/composer.json deleted file mode 100755 index be80e92..0000000 --- a/app/code/Bitpay/Core/composer.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "magento/module-core", - "description": "N/A", - "require": { - "php": "~5.5.0|~5.6.0|~7.0.0", - "magento/module-config": "100.0.*", - "magento/module-store": "100.0.*", - "magento/module-backend": "100.0.*", - "magento/module-customer": "100.0.*", - "magento/module-cms": "100.0.*", - "magento/framework": "100.0.*" - }, - "type": "magento2-module", - "version": "100.0.2", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Bitpay\\Core\\": "" - } - } -} diff --git a/composer.json b/composer.json index 84bd4cc..41923f0 100644 --- a/composer.json +++ b/composer.json @@ -44,5 +44,11 @@ "build/", "build.xml" ] + }, + "autoload": { + "files": [ "registration.php" ], + "psr-4": { + "Bitpay\\Core\\": "" + } } } diff --git a/app/code/Bitpay/Core/etc/adminhtml/system.xml b/etc/adminhtml/system.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/adminhtml/system.xml rename to etc/adminhtml/system.xml diff --git a/app/code/Bitpay/Core/etc/config.xml b/etc/config.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/config.xml rename to etc/config.xml diff --git a/app/code/Bitpay/Core/etc/di.xml b/etc/di.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/di.xml rename to etc/di.xml diff --git a/app/code/Bitpay/Core/etc/frontend/di.xml b/etc/frontend/di.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/frontend/di.xml rename to etc/frontend/di.xml diff --git a/app/code/Bitpay/Core/etc/frontend/events.xml b/etc/frontend/events.xml similarity index 100% rename from app/code/Bitpay/Core/etc/frontend/events.xml rename to etc/frontend/events.xml diff --git a/app/code/Bitpay/Core/etc/frontend/routes.xml b/etc/frontend/routes.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/frontend/routes.xml rename to etc/frontend/routes.xml diff --git a/app/code/Bitpay/Core/etc/module.xml b/etc/module.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/module.xml rename to etc/module.xml diff --git a/app/code/Bitpay/Core/etc/payment.xml b/etc/payment.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/etc/payment.xml rename to etc/payment.xml diff --git a/lib/internal/Bitpay/Storage/MagentoStorage.php b/lib/internal/Bitpay/Storage/MagentoStorage.php deleted file mode 100755 index 90db233..0000000 --- a/lib/internal/Bitpay/Storage/MagentoStorage.php +++ /dev/null @@ -1,73 +0,0 @@ -_keys[$key->getId()] = $key; - - $data = serialize($key); - - $encryptedData = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Framework\Encryption\EncryptorInterface')->encrypt($data); - $config = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Config\Model\ResourceModel\Config'); - $store = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Store\Model\StoreManagerInterface'); - $helper = \Magento\Framework\App\ObjectManager::getInstance()->get('\Bitpay\Core\Helper\Data'); - - if (true === isset($config) && false === empty($config)) { - $config->saveConfig($key->getId(), $encryptedData, $store->getStore()->getCode(), 0); - } else { - $helper->debugData('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); - throw new \Exception('[ERROR] In file lib/Bitpay/Storage/MagentoStorage.php, class MagentoStorage::persist - Could not instantiate a \Mage_Core_Model_Config object.'); - } - } - - /** - * @inheritdoc - */ - public function load($id) - { - if (true === isset($id) && true === isset($this->_keys[$id])) { - return $this->_keys[$id]; - } - $helper = \Magento\Framework\App\ObjectManager::getInstance()->get('\Bitpay\Core\Helper\Data'); - $storeconfig = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Framework\App\Config\ScopeConfigInterface'); - $entity = $storeconfig->getValue($id); - - /** - * Not in database - */ - if (false === isset($entity) || true === empty($entity)) { - $helper->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); - throw new \Exception('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' did not return the store config parameter because it was not found in the database.'); - } - - $decodedEntity = unserialize(\Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Framework\Encryption\EncryptorInterface')->decrypt($entity)); - - if (false === isset($decodedEntity) || true === empty($decodedEntity)) { - $helper->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); - throw new \Exception('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' could not decrypt & unserialize the entity ' . $entity . '.'); - } - - $helper->debugData('[INFO] Call to MagentoStorage::load($id) with the id of ' . $id . ' successfully decrypted & unserialized the entity ' . $entity . '.'); - - return $decodedEntity; - } -} diff --git a/app/code/Bitpay/Core/registration.php b/registration.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/registration.php rename to registration.php diff --git a/app/code/Bitpay/Core/view/adminhtml/templates/bitpay/info/default.phtml b/view/adminhtml/templates/bitpay/info/default.phtml old mode 100755 new mode 100644 similarity index 90% rename from app/code/Bitpay/Core/view/adminhtml/templates/bitpay/info/default.phtml rename to view/adminhtml/templates/bitpay/info/default.phtml index 2af41e2..776e6c8 --- a/app/code/Bitpay/Core/view/adminhtml/templates/bitpay/info/default.phtml +++ b/view/adminhtml/templates/bitpay/info/default.phtml @@ -5,7 +5,7 @@ */ /** - * @see Bitpay_Core_Block_Info + * @see Bitpay\Core\Block\Info */ echo '

Ordered with BitPay

'; diff --git a/app/code/Bitpay/Core/view/frontend/layout/bitpay_invoice_index.xml b/view/frontend/layout/bitpay_invoice_index.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/layout/bitpay_invoice_index.xml rename to view/frontend/layout/bitpay_invoice_index.xml diff --git a/app/code/Bitpay/Core/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/layout/checkout_index_index.xml rename to view/frontend/layout/checkout_index_index.xml diff --git a/app/code/Bitpay/Core/view/frontend/templates/bitpay/form/bitpay.phtml b/view/frontend/templates/bitpay/form/bitpay.phtml old mode 100755 new mode 100644 similarity index 94% rename from app/code/Bitpay/Core/view/frontend/templates/bitpay/form/bitpay.phtml rename to view/frontend/templates/bitpay/form/bitpay.phtml index cfcc4fb..a7f6a8a --- a/app/code/Bitpay/Core/view/frontend/templates/bitpay/form/bitpay.phtml +++ b/view/frontend/templates/bitpay/form/bitpay.phtml @@ -5,7 +5,7 @@ */ /** - * @see Bitpay_Core_Block_Form_Bitpay + * @see Bitpay\Core\Block\Form\Bitpay */ $_code = $block->getMethodCode(); diff --git a/app/code/Bitpay/Core/view/frontend/templates/bitpay/iframe.phtml b/view/frontend/templates/bitpay/iframe.phtml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/templates/bitpay/iframe.phtml rename to view/frontend/templates/bitpay/iframe.phtml diff --git a/app/code/Bitpay/Core/view/frontend/templates/bitpay/info/default.phtml b/view/frontend/templates/bitpay/info/default.phtml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/templates/bitpay/info/default.phtml rename to view/frontend/templates/bitpay/info/default.phtml diff --git a/app/code/Bitpay/Core/view/frontend/templates/bitpay/json.phtml b/view/frontend/templates/bitpay/json.phtml old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/templates/bitpay/json.phtml rename to view/frontend/templates/bitpay/json.phtml diff --git a/app/code/Bitpay/Core/view/frontend/web/js/action/set-payment-method.js b/view/frontend/web/js/action/set-payment-method.js old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/web/js/action/set-payment-method.js rename to view/frontend/web/js/action/set-payment-method.js diff --git a/app/code/Bitpay/Core/view/frontend/web/js/view/payment/bitpay.js b/view/frontend/web/js/view/payment/bitpay.js old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/web/js/view/payment/bitpay.js rename to view/frontend/web/js/view/payment/bitpay.js diff --git a/app/code/Bitpay/Core/view/frontend/web/js/view/payment/method-renderer/bitpay.js b/view/frontend/web/js/view/payment/method-renderer/bitpay.js old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/web/js/view/payment/method-renderer/bitpay.js rename to view/frontend/web/js/view/payment/method-renderer/bitpay.js diff --git a/app/code/Bitpay/Core/view/frontend/web/template/payment/bitpay.html b/view/frontend/web/template/payment/bitpay.html old mode 100755 new mode 100644 similarity index 100% rename from app/code/Bitpay/Core/view/frontend/web/template/payment/bitpay.html rename to view/frontend/web/template/payment/bitpay.html