Skip to content

Commit

Permalink
Symfony serializer (#1202)
Browse files Browse the repository at this point in the history
* Create ObjectNormalizer to add supports of SKIP_NULL_VALUES

* Added object deserializing tests

* Added dependency injection for serializer

* Updated PaymentService with response serialization

* CS fix

* Removed custom object normalizer

* Added bootstrap to phpunit config

* Added order object serialization to pass to event

* Service refactoring

* Added toArray function to object serializer and fixed snake case conversion

* Added serializer interface

* Fix

* Fixed phpstan errors

* Added json serialization to order requests and fixed cs issues

---------

Co-authored-by: Matt75 <[email protected]>
  • Loading branch information
L3RAZ and Matt75 committed Mar 7, 2024
1 parent 4652037 commit 67eacb4
Show file tree
Hide file tree
Showing 19 changed files with 615 additions and 207 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
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
20 changes: 13 additions & 7 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,23 @@ 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: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\CreatePayPalOrderCommandHandler'
Expand Down Expand Up @@ -486,16 +486,16 @@ services:
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'

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'

PrestaShop\Module\PrestashopCheckout\PayPal\Order\EventSubscriber\PayPalOrderEventSubscriber:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\EventSubscriber\PayPalOrderEventSubscriber'
Expand All @@ -513,11 +513,11 @@ services:
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 Down Expand Up @@ -555,7 +555,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 @@ -565,6 +565,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 @@ -586,6 +587,7 @@ services:
- '@?'
- '@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 Down Expand Up @@ -743,6 +745,10 @@ services:
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'
Expand Down
39 changes: 20 additions & 19 deletions src/Api/Payment/Client/PayPalOrderHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ public function __construct(PaymentClientConfigurationBuilder $configurationBuil
*
* @return ResponseInterface
*
* @throws HttpException
* @throws HttpException|RequestException|TransferException|NetworkException
*/
public function sendRequest(RequestInterface $request)
{
try {
return parent::sendRequest($request);
} catch (NetworkException $exception) {
throw $exception;
// Thrown when the request cannot be completed because of network issues.
// No response here
} catch (HttpException $exception) {
Expand All @@ -73,68 +74,68 @@ public function sendRequest(RequestInterface $request)
}

/**
* @param array $payload
* @param string $payload //Payload JSON
* @param array $options
*
* @return ResponseInterface
*/
public function createOrder(array $payload, array $options = [])
public function createOrder($payload, array $options = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/create', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/create', $options, $payload));
}

/**
* @param array $payload
* @param string $payload
* @param array $options
*
* @return ResponseInterface
*/
public function updateOrder(array $payload, array $options = [])
public function updateOrder($payload, array $options = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/update', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/update', $options, $payload));
}

/**
* @param array $payload
* @param string $payload
* @param array $options
*
* @return ResponseInterface
*/
public function fetchOrder(array $payload, array $options = [])
public function fetchOrder($payload, array $options = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/fetch', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/fetch', $options, $payload));
}

/**
* @param array $payload
* @param string $payload
* @param array $options
*
* @return ResponseInterface
*/
public function captureOrder(array $payload, array $options = [])
public function captureOrder($payload, array $options = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/capture', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/capture', $options, $payload));
}

/**
* @param array $payload
* @param string $payload
* @param array $options
*
* @return ResponseInterface
*/
public function refundOrder(array $payload, array $options = [])
public function refundOrder($payload, array $options = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/refund', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/refund', $options, $payload));
}

/**
* @param array $payload
* @param string $payload
* @param array $options
*
* @return ResponseInterface
*/
public function generateClientToken(array $payload, array $options = [])
public function generateClientToken($payload, array $options = [])
{
return $this->sendRequest(new Request('POST', '/payments/order/generate_client_token', $options, json_encode($payload)));
return $this->sendRequest(new Request('POST', '/payments/order/generate_client_token', $options, $payload));
}
}
Loading

0 comments on commit 67eacb4

Please sign in to comment.