Skip to content

Commit

Permalink
Merge pull request #50 from collector-bank/feature/oath
Browse files Browse the repository at this point in the history
Feature/oath
  • Loading branch information
kristoffer124 authored Oct 27, 2023
2 parents 1061326 + 381c4bc commit 85926e0
Show file tree
Hide file tree
Showing 41 changed files with 1,822 additions and 113 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "magento2-module",
"description": "Magento 2 Collector Bank Checkout Module",
"require": {
"collector-bank/collector-payment-sdk": "1.0.2",
"collector-bank/collector-checkout-sdk": "^1.0.10",
"collector-bank/collector-payment-sdk": "1.0.3",
"collector-bank/collector-checkout-sdk": "1.0.11",
"php": ">=7.4"
},
"authors": [
Expand Down
9 changes: 6 additions & 3 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ public function synchronize(\Magento\Quote\Model\Quote $quote, $eventName = null
->collectShippingRates();

$checkoutData = $this->acquireCheckoutInformationFromQuote($quote);
$oldFees = $checkoutData->getFees();
$oldCart = $checkoutData->getCart();

$quote = $this->quoteUpdater->setQuoteData($quote, $checkoutData);

$rate = $shippingAddress->getShippingRateByCode($shippingAddress->getShippingMethod());
Expand Down Expand Up @@ -188,7 +187,8 @@ public function initialize(\Magento\Quote\Model\Quote $quote) : \Webbhuset\Colle

$cart = $this->quoteConverter->getCart($quote);

if (!$this->isFallbackDeliveryMethodConfigured()) {
if (!$this->isFallbackDeliveryMethodConfigured()
|| $config->getIsCustomDeliveryAdapter()) {
$fees = $this->quoteConverter->getFees($quote);
} else {
$fees = $this->quoteConverter->getFallbackFees($quote);
Expand Down Expand Up @@ -389,6 +389,9 @@ public function getAdapter($config) : \Webbhuset\CollectorCheckoutSDK\Adapter\Ad
if ($config->getIsMockMode()) {
return new \Webbhuset\CollectorCheckoutSDK\Adapter\MockAdapter($config);
}
if ($config->getIsOath()) {
return new \Webbhuset\CollectorCheckoutSDK\Adapter\CurlWithAccessKey($config);
}

return new \Webbhuset\CollectorCheckoutSDK\Adapter\CurlAdapter($config);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Block/Admin/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ public function isDeliveryCheckoutActive()
{
return $this->config->getIsDeliveryCheckoutActive();
}
}

/**
* @return bool
*/
public function isCustomDeliveryAdapterActive()
{
return (bool) $this->config->getIsCustomDeliveryAdapter();
}
}
61 changes: 61 additions & 0 deletions src/Block/Admin/Form/Field/IconMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);

namespace Webbhuset\CollectorCheckout\Block\Admin\Form\Field;

use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Webbhuset\CollectorCheckout\Block\Admin\Form\Field\Icons as IconFields;

class IconMapper extends AbstractFieldArray
{
/**
* @var IconFields
*/
private $iconRenderer;

/**
* Prepare rendering the new field by adding all the needed columns
*/
protected function _prepareToRender()
{
$this->addColumn('method', [
'label' => __('Shipping methods'),
'renderer' => $this->getIconRenderer()
]);
$this->addColumn('icon', ['label' => __('Icon'), 'class' => 'required-entry']);

$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}

/**
* Prepare existing row data object
*
* @param DataObject $row
* @throws LocalizedException
*/
protected function _prepareArrayRow(DataObject $row): void
{
$options = [];

$row->setData('option_extra_attrs', $options);
}

/**
* @return IconFields
* @throws LocalizedException
*/
private function getIconRenderer()
{
if (!$this->iconRenderer) {
$this->iconRenderer = $this->getLayout()->createBlock(
IconFields::class,
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->iconRenderer;
}
}
47 changes: 47 additions & 0 deletions src/Block/Admin/Form/Field/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);

namespace Webbhuset\CollectorCheckout\Block\Admin\Form\Field;

use Magento\Framework\View\Element\Context;
use Magento\Framework\View\Element\Html\Select;
use Webbhuset\CollectorCheckout\Config\Source\IconsSource;

class Icons extends Select
{
/** @var IconsSource $iconsSource */
private $iconsSource;

public function __construct(
Context $context,
IconsSource $iconsSource,
array $data = []
) {
parent::__construct($context, $data);

$this->iconsSource = $iconsSource;
}

public function setInputName($value)
{
return $this->setName($value);
}

public function setInputId($value)
{
return $this->setId($value);
}

public function _toHtml(): string
{
if (!$this->getOptions()) {
$this->setOptions($this->getSourceOptions());
}
return parent::_toHtml();
}

private function getSourceOptions(): array
{
return $this->iconsSource->toOptionArray();
}
}
31 changes: 24 additions & 7 deletions src/Checkout/Order/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Webbhuset\CollectorCheckout\Checkout\Order;

use Magento\Sales\Api\Data\OrderInterface;
use Webbhuset\CollectorCheckoutSDK\Checkout\Purchase\Result as PurchaseResult;

/**
Expand Down Expand Up @@ -73,6 +74,10 @@ class Manager
*/
protected $config;
protected $carrierManager;
/**
* @var SetOrderStatus
*/
private $setOrderStatus;

/**
* Manager constructor.
Expand All @@ -99,6 +104,7 @@ public function __construct(
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Webbhuset\CollectorCheckout\AdapterFactory $collectorAdapter,
\Magento\Sales\Api\OrderManagementInterface $orderManagement,
\Webbhuset\CollectorCheckout\Checkout\Order\SetOrderStatus $setOrderStatus,
\Webbhuset\CollectorCheckout\Config\OrderConfigFactory $configFactory,
\Magento\Quote\Model\QuoteManagement $quoteManagement,
\Webbhuset\CollectorCheckout\Checkout\Order\ManagerFactory $orderManager,
Expand Down Expand Up @@ -126,6 +132,7 @@ public function __construct(
$this->subscriberFactory = $subscriberFactory;
$this->config = $config;
$this->carrierManager = $carrierManager;
$this->setOrderStatus = $setOrderStatus;
}

/**
Expand Down Expand Up @@ -275,7 +282,7 @@ public function notificationCallbackHandler(\Magento\Sales\Api\Data\OrderInterfa
$this->orderRepository->save($order);

if ($config->getIsDeliveryCheckoutActive()) {
$order = $this->carrierManager->saveShipmentDataOnOrder($order->getId(), $checkoutData);
$order = $this->carrierManager->saveShipmentDataOnOrder($order->getEntityId(), $checkoutData);
}
break;

Expand Down Expand Up @@ -343,8 +350,12 @@ public function acknowledgeOrder(
$this->logger->addInfo(
"Acknowledged order orderId: {$order->getIncrementId()}. qouteId: {$order->getQuoteId()} "
);
try {
$this->orderManagement->notify($order->getEntityId());
} catch (\Exception $e) {

}

$this->orderManagement->notify($order->getEntityId());

if ($this->orderHandler->getNewsletterSubscribe($order)) {
$this->subscriberFactory->create()->subscribe($order->getCustomerEmail());
Expand Down Expand Up @@ -576,13 +587,18 @@ protected function getColumnFromSalesOrder($column, $value): \Magento\Sales\Api\
/**
* Updates order status and state
*
* @param $order
* @param $status
* @param $state
* @param OrderInterface $order
* @param string $status
* @param string $state
* @return $this
*/
protected function updateOrderStatus($order, $status, $state)
protected function updateOrderStatus(OrderInterface $order,string $status,string $state)
{
$this->setOrderStatus->execute(
(int) $order->getEntityId(),
$status,
$state
);
$order->setState($state)
->setStatus($status);

Expand All @@ -604,7 +620,8 @@ protected function addPaymentInformation(
'payment_name' => $purchaseData->getPaymentName(),
'amount_to_pay' => $purchaseData->getAmountToPay(),
'invoice_delivery_method' => $purchaseData->getInvoiceDeliveryMethod(),
'purchase_identifier' => $purchaseData->getPurchaseIdentifier()
'purchase_identifier' => $purchaseData->getPurchaseIdentifier(),
'order_id' => $purchaseData->getOrderId(),
];
$payment->setAdditionalInformation($info);

Expand Down
29 changes: 29 additions & 0 deletions src/Checkout/Order/SetOrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace Webbhuset\CollectorCheckout\Checkout\Order;

use Magento\Framework\App\ResourceConnection;

class SetOrderStatus
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

public function __construct(
ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}

public function execute($orderId, $status, $state)
{
$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection->getTableName('sales_order');

$data = ['state' => $state, 'status' => $status];
$connection->update($tableName, $data, 'entity_id = ' . (int)$orderId);
}
}
12 changes: 12 additions & 0 deletions src/Checkout/Quote/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ public function getQuoteByPublicToken($publicToken): \Magento\Quote\Api\Data\Car
return $this->getColumnFromQuote("collectorbank_public_id", $publicToken);
}

/**
* Get quote by public token
*
* @param $privateId
* @return \Magento\Quote\Api\Data\CartInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getQuoteByPrivateId($privateId): \Magento\Quote\Api\Data\CartInterface
{
return $this->getColumnFromQuote("collectorbank_private_id", $privateId);
}

/**
* Gets a the specified column from quote table
*
Expand Down
Loading

0 comments on commit 85926e0

Please sign in to comment.