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

Refactoring - rebased v8.3.6.0 #1208

Open
wants to merge 6 commits into
base: prestashop/8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 36 additions & 6 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ services:
- '@ps_checkout.paypal.order.translations'
- '@ps_checkout.context.shop'


ps_checkout.paypal.builder.view_order_summary:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\PayPalOrderSummaryViewBuilder'
public: true
Expand Down Expand Up @@ -469,6 +470,7 @@ services:
PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForApprovalReversedQuery: "ps_checkout.query.handler.order.get_order_for_approval_reversed"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForCartIdQuery: "ps_checkout.query.handler.paypal.order.get_paypal_order_for_cart_id"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetCurrentPayPalOrderStatusQuery: "ps_checkout.query.handler.paypal.order.get_current_paypal_order_status"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderQuery: "ps_checkout.query.handler.paypal.order.get_paypal_order"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForCheckoutCompletedQuery: "ps_checkout.query.handler.paypal.order.get_paypal_order_for_checkout_completed"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForOrderConfirmationQuery: "ps_checkout.query.handler.paypal.order.get_paypal_order_for_order_confirmation"
PrestaShop\Module\PrestashopCheckout\Checkout\Command\UpdatePaymentMethodSelectedCommand: "ps_checkout.query.handler.checkout.update_payment_method_selected"
Expand Down Expand Up @@ -504,6 +506,7 @@ services:
- "@ps_checkout.checkout.checker"
- "@ps_checkout.paypal.order.service.check_transition_paypal_order_status"
- "@ps_checkout.order.state.service.order_state_mapper"
- '@ps_checkout.paypal.configuration'

ps_checkout.event.subscriber.paypal.capture:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\EventSubscriber\PayPalCaptureEventSubscriber'
Expand Down Expand Up @@ -578,9 +581,9 @@ services:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\CreatePayPalOrderCommandHandler'
public: true
arguments:
- "@ps_checkout.http.client.checkout"
- "@ps_checkout.event.dispatcher"
- "@ps_checkout.context.shop"
- '@?'
- '@?'
- '@ps_checkout.event.dispatcher'

ps_checkout.command.handler.paypal.order.update_paypal_order:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\UpdatePayPalOrderCommandHandler'
Expand All @@ -597,6 +600,15 @@ services:
- "@ps_checkout.http.client.checkout"
- "@ps_checkout.event.dispatcher"
- "@ps_checkout.cache.paypal.order"
- "@ps_checkout.repository.pscheckoutcart"
- '@ps_checkout.paypal.configuration'

ps_checkout.query.handler.paypal.order.get_paypal_order:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\QueryHandler\GetPayPalOrderQueryHandler'
public: true
arguments:
- '@ps_checkout.cache.paypal.order'
- '@ps_checkout.repository.pscheckoutcart'

ps_checkout.query.handler.paypal.order.get_current_paypal_order_status:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\QueryHandler\GetCurrentPayPalOrderStatusQueryHandler'
Expand Down Expand Up @@ -703,15 +715,33 @@ services:
arguments:
- "@ps_checkout.logger"

ps_checkout.environment.payment:
PrestaShop\Module\PrestashopCheckout\Environment\Env:
class: 'PrestaShop\Module\PrestashopCheckout\Environment\Env'

PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv:
class: 'PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv'
public: true

PrestaShop\Module\PrestashopCheckout\Builder\Configuration\PaymentClientConfigurationBuilder:
class: 'PrestaShop\Module\PrestashopCheckout\Builder\Configuration\PaymentClientConfigurationBuilder'
arguments:
- '@PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv'
- '@ps_checkout.prestashop.router'
- '@ps_checkout.context.shop'
- '@ps_checkout.repository.prestashop.account'
- '@ps_checkout.context.prestashop'
- "@ps_checkout.logger.configuration"
- "@ps_checkout.logger"

PrestaShop\Module\PrestashopCheckout\Api\Payment\Client\PayPalOrderHttpClient:
class: 'PrestaShop\Module\PrestashopCheckout\Api\Payment\Client\PayPalOrderHttpClient'
arguments:
- '@PrestaShop\Module\PrestashopCheckout\Builder\Configuration\PaymentClientConfigurationBuilder'

ps_checkout.http.client.configuration:
class: 'PrestaShop\Module\PrestashopCheckout\Http\CheckoutHttpClientConfigurationBuilder'
public: true
arguments:
- "@ps_checkout.environment.payment"
- '@PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv'
- "@ps_checkout.prestashop.router"
- "@ps_checkout.context.shop"
- "@ps_checkout.repository.prestashop.account"
Expand Down
9 changes: 9 additions & 0 deletions controllers/front/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException;
use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface;
use PrestaShop\Module\PrestashopCheckout\Controller\AbstractFrontController;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\CreatePayPalOrderCommand;
Expand All @@ -43,6 +44,9 @@ class Ps_CheckoutCreateModuleFrontController extends AbstractFrontController
public function postProcess()
{
try {
/** @var CommandBusInterface $commandBus */
$commandBus = $this->module->getService('ps_checkout.bus.command');

// BEGIN Express Checkout
$bodyValues = [];
$bodyContent = file_get_contents('php://input');
Expand Down Expand Up @@ -116,6 +120,11 @@ public function postProcess()
'exceptionCode' => null,
'exceptionMessage' => null,
]);
} catch (CartNotFoundException $exception) {
$this->exitWithResponse([
'httpCode' => 400,
'body' => 'No cart found.',
]);
} catch (Exception $exception) {
$this->module->getLogger()->error(
'CreateController - Exception ' . $exception->getCode(),
Expand Down
71 changes: 71 additions & 0 deletions controllers/front/vault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface;
use PrestaShop\Module\PrestashopCheckout\Controller\AbstractFrontController;
use PrestaShop\Module\PrestashopCheckout\PaymentMethodToken\Query\GetCustomerPaymentMethodTokensQuery;
use PrestaShop\Module\PrestashopCheckout\PaymentMethodToken\Query\GetCustomerPaymentMethodTokensQueryResult;
use Psr\Log\LoggerInterface;

/**
* This controller receive ajax call to manage the Customer PayPal Payment Method tokens
*/
class Ps_CheckoutVaultModuleFrontController extends AbstractFrontController
{
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
try {
/** @var CommandBusInterface $commandBus */
$commandBus = $this->module->getService('ps_checkout.bus.command');
/** @var GetCustomerPaymentMethodTokensQueryResult $getCustomerPaymentMethodTokensQueryResult */
$getCustomerPaymentMethodTokensQueryResult = $commandBus->handle(new GetCustomerPaymentMethodTokensQuery(
$this->getCustomerId(),
$this->getPageSize(),
$this->getPageNumber()
));

$this->exitWithResponse([
'status' => true,
'httpCode' => 200,
'body' => [
'customerId' => $getCustomerPaymentMethodTokensQueryResult->getCustomerId(),
'paymentTokens' => $getCustomerPaymentMethodTokensQueryResult->getPaymentTokens(),
'totalItems' => $getCustomerPaymentMethodTokensQueryResult->getTotalItems(),
'totalPages' => $getCustomerPaymentMethodTokensQueryResult->getTotalPages(),
],
]);
} catch (Exception $exception) {
/** @var LoggerInterface $logger */
$logger = $this->module->getService('ps_checkout.logger');
$logger->error(
sprintf(
'VaultController exception %s : %s',
$exception->getCode(),
$exception->getMessage()
)
);

$this->exitWithExceptionMessage($exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/**
* Construct the client used to make call to maasland
*/
class PaymentClient extends GenericClient
class OldPaymentClient extends GenericClient
{
/**
* @param Link $link
Expand Down
32 changes: 32 additions & 0 deletions src/Api/Payment/Client/PayPalOrderHttpClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\Api\Payment\Client;

use PrestaShop\Module\PrestashopCheckout\Builder\Configuration\PaymentClientConfigurationBuilder;
use PrestaShop\Module\PrestashopCheckout\Http\PsrHttpClientAdapter;

class PayPalOrderHttpClient extends PsrHttpClientAdapter
{
public function __construct(PaymentClientConfigurationBuilder $configurationBuilder)
{
parent::__construct($configurationBuilder->build());
}
}
4 changes: 2 additions & 2 deletions src/Api/Payment/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

namespace PrestaShop\Module\PrestashopCheckout\Api\Payment;

use PrestaShop\Module\PrestashopCheckout\Api\Payment\Client\PaymentClient;
use PrestaShop\Module\PrestashopCheckout\Api\Payment\Client\OldPaymentClient;

/**
* Handle order requests
*
* @deprecated
*/
class Order extends PaymentClient
class Order extends OldPaymentClient
{
/**
* @deprecated
Expand Down
Loading
Loading