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

Draft of CreatePayPalOrderPayloadBuilder #1209

Draft
wants to merge 26 commits into
base: release/v8.4.0.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8402ca6
Draft for httpclient refactoring
btafforeau Jan 3, 2024
6dd7d1c
Modified payment client and configuration builder (#1199)
L3RAZ Feb 13, 2024
29aebcc
PAYSHIP-2630 (#1182)
Matt75 Feb 13, 2024
52a474d
Fixed old Order client class extension
L3RAZ Mar 4, 2024
e02044c
Removed abstract property from PshHttpClientAdapter
L3RAZ Mar 6, 2024
345a7cb
Added logger to new API client
L3RAZ Mar 6, 2024
7380e30
Draft for httpclient refactoring
btafforeau Jan 3, 2024
b305f0b
Modified payment client and configuration builder (#1199)
L3RAZ Feb 13, 2024
a0bf104
PAYSHIP-2630 (#1182)
Matt75 Feb 13, 2024
7298811
Changed CreateOrderHandler to use new HttpClient
L3RAZ Feb 12, 2024
2a655a4
Fix
L3RAZ Feb 13, 2024
da3d354
Added order managing functions to OrderHttpClient
L3RAZ Feb 13, 2024
6d3fc0c
CS fix
L3RAZ Feb 13, 2024
86a0c2f
Added json encoding for request sending
L3RAZ Feb 14, 2024
0310a61
Added dependency config
L3RAZ Feb 14, 2024
fe55342
Create order unit tests
btafforeau Feb 19, 2024
175ae2d
Renamed service names
L3RAZ Feb 19, 2024
140b092
Fixed interface and tests
L3RAZ Feb 19, 2024
4652037
Handling more errors for PaymentService
btafforeau Feb 23, 2024
67eacb4
Symfony serializer (#1202)
L3RAZ Mar 5, 2024
92dea79
[PAYSHIP-2679] New DB structure for PayPal Order (#1203)
L3RAZ Mar 5, 2024
1267349
Updated PayPal order getters and removed PsCheckoutCart creation
L3RAZ Mar 5, 2024
8547e25
Fixed oldPaymentClient
L3RAZ Mar 7, 2024
3f09c36
Added Draft for CreatePayPalOrderPayloadBuilder
L3RAZ Mar 6, 2024
64404f7
Added temporary data attribute to builder
L3RAZ Mar 6, 2024
92751f6
Added payment source and supplementary data
L3RAZ Mar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/php.yml
Expand Up @@ -88,6 +88,9 @@ jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: [ '8.0.0', 'latest' ]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -111,5 +114,9 @@ jobs:

- run: composer install

- name: Pull PrestaShop files (Tag ${{ matrix.presta-versions }})
run: docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:${{ matrix.presta-versions }}

- name: Run PHPUnit
run: php vendor/bin/phpunit tests/Unit
run: docker run --rm --volumes-from temp-ps -v $PWD:/var/www/html/modules/ps_checkout -e _PS_ROOT_DIR_=/var/www/html/ --workdir=/var/www/html/modules/ps_checkout php:7.2 ./vendor/bin/phpunit -c ./tests/Unit/phpunit.xml
# run: php vendor/bin/phpunit tests/Unit
109 changes: 83 additions & 26 deletions config/common.yml
Expand Up @@ -12,6 +12,10 @@ services:
arguments:
- "ps_checkout"

ps_checkout.db:
class: Db
factory: [ 'Db', 'getInstance' ]

ps_checkout.module.version:
class: 'PrestaShop\Module\PrestashopCheckout\Version\Version'
factory: ["PrestaShop\\Module\\PrestashopCheckout\\Version\\Version", "buildFromString"]
Expand Down Expand Up @@ -436,26 +440,26 @@ services:

ps_checkout.tactician.bus:
class: 'League\Tactician\CommandBus'
factory: ["@ps_checkout.tactician.bus.factory", "create"]
factory: ['@PrestaShop\Module\PrestashopCheckout\CommandBus\TacticianCommandBusFactory', "create"]

ps_checkout.bus.command:
class: 'PrestaShop\Module\PrestashopCheckout\CommandBus\TacticianCommandBusAdapter'
public: true
arguments:
- "@ps_checkout.tactician.bus"

ps_checkout.tactician.bus.factory:
PrestaShop\Module\PrestashopCheckout\CommandBus\TacticianCommandBusFactory:
class: 'PrestaShop\Module\PrestashopCheckout\CommandBus\TacticianCommandBusFactory'
public: true
arguments:
- "@ps_checkout.module"
- "@ps_checkout.logger"
-
PrestaShop\Module\PrestashopCheckout\Order\Command\AddOrderPaymentCommand: "ps_checkout.command.handler.order.add_order_payment"
PrestaShop\Module\PrestashopCheckout\Order\Command\CreateOrderCommand: "ps_checkout.command.handler.order.create_order"
PrestaShop\Module\PrestashopCheckout\Order\Command\CreateOrderCommand: 'PrestaShop\Module\PrestashopCheckout\Order\CommandHandler\CreateOrderCommandHandler'
PrestaShop\Module\PrestashopCheckout\Order\Command\UpdateOrderStatusCommand: "ps_checkout.command.handler.order.update_order_status"
PrestaShop\Module\PrestashopCheckout\Order\Matrice\Command\UpdateOrderMatriceCommand: "ps_checkout.command.handler.order.matrice.update_order_matrice"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\CreatePayPalOrderCommand: "ps_checkout.command.handler.paypal.order.create_paypal_order"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\CreatePayPalOrderCommand: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\CreatePayPalOrderCommandHandler'
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\UpdatePayPalOrderCommand: "ps_checkout.command.handler.paypal.order.update_paypal_order"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\CapturePayPalOrderCommand: "ps_checkout.command.handler.paypal.order.capture_paypal_order"
PrestaShop\Module\PrestashopCheckout\Checkout\Command\CancelCheckoutCommand: "ps_checkout.command.handler.checkout.cancel_checkout"
Expand All @@ -469,6 +473,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 All @@ -481,39 +486,43 @@ services:
- "@ps_checkout.logger"
- "@ps_checkout.logger.configuration"

ps_checkout.event.subscriber.checkout:
PrestaShop\Module\PrestashopCheckout\Checkout\EventSubscriber\CheckoutEventSubscriber:
class: 'PrestaShop\Module\PrestashopCheckout\Checkout\EventSubscriber\CheckoutEventSubscriber'
public: true
arguments:
- "@ps_checkout.module"
- '@PrestaShop\Module\PrestashopCheckout\Checkout\CheckoutChecker'
- '@ps_checkout.bus.command'
- '@ps_checkout.repository.pscheckoutcart'

ps_checkout.event.subscriber.order:
PrestaShop\Module\PrestashopCheckout\Order\EventSubscriber\OrderEventSubscriber:
class: 'PrestaShop\Module\PrestashopCheckout\Order\EventSubscriber\OrderEventSubscriber'
public: true
arguments:
- "@ps_checkout.module"
- "@ps_checkout.repository.pscheckoutcart"
- '@ps_checkout.bus.command'

ps_checkout.event.subscriber.paypal.order:
PrestaShop\Module\PrestashopCheckout\PayPal\Order\EventSubscriber\PayPalOrderEventSubscriber:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\EventSubscriber\PayPalOrderEventSubscriber'
public: true
arguments:
- "@ps_checkout.module"
- "@ps_checkout.repository.pscheckoutcart"
- "@ps_checkout.cache.paypal.order"
- "@ps_checkout.checkout.checker"
- '@PrestaShop\Module\PrestashopCheckout\Checkout\CheckoutChecker'
- "@ps_checkout.paypal.order.service.check_transition_paypal_order_status"
- "@ps_checkout.order.state.service.order_state_mapper"
- '@ps_checkout.paypal.configuration'
- '@PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository'

ps_checkout.event.subscriber.paypal.capture:
PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\EventSubscriber\PayPalCaptureEventSubscriber:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\EventSubscriber\PayPalCaptureEventSubscriber'
public: true
arguments:
- "@ps_checkout.module"
- "@ps_checkout.order.service.check_order_amount"
- "@ps_checkout.cache.paypal.capture"
- "@ps_checkout.cache.paypal.order"
- "@ps_checkout.order.state.service.order_state_mapper"
- "@ps_checkout.bus.command"

PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Refund\EventSubscriber\PayPalRefundEventSubscriber:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Refund\EventSubscriber\PayPalRefundEventSubscriber'
Expand All @@ -530,12 +539,12 @@ services:
factory: ["@ps_checkout.event.dispatcher.factory", "create"]
arguments:
- [
"@ps_checkout.event.subscriber.checkout",
"@ps_checkout.event.subscriber.order",
"@ps_checkout.event.subscriber.paypal.order",
"@ps_checkout.event.subscriber.paypal.capture",
'@PrestaShop\Module\PrestashopCheckout\Checkout\EventSubscriber\CheckoutEventSubscriber',
'@PrestaShop\Module\PrestashopCheckout\Order\EventSubscriber\OrderEventSubscriber',
'@PrestaShop\Module\PrestashopCheckout\PayPal\Order\EventSubscriber\PayPalOrderEventSubscriber',
'@PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\EventSubscriber\PayPalCaptureEventSubscriber',
'@PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Refund\EventSubscriber\PayPalRefundEventSubscriber'
]
]

ps_checkout.event.dispatcher:
class: 'PrestaShop\Module\PrestashopCheckout\Event\SymfonyEventDispatcherAdapter'
Expand All @@ -551,7 +560,7 @@ services:
- "@ps_checkout.funding_source.translation"
- "@ps_checkout.paypal.configuration"

ps_checkout.command.handler.order.create_order:
PrestaShop\Module\PrestashopCheckout\Order\CommandHandler\CreateOrderCommandHandler:
class: 'PrestaShop\Module\PrestashopCheckout\Order\CommandHandler\CreateOrderCommandHandler'
public: true
arguments:
Expand All @@ -561,6 +570,7 @@ services:
- "@ps_checkout.order.state.service.order_state_mapper"
- "@ps_checkout.module"
- "@ps_checkout.order.service.check_order_amount"
- '@ps_checkout.funding_source.translation'

ps_checkout.command.handler.order.update_order_status:
class: 'PrestaShop\Module\PrestashopCheckout\Order\CommandHandler\UpdateOrderStatusCommandHandler'
Expand All @@ -574,13 +584,15 @@ services:
arguments:
- "@ps_checkout.event.dispatcher"

ps_checkout.command.handler.paypal.order.create_paypal_order:
PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\CreatePayPalOrderCommandHandler:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\CreatePayPalOrderCommandHandler'
public: true
arguments:
- "@ps_checkout.http.client.checkout"
- "@ps_checkout.event.dispatcher"
- "@ps_checkout.context.shop"
- '@?'
- '@PrestaShop\Module\PrestashopCheckout\PayPal\Order\Builder\Payload\CreatePayPalOrderPayloadBuilder'
- '@ps_checkout.event.dispatcher'
- '@PrestaShop\Module\PrestashopCheckout\Api\Payment\PaymentService'
- '@PrestaShop\Module\PrestashopCheckout\Serializer\ObjectSerializer'

ps_checkout.command.handler.paypal.order.update_paypal_order:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\UpdatePayPalOrderCommandHandler'
Expand All @@ -597,6 +609,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 @@ -697,21 +718,54 @@ services:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\CheckTransitionPayPalCaptureStatusService'
public: true

ps_checkout.checkout.checker:
PrestaShop\Module\PrestashopCheckout\Checkout\CheckoutChecker:
class: 'PrestaShop\Module\PrestashopCheckout\Checkout\CheckoutChecker'
public: true
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'


PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository:
class: 'PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository'
arguments:
- '@ps_checkout.db'

PrestaShop\Module\PrestashopCheckout\Api\Payment\PaymentService:
class: 'PrestaShop\Module\PrestashopCheckout\Api\Payment\PaymentService'
arguments:
- '@PrestaShop\Module\PrestashopCheckout\Api\Payment\Client\PayPalOrderHttpClient'
- '@PrestaShop\Module\PrestashopCheckout\Serializer\ObjectSerializer'

PrestaShop\Module\PrestashopCheckout\Serializer\ObjectSerializer:
class: 'PrestaShop\Module\PrestashopCheckout\Serializer\ObjectSerializer'

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 All @@ -735,3 +789,6 @@ services:
public: true
arguments:
- "@ps_checkout.http.client"

PrestaShop\Module\PrestashopCheckout\PayPal\Order\Builder\Payload\CreatePayPalOrderPayloadBuilder:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\Builder\Payload\CreatePayPalOrderPayloadBuilder'
9 changes: 9 additions & 0 deletions controllers/front/create.php
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
@@ -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 license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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);
}
}
}
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