Skip to content

Commit

Permalink
Release 1.0.51
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Schurter committed Jul 10, 2019
1 parent d944548 commit 72352f3
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 45 deletions.
26 changes: 0 additions & 26 deletions Model/Service/AbstractTransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
*/
namespace PostFinanceCheckout\Payment\Model\Service;

use Magento\Customer\Model\Customer;
use Magento\Customer\Model\CustomerRegistry;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\Quote;
use Magento\Store\Model\ScopeInterface;
use PostFinanceCheckout\Payment\Api\PaymentMethodConfigurationManagementInterface;
use PostFinanceCheckout\Payment\Helper\Data as Helper;
use PostFinanceCheckout\Payment\Model\ApiClient;
Expand Down Expand Up @@ -245,28 +243,4 @@ protected function getDateOfBirth($dateOfBirth, $customerId)
return \substr($dateOfBirth, 0, 10);
}
}

/**
* 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)
{
$attributeCodesConfig = $this->scopeConfig->getValue(
'postfinancecheckout_payment/meta_data/customer_attributes', ScopeInterface::SCOPE_STORE,
$customer->getStoreId());
if (! empty($attributeCodesConfig)) {
$metaData = [];
$attributeCodes = \explode(',', $attributeCodesConfig);
foreach ($attributeCodes as $attributeCode) {
$value = $customer->getData($attributeCode);
if ($value !== null && $value !== "" && $value !== false) {
$metaData['customer_' . $attributeCode] = $value;
}
}
return $metaData;
}
}
}
31 changes: 23 additions & 8 deletions Model/Service/Order/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
namespace PostFinanceCheckout\Payment\Model\Service\Order;

use Magento\Customer\Model\CustomerRegistry;
use Magento\Framework\DataObject;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Stdlib\CookieManagerInterface;
Expand Down Expand Up @@ -66,9 +68,9 @@ class TransactionService extends AbstractTransactionService

/**
*
* @var CustomerRegistry
* @var ManagerInterface
*/
private $customerRegistry;
private $eventManager;

/**
*
Expand Down Expand Up @@ -99,6 +101,7 @@ class TransactionService extends AbstractTransactionService
* @param ResourceConnection $resource
* @param Helper $helper
* @param ScopeConfigInterface $scopeConfig
* @param ManagerInterface $eventManager
* @param CustomerRegistry $customerRegistry
* @param CartRepositoryInterface $quoteRepository
* @param PaymentMethodConfigurationManagementInterface $paymentMethodConfigurationManagement
Expand All @@ -108,16 +111,16 @@ class TransactionService extends AbstractTransactionService
* @param TransactionInfoRepositoryInterface $transactionInfoRepository
*/
public function __construct(ResourceConnection $resource, Helper $helper, ScopeConfigInterface $scopeConfig,
CustomerRegistry $customerRegistry, CartRepositoryInterface $quoteRepository, TimezoneInterface $timezone,
PaymentMethodConfigurationManagementInterface $paymentMethodConfigurationManagement, ApiClient $apiClient,
CookieManagerInterface $cookieManager, LineItemService $lineItemService,
ManagerInterface $eventManager, CustomerRegistry $customerRegistry, CartRepositoryInterface $quoteRepository,
TimezoneInterface $timezone, PaymentMethodConfigurationManagementInterface $paymentMethodConfigurationManagement,
ApiClient $apiClient, CookieManagerInterface $cookieManager, LineItemService $lineItemService,
TransactionInfoRepositoryInterface $transactionInfoRepository)
{
parent::__construct($resource, $helper, $scopeConfig, $customerRegistry, $quoteRepository, $timezone,
$paymentMethodConfigurationManagement, $apiClient, $cookieManager);
$this->helper = $helper;
$this->scopeConfig = $scopeConfig;
$this->customerRegistry = $customerRegistry;
$this->eventManager = $eventManager;
$this->quoteRepository = $quoteRepository;
$this->lineItemService = $lineItemService;
$this->transactionInfoRepository = $transactionInfoRepository;
Expand Down Expand Up @@ -192,8 +195,6 @@ protected function assembleTransactionDataFromOrder(AbstractTransactionPending $
$transaction->setInvoiceMerchantReference($invoice->getIncrementId());
if (! empty($order->getCustomerId())) {
$transaction->setCustomerId($order->getCustomerId());
$transaction->setMetaData(
$this->collectCustomerMetaData($this->customerRegistry->retrieve($order->getCustomerId())));
}
if ($order->getShippingAddress()) {
$transaction->setShippingMethod(
Expand Down Expand Up @@ -224,6 +225,20 @@ protected function assembleTransactionDataFromOrder(AbstractTransactionPending $
if ($token != null) {
$transaction->setToken($token->getId());
}
$transaction->setMetaData($this->collectMetaData($order));
}

protected function collectMetaData(Order $order)
{
$transport = new DataObject([
'metaData' => []
]);
$this->eventManager->dispatch('postfinancecheckout_payment_collect_meta_data',
[
'transport' => $transport,
'order' => $order
]);
return $transport->getData('metaData');
}

/**
Expand Down
2 changes: 0 additions & 2 deletions Model/Service/Quote/TransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ private function assembleTransactionDataFromQuote(AbstractTransactionPending $tr
$transaction->setLineItems($this->lineItemService->convertQuoteLineItems($quote));
if (! empty($quote->getCustomerId())) {
$transaction->setCustomerId($quote->getCustomerId());
$transaction->setMetaData(
$this->collectCustomerMetaData($this->customerRegistry->retrieve($quote->getCustomerId())));
}
if ($quote->getShippingAddress()) {
$transaction->setShippingMethod(
Expand Down
83 changes: 83 additions & 0 deletions Observer/CollectCustomerMetaData.php
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;
}
}
79 changes: 79 additions & 0 deletions Observer/CollectOrderAttributeMetaData.php
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;
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This repository contains the Magento 2.3 extension that enables to process payme

## Documentation

* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.50/docs/en/documentation.html)
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.51/docs/en/documentation.html)

## License

Please see the [license file](https://github.com/pfpayments/magento-2.3/blob/1.0.50/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/magento-2.3/blob/1.0.51/LICENSE) for more information.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"type" : "magento2-module",
"version" : "1.0.50",
"version" : "1.0.51",
"require" : {
"php": "~7.1.3||~7.2.0",
"magento/framework" : "^102.0.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/magento-2.3/releases/tag/1.0.50/">
<a href="https://github.com/pfpayments/magento-2.3/releases/tag/1.0.51/">
Source
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<resource>PostFinanceCheckout_Payment::config</resource>
<group id="information" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Information</label>
<comment><![CDATA[If you need help setting up the PostFinance Checkout extension, check out the <a href="https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.50/docs/en/documentation.html" target="_blank">documentation</a>.]]></comment>
<comment><![CDATA[If you need help setting up the PostFinance Checkout extension, check out the <a href="https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.51/docs/en/documentation.html" target="_blank">documentation</a>.]]></comment>
<field id="version" translate="label" type="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Module Version</label>
</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<default>
<postfinancecheckout_payment>
<information>
<version>1.0.50</version>
<version>1.0.51</version>
<sdk_version>1.1.15</sdk_version>
</information>
<general>
Expand Down
5 changes: 5 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<observer name="postfinancecheckout_payment_update_manual_task" instance="PostFinanceCheckout\Payment\Observer\UpdateManualTask" />
</event>

<event name="postfinancecheckout_payment_collect_meta_data">
<observer name="postfinancecheckout_payment_collect_customer_meta_data" instance="PostFinanceCheckout\Payment\Observer\CollectCustomerMetaData" />
<observer name="postfinancecheckout_payment_collect_order_attribute_meta_data" instance="PostFinanceCheckout\Payment\Observer\CollectOrderAttributeMetaData" />
</event>

<event name="sales_order_payment_capture">
<observer name="postfinancecheckout_payment_payment_capture" instance="PostFinanceCheckout\Payment\Observer\CapturePayment" />
</event>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="PostFinanceCheckout_Payment" setup_version="1.0.50">
<module name="PostFinanceCheckout_Payment" setup_version="1.0.51">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
2 changes: 1 addition & 1 deletion i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"General","Allgemein"
"Hold Delivery","Lieferung halten"
"ID required","ID erforderlich"
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.50/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Falls Sie Hilfe benötigen beim Einrichten der PostFinance Checkout-Erweiterung, sehen Sie sich die <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.50/docs/en/documentation.html"" target=""_blank"">Dokumentation</a> an."
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.51/docs/en/documentation.html"" target=""_blank"">documentation</a>.","Falls Sie Hilfe benötigen beim Einrichten der PostFinance Checkout-Erweiterung, sehen Sie sich die <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.51/docs/en/documentation.html"" target=""_blank"">Dokumentation</a> an."
"Inactive","Inaktiv"
"Information","Informationen"
"Invoice","Rechnung"
Expand Down
2 changes: 1 addition & 1 deletion i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"General","General"
"Hold Delivery","Hold Delivery"
"ID required","ID required"
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.50/docs/en/documentation.html"" target=""_blank"">documentation</a>.","If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.50/docs/en/documentation.html"" target=""_blank"">documentation</a>."
"If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.51/docs/en/documentation.html"" target=""_blank"">documentation</a>.","If you need help setting up the PostFinance Checkout extension, check out the <a href=""https://plugin-documentation.postfinance-checkout.ch/pfpayments/magento-2.3/1.0.51/docs/en/documentation.html"" target=""_blank"">documentation</a>."
"Inactive","Inactive"
"Information","Information"
"Invoice","Invoice"
Expand Down

0 comments on commit 72352f3

Please sign in to comment.