Skip to content

Commit

Permalink
Fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed Apr 3, 2024
1 parent b183882 commit 816a068
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 82 deletions.
13 changes: 10 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
### UPGRADE FROM 1.5.1 to 1.6

1. Support for Sylius 1.13 has been added, it is now the recommended Sylius version to use.
2. Support for PHP 8.0 has been dropped.
3. The following constructor signatures have been changed:

1. Support for PHP 8.0 has been dropped.

1. The following constructor signatures have been changed:

`Sylius\PayPalPlugin\Client\PayPalClient`:
```diff
Expand All @@ -12,6 +14,7 @@
use Psr\Http\Message\StreamFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
private readonly LoggerInterface $logger,
private readonly UuidProviderInterface $uuidProvider,
Expand All @@ -32,6 +35,7 @@
use Psr\Http\Message\RequestFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
+ private readonly ?RequestFactoryInterface $requestFactory = null,
)
Expand All @@ -45,6 +49,7 @@
use Psr\Http\Message\StreamFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
private readonly string $baseUrl,
+ private readonly ?RequestFactoryInterface $requestFactory = null,
Expand All @@ -59,13 +64,15 @@
use Psr\Http\Message\RequestFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
private readonly SellerWebhookRegistrarInterface $sellerWebhookRegistrar,
private readonly string $url,
+ private readonly ?RequestFactoryInterface $requestFactory = null,
)
```
4. Added doctrine migration for PostgreSQL. For more information, please refer to the [Sylius 1.13 UPGRADE.md](https://github.com/Sylius/Sylius/blob/1.13/UPGRADE-1.13.md)

1. Added doctrine migration for PostgreSQL. For more information, please refer to the [Sylius 1.13 UPGRADE.md](https://github.com/Sylius/Sylius/blob/1.13/UPGRADE-1.13.md)

### UPGRADE FROM 1.3.0 to 1.3.1

Expand Down
3 changes: 2 additions & 1 deletion spec/Api/WebhookApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function it_registers_webhook(
StreamInterface $body
): void {

$requestFactory->createRequest('POST','http://base-url.com/v1/notifications/webhooks')
$requestFactory
->createRequest('POST','http://base-url.com/v1/notifications/webhooks')
->willReturn($request);
$client->sendRequest($request)->willReturn($response);

Expand Down
2 changes: 1 addition & 1 deletion src/Api/WebhookApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
);
}

if (null === $this->requestFactory && null === $this->streamFactory) {
if (null === $this->requestFactory || null === $this->streamFactory) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
Expand Down
2 changes: 1 addition & 1 deletion src/Client/PayPalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
);
}

if (null === $this->requestFactory && null === $this->streamFactory) {
if (null === $this->requestFactory || null === $this->streamFactory) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
Expand Down
80 changes: 44 additions & 36 deletions src/Controller/CreatePayPalOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,54 @@
final class CreatePayPalOrderAction
{
public function __construct(
private readonly Payum $payum,
private readonly OrderRepositoryInterface $orderRepository,
private readonly FactoryInterface $stateMachineFactory,
private readonly ObjectManager $paymentManager,
private readonly ?Payum $payum,
private readonly ?OrderRepositoryInterface $orderRepository,
private readonly ?FactoryInterface $stateMachineFactory,
private readonly ?ObjectManager $paymentManager,
private readonly PaymentStateManagerInterface $paymentStateManager,
private readonly OrderProviderInterface $orderProvider,
private readonly CapturePaymentResolverInterface $capturePaymentResolver,
) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the first argument is deprecated and will be prohibited in 2.0',
Payum::class,
),
);
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the second argument is deprecated and will be prohibited in 2.0',
OrderRepositoryInterface::class,
),
);
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the third argument is deprecated and will be prohibited in 2.0',
FactoryInterface::class,
),
);
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the fourth argument is deprecated and will be prohibited in 2.0',
ObjectManager::class,
),
);
if (null !== $this->payum) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the first argument is deprecated and will be prohibited in 2.0',
Payum::class,
),
);
}
if (null !== $this->orderRepository) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the second argument is deprecated and will be prohibited in 2.0',
OrderRepositoryInterface::class,
),
);
}
if (null !== $this->stateMachineFactory) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the third argument is deprecated and will be prohibited in 2.0',
FactoryInterface::class,
),
);
}
if (null !== $this->paymentManager) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the fourth argument is deprecated and will be prohibited in 2.0',
ObjectManager::class,
),
);
}
}

public function __invoke(Request $request): Response
Expand Down
60 changes: 33 additions & 27 deletions src/Controller/CreatePayPalOrderFromCartAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,43 @@
final class CreatePayPalOrderFromCartAction
{
public function __construct(
private readonly Payum $payum,
private readonly OrderRepositoryInterface $orderRepository,
private readonly FactoryInterface $stateMachineFactory,
private readonly ?Payum $payum,
private readonly ?OrderRepositoryInterface $orderRepository,
private readonly ?FactoryInterface $stateMachineFactory,
private readonly ObjectManager $paymentManager,
private readonly OrderProviderInterface $orderProvider,
private readonly CapturePaymentResolverInterface $capturePaymentResolver,
) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the first argument is deprecated and will be prohibited in 2.0',
Payum::class,
),
);
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the second argument is deprecated and will be prohibited in 2.0',
OrderRepositoryInterface::class,
),
);
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the third argument is deprecated and will be prohibited in 2.0',
FactoryInterface::class,
),
);
if (null !== $this->payum) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the first argument is deprecated and will be prohibited in 2.0',
Payum::class,
),
);
}
if (null !== $this->orderRepository) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the second argument is deprecated and will be prohibited in 2.0',
OrderRepositoryInterface::class,
),
);
}
if (null !== $this->stateMachineFactory) {
trigger_deprecation(
'sylius/paypal-plugin',
'1.6',
sprintf(
'Passing an instance of "%s" as the third argument is deprecated and will be prohibited in 2.0',
FactoryInterface::class,
),
);
}
}

public function __invoke(Request $request): Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Sylius\PayPalPlugin\Listener;
namespace Sylius\PayPalPlugin\EventListener\Workflow;

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\PayPalPlugin\Processor\PayPalOrderCompleteProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* file that was distributed with this source code.
*/

namespace Sylius\PayPalPlugin\Listener;
namespace Sylius\PayPalPlugin\EventListener\Workflow;

use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\PayPalPlugin\Processor\PaymentRefundProcessorInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/integrations/workflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="Sylius\PayPalPlugin\Listener\CompletePayPalOrderListener">
<service id="Sylius\PayPalPlugin\EventListener\Workflow\CompletePayPalOrderListener">
<argument type="service" id="Sylius\PayPalPlugin\Processor\PayPalOrderCompleteProcessor" />

<tag name="kernel.event_listener" event="workflow.sylius_order.completed.complete" priority="100" />
</service>

<service id="Sylius\PayPalPlugin\Listener\RefundPaymentListener">
<service id="Sylius\PayPalPlugin\EventListener\Workflow\RefundPaymentListener">
<argument type="service" id="Sylius\PayPalPlugin\Processor\PaymentRefundProcessorInterface" />

<tag name="kernel.event_listener" event="workflow.sylius_order_payment.enter.refund" priority="100" />
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
id="Sylius\PayPalPlugin\Enabler\PaymentMethodEnablerInterface"
class="Sylius\PayPalPlugin\Enabler\PayPalPaymentMethodEnabler"
>
<argument type="service" id="sylius.http_client" />
<argument type="service" id="Http\Discovery\Psr18Client" />
<argument>%sylius.pay_pal.facilitator_url%</argument>
<argument type="service" id="sylius.manager.payment_method" />
<argument type="service" id="Sylius\PayPalPlugin\Registrar\SellerWebhookRegistrarInterface" />
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@
</service>

<service id="Sylius\PayPalPlugin\Controller\CreatePayPalOrderAction">
<argument type="service" id="payum" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sm.factory" />
<argument type="service" id="sylius.manager.payment" />
<argument>null</argument>
<argument>null</argument>
<argument>null</argument>
<argument>null</argument>
<argument type="service" id="Sylius\PayPalPlugin\Manager\PaymentStateManagerInterface" />
<argument type="service" id="Sylius\PayPalPlugin\Provider\OrderProviderInterface" />
<argument type="service" id="Sylius\PayPalPlugin\Resolver\CapturePaymentResolverInterface" />
</service>

<service id="Sylius\PayPalPlugin\Controller\CreatePayPalOrderFromCartAction">
<argument type="service" id="payum" />
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sm.factory" />
<argument>null</argument>
<argument>null</argument>
<argument>null</argument>
<argument type="service" id="sylius.manager.payment" />
<argument type="service" id="Sylius\PayPalPlugin\Provider\OrderProviderInterface" />
<argument type="service" id="Sylius\PayPalPlugin\Resolver\CapturePaymentResolverInterface" />
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/config/packages/workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
framework:
workflows: ~
workflows: ~

0 comments on commit 816a068

Please sign in to comment.