-
Notifications
You must be signed in to change notification settings - Fork 3
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
Simon Schurter
committed
Jul 10, 2019
1 parent
d944548
commit 72352f3
Showing
14 changed files
with
199 additions
and
45 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
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
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
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,83 @@ | ||
<?php | ||
/** | ||
* PostFinance Checkout Magento 2 | ||
* | ||
* This Magento 2 extension enables to process payments with PostFinance Checkout (https://www.postfinance.ch/). | ||
* | ||
* @package PostFinanceCheckout_Payment | ||
* @author customweb GmbH (http://www.customweb.com/) | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License (ASL 2.0) | ||
*/ | ||
namespace PostFinanceCheckout\Payment\Observer; | ||
|
||
use Magento\Customer\Model\Customer; | ||
use Magento\Customer\Model\CustomerRegistry; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Observer to collect the customer's meta data for the transaction. | ||
*/ | ||
class CollectCustomerMetaData implements ObserverInterface | ||
{ | ||
|
||
/** | ||
* | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* | ||
* @var CustomerRegistry | ||
*/ | ||
private $customerRegistry; | ||
|
||
/** | ||
* | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param CustomerRegistry $customerRegistry | ||
*/ | ||
public function __construct(ScopeConfigInterface $scopeConfig, CustomerRegistry $customerRegistry) | ||
{ | ||
$this->scopeConfig = $scopeConfig; | ||
$this->customerRegistry = $customerRegistry; | ||
} | ||
|
||
public function execute(Observer $observer) | ||
{ | ||
/* @var \Magento\Sales\Model\Order $order */ | ||
$order = $observer->getOrder(); | ||
$transport = $observer->getTransport(); | ||
|
||
$transport->setData('metaData', | ||
\array_merge($transport->getData('metaData'), | ||
$this->collectCustomerMetaData($this->customerRegistry->retrieve($order->getCustomerId())))); | ||
} | ||
|
||
/** | ||
* Collects the data that is to be transmitted to the gateway as transaction meta data. | ||
* | ||
* @param Customer $customer | ||
* @return array | ||
*/ | ||
protected function collectCustomerMetaData(Customer $customer) | ||
{ | ||
$metaData = []; | ||
$attributeCodesConfig = $this->scopeConfig->getValue( | ||
'postfinancecheckout_payment/meta_data/customer_attributes', ScopeInterface::SCOPE_STORE, | ||
$customer->getStoreId()); | ||
if (! empty($attributeCodesConfig)) { | ||
$attributeCodes = \explode(',', $attributeCodesConfig); | ||
foreach ($attributeCodes as $attributeCode) { | ||
$value = $customer->getData($attributeCode); | ||
if ($value !== null && $value !== "" && $value !== false) { | ||
$metaData['customer_' . $attributeCode] = $value; | ||
} | ||
} | ||
} | ||
return $metaData; | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
/** | ||
* PostFinance Checkout Magento 2 | ||
* | ||
* This Magento 2 extension enables to process payments with PostFinance Checkout (https://www.postfinance.ch/). | ||
* | ||
* @package PostFinanceCheckout_Payment | ||
* @author customweb GmbH (http://www.customweb.com/) | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License (ASL 2.0) | ||
*/ | ||
namespace PostFinanceCheckout\Payment\Observer; | ||
|
||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\Module\Manager as ModuleManager; | ||
use Magento\Sales\Model\Order; | ||
|
||
/** | ||
* Observer to collect the order attribute meta data for the transaction. | ||
*/ | ||
class CollectOrderAttributeMetaData implements ObserverInterface | ||
{ | ||
|
||
/** | ||
* | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* | ||
* @var ModuleManager | ||
*/ | ||
private $moduleManager; | ||
|
||
/** | ||
* | ||
* @param ObjectManagerInterface $objectManager | ||
* @param ModuleManager $moduleManager | ||
*/ | ||
public function __construct(ObjectManagerInterface $objectManager, ModuleManager $moduleManager) | ||
{ | ||
$this->objectManager = $objectManager; | ||
$this->moduleManager = $moduleManager; | ||
} | ||
|
||
public function execute(Observer $observer) | ||
{ | ||
/* @var \Magento\Sales\Model\Order $order */ | ||
$order = $observer->getOrder(); | ||
$transport = $observer->getTransport(); | ||
|
||
if ($this->moduleManager->isEnabled('Amasty_Orderattr')) { | ||
$transport->setData('metaData', | ||
\array_merge($transport->getData('metaData'), $this->collectOrderAttributeMetaData($order))); | ||
} | ||
} | ||
|
||
/** | ||
* Collects the data that is to be transmitted to the gateway as transaction meta data. | ||
* | ||
* @param Order $order | ||
* @return array | ||
*/ | ||
protected function collectOrderAttributeMetaData(Order $order) | ||
{ | ||
$metaData = []; | ||
/* @var \Amasty\Orderattr\Model\ResourceModel\Attribute\Collection $attributeCollection */ | ||
$attributeCollection = $this->objectManager->get( | ||
'Amasty\Orderattr\Model\ResourceModel\Attribute\CollectionFactory')->create(); | ||
$attributeCollection->addFieldToSelect('attribute_code'); | ||
$attributeCollection->addFieldToSelect('frontend_label'); | ||
foreach ($attributeCollection->getData() as $attribute) { | ||
$metaData['order_' . $attribute['attribute_code']] = $order->getData($attribute['attribute_code']); | ||
} | ||
return $metaData; | ||
} | ||
} |
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
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
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
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
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
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
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
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
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