Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BP- 2132 BP-2813 clean refactor push & redirect #770

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
711285d
BP-2132 - add comments and move lock processing in specific service
LucianTuriacArnia May 23, 2023
4d56db2
BP-2132 - refactor push move locker process into separate service and…
LucianTuriacArnia May 24, 2023
7d93db7
BP-2132 - refactor push working
LucianTuriacArnia May 25, 2023
c2bad48
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jun 8, 2023
2085638
BP-2132 - Working on Push
LucianTuriacArnia Jun 19, 2023
e8dbda5
Merge branch 'feature/payment_provider_gateway' of https://github.com…
LucianTuriacArnia Jul 3, 2023
6ded9b5
Merge branch 'feature/payment_provider_gateway' of https://github.com…
LucianTuriacArnia Jul 3, 2023
abcb57b
Buckaroo Push Refactor - Fix PayPerEmail Message, work in progress re…
LucianTuriacArnia Jul 5, 2023
cd8d4b4
Buckaroo Push Refactor - work in progress refactor push
LucianTuriacArnia Jul 6, 2023
d0452fc
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 11, 2023
0c26ab4
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 13, 2023
24c87de
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 13, 2023
977e16c
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 16, 2023
362a289
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 17, 2023
151f1a7
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 19, 2023
45396e2
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 24, 2023
4a0a4f7
Merge branch 'feature/payment_provider_gateway' of https://github.com…
LucianTuriacArnia Jul 24, 2023
71f4032
BP-2132 - Working on Push Refactor
LucianTuriacArnia Jul 25, 2023
a5fd821
Fix bugs on refactor push
LucianTuriacArnia Jul 27, 2023
4d29d4f
Fix Payperemail
LucianTuriacArnia Jul 28, 2023
b891151
BP-2133 - Working at Refactor Redirect
LucianTuriacArnia Aug 8, 2023
f0d1ea7
BP-2133 - Working at Refactor Redirect
LucianTuriacArnia Aug 9, 2023
e257ace
BP-2133 - Refactor Redirect
LucianTuriacArnia Aug 10, 2023
9c1ce4d
BP-2133 - Fix IDIN
LucianTuriacArnia Aug 11, 2023
739dd71
BP-2133 - Add comments to functions, fix payconiq
LucianTuriacArnia Aug 11, 2023
d014797
BP-2813 - Refactor Push clean the old code
LucianTuriacArnia Aug 14, 2023
b8bec98
BP-2813 - Remove testing code
LucianTuriacArnia Aug 14, 2023
6ac3dbd
Merge branch 'feature/payment_provider_gateway' of https://github.com…
LucianTuriacArnia Aug 14, 2023
5802014
BP-2132 - BP-2813 - code review
LucianTuriacArnia Aug 15, 2023
8b7b1a8
BP-2132 - BP-2813 - fix PHP_MD and PHP_CS
LucianTuriacArnia Aug 15, 2023
eec655e
Merge branch 'feature/payment_provider_gateway' of https://github.com…
LucianTuriacArnia Aug 15, 2023
b70fae1
BP-2132 - BP-2813 - fix PHP_MD
LucianTuriacArnia Aug 15, 2023
9296707
BP-2132 - BP-2813 - fix PHP_MD
LucianTuriacArnia Aug 15, 2023
f73ec9e
BP-2132 - BP-2813 - code review
LucianTuriacArnia Aug 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Api/PushProcessorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Buckaroo\Magento2\Api;

interface PushProcessorInterface
{
/**
* @param PushRequestInterface $pushRequest
* @return bool
*/
public function processPush(PushRequestInterface $pushRequest): bool;
}
94 changes: 26 additions & 68 deletions Controller/Payconiq/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,31 @@
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/
declare(strict_types=1);

namespace Buckaroo\Magento2\Controller\Payconiq;

use Buckaroo\Magento2\Exception;
use Buckaroo\Magento2\Helper\Data;
use Buckaroo\Magento2\Logging\Log;
use Buckaroo\Magento2\Model\ConfigProvider\Factory;
use Buckaroo\Magento2\Model\BuckarooStatusCode;
use Buckaroo\Magento2\Model\ConfigProvider\Account as AccountConfig;
use Buckaroo\Magento2\Model\OrderStatusFactory;
use Buckaroo\Magento2\Model\RequestPush\RequestPushFactory;
use Buckaroo\Magento2\Model\Service\Order as OrderService;
use Buckaroo\Magento2\Service\Push\OrderRequestService;
use Buckaroo\Magento2\Service\Sales\Quote\Recreate;
use Magento\Checkout\Model\Cart;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Customer;
use Magento\Customer\Model\ResourceModel\CustomerFactory;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Customer\Model\SessionFactory;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Model\Quote;
use Magento\Sales\Api\Data\TransactionInterface;
use Magento\Sales\Api\Data\TransactionSearchResultInterface;
use Magento\Sales\Api\TransactionRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\Order\Payment\Transaction;

/**
Expand All @@ -57,91 +52,57 @@ class Process extends \Buckaroo\Magento2\Controller\Redirect\Process
/**
* @var null|Transaction
*/
protected $transaction = null;
protected ?Transaction $transaction = null;

/**
* @var SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
protected SearchCriteriaBuilder $searchCriteriaBuilder;

/**
* @var TransactionRepositoryInterface
*/
protected $transactionRepository;
protected TransactionRepositoryInterface $transactionRepository;

/**
* @param Context $context
* @param Data $helper
* @param Cart $cart
* @param Order $order
* @param Quote $quote
* @param TransactionInterface $transaction
* @param Log $logger
* @param Factory $configProviderFactory
* @param OrderSender $orderSender
* @param Quote $quote
* @param AccountConfig $accountConfig
* @param OrderRequestService $orderRequestService
* @param OrderStatusFactory $orderStatusFactory
* @param CheckoutSession $checkoutSession
* @param CustomerSession $customerSession
* @param CustomerRepositoryInterface $customerRepository
* @param SessionFactory $sessionFactory
* @param Customer $customerModel
* @param CustomerFactory $customerFactory
* @param OrderService $orderService
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param TransactionRepositoryInterface $transactionRepository
* @param ManagerInterface $eventManager
* @param Recreate $quoteRecreate
* @param RequestPushFactory $requestPushFactory
* @throws Exception
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param TransactionRepositoryInterface $transactionRepository
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Data $helper,
Cart $cart,
Order $order,
Quote $quote,
TransactionInterface $transaction,
Log $logger,
Factory $configProviderFactory,
OrderSender $orderSender,
Quote $quote,
AccountConfig $accountConfig,
OrderRequestService $orderRequestService,
OrderStatusFactory $orderStatusFactory,
CheckoutSession $checkoutSession,
CustomerSession $customerSession,
CustomerRepositoryInterface $customerRepository,
SessionFactory $sessionFactory,
Customer $customerModel,
CustomerFactory $customerFactory,
OrderService $orderService,
SearchCriteriaBuilder $searchCriteriaBuilder,
TransactionRepositoryInterface $transactionRepository,
ManagerInterface $eventManager,
Recreate $quoteRecreate,
RequestPushFactory $requestPushFactory
RequestPushFactory $requestPushFactory,
SearchCriteriaBuilder $searchCriteriaBuilder,
TransactionRepositoryInterface $transactionRepository
) {
parent::__construct(
$context,
$helper,
$cart,
$order,
$quote,
$transaction,
$logger,
$configProviderFactory,
$orderSender,
$orderStatusFactory,
$checkoutSession,
$customerSession,
$customerRepository,
$sessionFactory,
$customerModel,
$customerFactory,
$orderService,
$eventManager,
$quoteRecreate,
$requestPushFactory
);
parent::__construct($context, $logger, $quote, $accountConfig, $orderRequestService,
$orderStatusFactory, $checkoutSession, $customerSession, $customerRepository,
$orderService, $eventManager, $quoteRecreate, $requestPushFactory);

$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->transactionRepository = $transactionRepository;
Expand All @@ -151,7 +112,6 @@ public function __construct(
* Redirect Process Payconiq
*
* @return ResponseInterface|void
* @throws LocalizedException
* @throws Exception
*/
public function execute()
Expand All @@ -162,7 +122,7 @@ public function execute()
}

$transaction = $this->getTransaction();
$this->order = $transaction->getOrder();
$this->order = $transaction->getOrder()->getOrder();

if ($this->customerSession->getCustomerId() == $this->order->getCustomerId()) {
$this->logger->addError('Customer is different then the customer that start payconiq process request.');
Expand All @@ -173,17 +133,15 @@ public function execute()
'checkout',
[
'_fragment' => 'payment',
'_query' => ['bk_e' => 1]
'_query' => ['bk_e' => 1]
]
);
}
$this->quote->load($this->order->getQuoteId());

// @codingStandardsIgnoreStart
try {
$this->handleFailed(
$this->helper->getStatusCode('BUCKAROO_MAGENTO2_STATUSCODE_CANCELLED_BY_USER')
);
$this->handleFailed(BuckarooStatusCode::CANCELLED_BY_USER);
} catch (\Exception $exception) {
// handle failed exception
}
Expand Down Expand Up @@ -212,7 +170,7 @@ protected function getTransactionKey()
/**
* Get transaction object
*
* @return TransactionInterface|Transaction
* @return TransactionInterface|Transaction|null
* @throws Exception
*/
protected function getTransaction()
Expand All @@ -239,7 +197,7 @@ protected function getTransaction()
* @return TransactionSearchResultInterface
* @throws Exception
*/
protected function getList()
protected function getList(): TransactionSearchResultInterface
{
$transactionKey = $this->getTransactionKey();

Expand Down
168 changes: 168 additions & 0 deletions Controller/Redirect/IdinProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please email
* to [email protected], so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/
declare(strict_types=1);

namespace Buckaroo\Magento2\Controller\Redirect;

use Buckaroo\Magento2\Logging\Log;
use Buckaroo\Magento2\Model\ConfigProvider\Account as AccountConfig;
use Buckaroo\Magento2\Model\OrderStatusFactory;
use Buckaroo\Magento2\Model\RequestPush\RequestPushFactory;
use Buckaroo\Magento2\Model\Service\Order as OrderService;
use Buckaroo\Magento2\Service\Push\OrderRequestService;
use Buckaroo\Magento2\Service\Sales\Quote\Recreate;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Customer;
use Magento\Customer\Model\ResourceModel\CustomerFactory;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Quote\Model\Quote;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IdinProcess extends Process
{
/**
* @var CustomerFactory
*/
private CustomerFactory $customerResourceFactory;

/**
* @param Context $context
* @param Log $logger
* @param Quote $quote
* @param AccountConfig $accountConfig
* @param OrderRequestService $orderRequestService
* @param OrderStatusFactory $orderStatusFactory
* @param CheckoutSession $checkoutSession
* @param CustomerSession $customerSession
* @param CustomerRepositoryInterface $customerRepository
* @param OrderService $orderService
* @param ManagerInterface $eventManager
* @param Recreate $quoteRecreate
* @param RequestPushFactory $requestPushFactory
* @param CustomerFactory $customerFactory
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Log $logger,
Quote $quote,
AccountConfig $accountConfig,
OrderRequestService $orderRequestService,
OrderStatusFactory $orderStatusFactory,
CheckoutSession $checkoutSession,
CustomerSession $customerSession,
CustomerRepositoryInterface $customerRepository,
OrderService $orderService,
ManagerInterface $eventManager,
Recreate $quoteRecreate,
RequestPushFactory $requestPushFactory,
CustomerFactory $customerFactory
) {
parent::__construct($context, $logger, $quote, $accountConfig, $orderRequestService,
$orderStatusFactory, $checkoutSession, $customerSession, $customerRepository,
$orderService, $eventManager, $quoteRecreate, $requestPushFactory);

$this->customerResourceFactory = $customerFactory;
}

/**
* @return ResponseInterface|void
* @throws \Buckaroo\Magento2\Exception
*/
public function execute(): ResponseInterface
{
// Initialize the order, quote, payment
if ($this->redirectRequest->hasPostData('primary_service', 'IDIN')) {

Check failure on line 99 in Controller/Redirect/IdinProcess.php

View workflow job for this annotation

GitHub Actions / M2 PHPStan

Method Buckaroo\Magento2\Controller\Redirect\IdinProcess::execute() should return Magento\Framework\App\ResponseInterface but return statement is missing.

Check failure on line 99 in Controller/Redirect/IdinProcess.php

View workflow job for this annotation

GitHub Actions / M2 PHPStan

Method Buckaroo\Magento2\Controller\Redirect\IdinProcess::execute() should return Magento\Framework\App\ResponseInterface but return statement is missing.
if ($this->setCustomerIDIN()) {
$this->addSuccessMessage(__('Your iDIN verified succesfully!'));
} else {
$this->addErrorMessage(
__(
'Unfortunately iDIN not verified!'
)
);
}

return $this->redirectToCheckout();
}
}

/**
* Set consumer bin IDIN on customer
*
* @return bool
*/
private function setCustomerIDIN(): bool
{
if (!empty($this->redirectRequest->getServiceIdinConsumerbin())
&& !empty($this->redirectRequest->getServiceIdinIseighteenorolder())
&& $this->redirectRequest->getServiceIdinIseighteenorolder() == 'True'
) {
$this->checkoutSession->setCustomerIDIN($this->redirectRequest->getServiceIdinConsumerbin());
$this->checkoutSession->setCustomerIDINIsEighteenOrOlder(true);
$idinCid = $this->redirectRequest->getAdditionalInformation('idin_cid');
if (!empty($idinCid)) {
try {
/** @var Customer $customerNew */
$customerNew = $this->customerRepository->getById((int)$idinCid);
} catch (\Exception $e) {
$this->addErrorMessage(__('Unfortunately customer was not find by IDIN id: "%1"!', $idinCid));
$this->logger->addError(__METHOD__ . ' | ' . $e->getMessage());
return false;
}
$customerData = $customerNew->getDataModel();
$customerData->setCustomAttribute('buckaroo_idin', $this->redirectRequest->getServiceIdinConsumerbin());
$customerData->setCustomAttribute('buckaroo_idin_iseighteenorolder', 1);
$customerNew->updateData($customerData);

$customerResource = $this->customerResourceFactory->create();
$customerResource->saveAttribute($customerNew, 'buckaroo_idin');
$customerResource->saveAttribute($customerNew, 'buckaroo_idin_iseighteenorolder');
}
return true;
}
return false;
}

/**
* Create redirect response
*
* @return ResponseInterface
*/
protected function redirectToCheckout(): ResponseInterface
{
$this->logger->addDebug('start redirectToCheckout');
try {
$this->checkoutSession->restoreQuote();

} catch (\Exception $e) {
$this->logger->addError('Could not restore the quote.');
}

return $this->handleProcessedResponse('checkout', ['_query' => ['bk_e' => 1]]);
}
}
Loading
Loading