Skip to content
This repository has been archived by the owner on Aug 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13 from innoppl-developers/master
Browse files Browse the repository at this point in the history
M2 plugin converted to support magento marketplace
  • Loading branch information
Pieter Poorthuis authored Apr 11, 2017
2 parents 98e82a5 + 59f4313 commit d827c68
Show file tree
Hide file tree
Showing 52 changed files with 107 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions app/code/Bitpay/Core/Block/Iframe.php → Block/Iframe.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,4 @@ public function isTestMode() {
return false;
}






}
8 changes: 4 additions & 4 deletions app/code/Bitpay/Core/Block/Info.php → Block/Info.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 10 additions & 4 deletions ...code/Bitpay/Core/Controller/Ipn/Index.php → Controller/Ipn/Index.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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') {
Expand Down
13 changes: 7 additions & 6 deletions app/code/Bitpay/Core/Helper/Data.php → Helper/Data.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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!');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ...Core/Model/Config/Backend/PairingCode.php → Model/Config/Backend/PairingCode.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions app/code/Bitpay/Core/Model/Invoice.php → Model/Invoice.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions app/code/Bitpay/Core/Model/Ipn.php → Model/Ipn.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
62 changes: 62 additions & 0 deletions Model/MagentoStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
namespace Bitpay\Core\Model;

class MagentoStorage implements \Bitpay\Storage\StorageInterface {
/**
* @var array
*/
protected $_keys;

/**
* @inheritdoc
*/
public function persist(\Bitpay\KeyInterface $key) {
$this -> _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;
}

}
14 changes: 5 additions & 9 deletions ...code/Bitpay/Core/Model/Method/Bitcoin.php → Model/Method/Bitcoin.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 0 additions & 27 deletions app/code/Bitpay/Core/composer.json

This file was deleted.

6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@
"build/",
"build.xml"
]
},
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Bitpay\\Core\\": ""
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d827c68

Please sign in to comment.