Skip to content

Commit f530e47

Browse files
authored
[UPMERGE] 1.7 -> 2.0 (Sylius#379)
This PR has been generated automatically. For more details see [upmerge_pr.yaml](/Sylius/PayPalPlugin/blob/1.7/.github/workflows/upmerge_pr.yaml). **Remember!** The upmerge should always be merged with using `Merge pull request` button. In case of conflicts, please resolve them manually with usign the following commands: ``` git fetch upstream gh pr checkout <this-pr-number> git merge upstream/2.0 -m "Resolve conflicts between 1.7 and 2.0" ``` If you use other name for the upstream remote, please replace `upstream` with the name of your remote pointing to the `Sylius/PayPalPlugin` repository. Once the conflicts are resolved, please run `git merge --continue` and push the changes to this PR.
2 parents 5a4035f + d71285c commit f530e47

File tree

44 files changed

+2369
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2369
-184
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"friends-of-behat/symfony-extension": "^2.1",
2929
"friends-of-behat/variadic-extension": "^1.3",
3030
"lchrusciel/api-test-case": "^5.1",
31+
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
3132
"nyholm/psr7": "^1.8",
3233
"phpstan/phpstan": "^2.0",
3334
"phpstan/phpstan-doctrine": "^2.0",

config/services.xml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,33 @@
2020
<import resource="services/**/*.xml" />
2121
</imports>
2222

23+
<parameters>
24+
<parameter key="sylius_paypal.prioritize_paypal_as_default_method">true</parameter>
25+
26+
<parameter type="collection" key="sylius_paypal.repository.query.pay_pal_payment.updatable_states">
27+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_CART</parameter>
28+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW</parameter>
29+
</parameter>
30+
<parameter type="collection" key="sylius_paypal.repository.query.pay_pal_payment.cancellable_states">
31+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_CART</parameter>
32+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_NEW</parameter>
33+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_PROCESSING</parameter>
34+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_AUTHORIZED</parameter>
35+
</parameter>
36+
<parameter type="collection" key="sylius_paypal.repository.query.pay_pal_payment.refundable_states">
37+
<parameter type="constant">Sylius\Component\Payment\Model\PaymentInterface::STATE_COMPLETED</parameter>
38+
</parameter>
39+
</parameters>
40+
2341
<services>
2442
<service id="sylius_paypal.form.extension.payment_method" class="Sylius\PayPalPlugin\Form\Extension\PaymentMethodTypeExtension">
2543
<tag name="form.type_extension" />
2644
</service>
2745

2846
<service id="sylius_paypal.form.type.paypal_configuration" class="Sylius\PayPalPlugin\Form\Type\PayPalConfigurationType">
47+
<argument>%sylius_paypal.sandbox%</argument>
48+
49+
<tag name="form.type" />
2950
<tag name="sylius.gateway_configuration_type" type="sylius_paypal" label="sylius_paypal.label" />
3051
</service>
3152

@@ -46,6 +67,7 @@
4667
<argument type="service" id="router" />
4768
<argument type="service" id="request_stack" />
4869
<argument type="service" id="sylius_paypal.provider.paypal_payment_method" />
70+
<argument>%sylius_paypal.sandbox%</argument>
4971
<tag name="kernel.event_listener" event="sylius.payment_method.initialize_create" method="initializeCreate" />
5072
</service>
5173

@@ -75,6 +97,7 @@
7597
>
7698
<argument type="service" id="sylius.repository.payment" />
7799
<argument type="service" id="sylius.repository.order" />
100+
<deprecated package="sylius/paypal-plugin" version="1.7">The "%service_id%" service is deprecated since 1.7 and will be removed in 3.0.</deprecated>
78101
</service>
79102
<service id="Sylius\PayPalPlugin\Provider\PaymentProviderInterface" alias="sylius_paypal.provider.payment" />
80103

@@ -157,7 +180,9 @@
157180
<service
158181
id="sylius_paypal.processor.locale"
159182
class="Sylius\PayPalPlugin\Processor\LocaleProcessor"
160-
/>
183+
>
184+
<argument type="service" id="sylius_paypal.resolver.supported_locale" />
185+
</service>
161186
<service id="Sylius\PayPalPlugin\Processor\LocaleProcessorInterface" alias="sylius_paypal.processor.locale" />
162187

163188
<service
@@ -188,6 +213,7 @@
188213
>
189214
<argument type="service" id=".inner" />
190215
<argument type="service" id="sylius.repository.payment_method" />
216+
<argument>%sylius_paypal.prioritize_paypal_as_default_method%</argument>
191217
</service>
192218

193219
<service
@@ -291,5 +317,30 @@
291317

292318
<service id="sylius_paypal.verifier.payment_amount" class="Sylius\PayPalPlugin\Verifier\PaymentAmountVerifier" />
293319
<service id="Sylius\PayPalPlugin\Verifier\PaymentAmountVerifierInterface" alias="sylius_paypal.verifier.payment_amount" />
320+
321+
<service
322+
id="sylius_paypal.repository.query.paypal_payment"
323+
class="Sylius\PayPalPlugin\Repository\Query\PaypalPaymentQuery"
324+
>
325+
<argument type="service" id="sylius.manager.payment" />
326+
<argument type="service" id="sylius.repository.payment"/>
327+
<argument>%sylius_paypal.repository.query.pay_pal_payment.updatable_states%</argument>
328+
<argument>%sylius_paypal.repository.query.pay_pal_payment.cancellable_states%</argument>
329+
<argument>%sylius_paypal.repository.query.pay_pal_payment.refundable_states%</argument>
330+
</service>
331+
<service id="Sylius\PayPalPlugin\Repository\Query\PaypalPaymentQueryInterface" alias="sylius_paypal.repository.query.paypal_payment" />
332+
333+
<service id="sylius_paypal.resolver.paypal_payment_methods" class="Sylius\PayPalPlugin\Resolver\PayPalPaymentMethodsResolver">
334+
<argument type="service" id="sylius.repository.payment_method" />
335+
</service>
336+
<service id="Sylius\PayPalPlugin\Resolver\PayPalPaymentMethodsResolverInterface" alias="sylius_paypal.resolver.paypal_payment_methods" />
337+
338+
<service
339+
id="sylius_paypal.resolver.supported_locale"
340+
class="Sylius\PayPalPlugin\Resolver\SupportedLocaleResolver"
341+
>
342+
<argument>%sylius_paypal.supported_locales%</argument>
343+
</service>
344+
<service id="Sylius\PayPalPlugin\Resolver\SupportedLocaleResolverInterface" alias="sylius_paypal.resolver.supported_locale" />
294345
</services>
295346
</container>

config/services/controller.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
<argument type="service" id="sylius_paypal.provider.payment" />
2525
<argument type="service" id="sylius.manager.payment" />
2626
<argument type="service" id="sylius_paypal.provider.paypal_refund_data" />
27+
<argument type="service" id="sylius_paypal.repository.query.paypal_payment" />
2728
</service>
2829

2930
<service id="sylius_paypal.controller.cancel_paypal_order" class="Sylius\PayPalPlugin\Controller\CancelPayPalOrderAction">
30-
<argument type="service" id="sylius_paypal.provider.payment" />
31-
<argument type="service" id="sylius.repository.order" />
31+
<argument>null</argument>
32+
<argument>null</argument>
3233
<argument type="service" id="request_stack" />
3334
</service>
3435

@@ -38,6 +39,7 @@
3839
<argument type="service" id="request_stack" />
3940
<argument type="service" id="sylius_abstraction.state_machine" />
4041
<argument type="service" id="sylius.order_processing.order_payment_processor.checkout" />
42+
<argument type="service" id="sylius_paypal.repository.query.paypal_payment" />
4143
</service>
4244

4345
<service id="sylius_paypal.controller.cancel_last_paypal_payment" class="Sylius\PayPalPlugin\Controller\CancelLastPayPalPaymentAction">
@@ -50,6 +52,7 @@
5052
<service id="sylius_paypal.controller.cancel_paypal_checkout_payment" class="Sylius\PayPalPlugin\Controller\CancelPayPalCheckoutPaymentAction">
5153
<argument type="service" id="sylius_paypal.provider.payment" />
5254
<argument type="service" id="sylius_paypal.manager.payment_state" />
55+
<argument type="service" id="sylius_paypal.repository.query.paypal_payment" />
5356
</service>
5457

5558
<service id="sylius_paypal.controller.complete_paypal_order" class="Sylius\PayPalPlugin\Controller\CompletePayPalOrderAction">
@@ -89,6 +92,7 @@
8992
<argument type="service" id="sylius_paypal.resolver.capture_payment" />
9093
<argument type="service" id="sylius.remover.payment.order" />
9194
<argument type="service" id="sylius.order_processing.order_processor" />
95+
<argument type="service" id="sylius_paypal.resolver.paypal_payment_methods" />
9296
</service>
9397

9498
<service id="sylius_paypal.controller.paypal_buttons" class="Sylius\PayPalPlugin\Controller\PayPalButtonsController">
@@ -108,6 +112,7 @@
108112
<argument type="service" id="sylius_paypal.provider.available_countries" />
109113
<argument type="service" id="sylius_paypal.api.cache_authorize_client" />
110114
<argument type="service" id="sylius_paypal.api.identity" />
115+
<argument type="service" id="sylius_paypal.processor.locale" />
111116
</service>
112117

113118
<service id="sylius_paypal.controller.process_paypal_order" class="Sylius\PayPalPlugin\Controller\ProcessPayPalOrderAction">
@@ -129,6 +134,7 @@
129134
<argument type="service" id="sylius_paypal.api.update_order" />
130135
<argument type="service" id="sylius.factory.address" />
131136
<argument type="service" id="sylius.order_processing.order_processor" />
137+
<argument type="service" id="sylius_paypal.repository.query.paypal_payment" />
132138
</service>
133139

134140
<service id="sylius_paypal.controller.complete_paypal_order_from_payment_page" class="Sylius\PayPalPlugin\Controller\CompletePayPalOrderFromPaymentPageAction">

ecs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
return static function (ECSConfig $config): void {
1212
$config->paths([
1313
'src',
14-
'spec',
1514
'tests/Behat',
1615
'tests/Functional',
1716
'tests/Service',
@@ -37,7 +36,6 @@
3736
);
3837

3938
$config->skip([
40-
VisibilityRequiredFixer::class => ['*Spec.php'],
4139
InlineDocCommentDeclarationSniff::class . '.MissingVariable',
4240
]);
4341
};

src/Controller/CancelLastPayPalPaymentAction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function __invoke(Request $request): Response
4141
/** @var PaymentInterface $payment */
4242
$payment = $order->getLastPayment();
4343

44+
if (!$this->stateMachineFactory->can($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CANCEL)) {
45+
return new Response('', Response::HTTP_NO_CONTENT);
46+
}
47+
4448
$this->stateMachineFactory->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CANCEL);
4549

4650
/** @var PaymentInterface $lastPayment */

src/Controller/CancelPayPalCheckoutPaymentAction.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,51 @@
1515

1616
use Sylius\PayPalPlugin\Manager\PaymentStateManagerInterface;
1717
use Sylius\PayPalPlugin\Provider\PaymentProviderInterface;
18+
use Sylius\PayPalPlugin\Repository\Query\PaypalPaymentQueryInterface;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpFoundation\Response;
2021
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
2122

2223
final readonly class CancelPayPalCheckoutPaymentAction
2324
{
2425
public function __construct(
25-
private PaymentProviderInterface $paymentProvider,
26+
private ?PaymentProviderInterface $paymentProvider,
2627
private PaymentStateManagerInterface $paymentStateManager,
28+
private ?PaypalPaymentQueryInterface $paypalPaymentQuery = null,
2729
) {
30+
if (null !== $this->paymentProvider) {
31+
trigger_deprecation(
32+
'sylius/paypal-plugin',
33+
'1.7',
34+
sprintf(
35+
'Passing an instance of "%s" as the first argument is deprecated and will be prohibited in 3.0',
36+
PaymentProviderInterface::class,
37+
),
38+
);
39+
}
40+
if (null === $this->paypalPaymentQuery) {
41+
trigger_deprecation(
42+
'sylius/paypal-plugin',
43+
'1.7',
44+
sprintf(
45+
'Not passing an instance of "%s" is deprecated and will be prohibited in 3.0',
46+
PaypalPaymentQueryInterface::class,
47+
),
48+
);
49+
}
2850
}
2951

3052
public function __invoke(Request $request): Response
3153
{
32-
/**
33-
* @var string $content
34-
*/
54+
/** @var string $content */
3555
$content = $request->getContent();
36-
3756
$content = (array) json_decode($content, true);
3857

39-
$payment = $this->paymentProvider->getByPayPalOrderId((string) $content['payPalOrderId']);
58+
if (null !== $this->paypalPaymentQuery) {
59+
$payment = $this->paypalPaymentQuery->getForCancellationByOrderId((string) $content['payPalOrderId']);
60+
} else {
61+
$payment = $this->paymentProvider->getByPayPalOrderId((string) $content['payPalOrderId']);
62+
}
4063

4164
/** @var FlashBagInterface $flashBag */
4265
$flashBag = $request->getSession()->getBag('flashes');

src/Controller/CancelPayPalOrderAction.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Sylius\PayPalPlugin\Controller;
1515

16-
use Sylius\Component\Core\Model\OrderInterface;
1716
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
1817
use Sylius\PayPalPlugin\Provider\FlashBagProvider;
1918
use Sylius\PayPalPlugin\Provider\PaymentProviderInterface;
@@ -24,28 +23,21 @@
2423
final readonly class CancelPayPalOrderAction
2524
{
2625
public function __construct(
27-
private PaymentProviderInterface $paymentProvider,
28-
private OrderRepositoryInterface $orderRepository,
26+
private ?PaymentProviderInterface $paymentProvider,
27+
private ?OrderRepositoryInterface $orderRepository,
2928
private RequestStack $flashBagOrRequestStack,
3029
) {
30+
if (null !== $this->paymentProvider) {
31+
trigger_deprecation('sylius/paypal-plugin', '1.7', sprintf('Passing an instance of %s as the first argument is deprecated and will be prohibited in 3.0', PaymentProviderInterface::class));
32+
}
33+
if (null !== $this->orderRepository) {
34+
trigger_deprecation('sylius/paypal-plugin', '1.7', sprintf('Passing an instance of %s as the second argument is deprecated and will be prohibited in 3.0', OrderRepositoryInterface::class));
35+
}
3136
}
3237

3338
public function __invoke(Request $request): Response
3439
{
35-
/**
36-
* @var string $content
37-
*/
38-
$content = $request->getContent();
39-
40-
$content = (array) json_decode($content, true);
41-
42-
$payment = $this->paymentProvider->getByPayPalOrderId((string) $content['payPalOrderId']);
43-
44-
/** @var OrderInterface $order */
45-
$order = $payment->getOrder();
46-
$this->orderRepository->remove($order);
47-
48-
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)->add('success', 'sylius_paypal.order_cancelled');
40+
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)->add('success', 'sylius.pay_pal.order_cancelled');
4941

5042
return new Response('', Response::HTTP_NO_CONTENT);
5143
}

src/Controller/CancelPayPalPaymentAction.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,68 @@
2020
use Sylius\Component\Payment\PaymentTransitions;
2121
use Sylius\PayPalPlugin\Provider\FlashBagProvider;
2222
use Sylius\PayPalPlugin\Provider\PaymentProviderInterface;
23+
use Sylius\PayPalPlugin\Repository\Query\PaypalPaymentQueryInterface;
2324
use Symfony\Component\HttpFoundation\Request;
2425
use Symfony\Component\HttpFoundation\RequestStack;
2526
use Symfony\Component\HttpFoundation\Response;
2627

2728
final readonly class CancelPayPalPaymentAction
2829
{
2930
public function __construct(
30-
private PaymentProviderInterface $paymentProvider,
31+
private ?PaymentProviderInterface $paymentProvider,
3132
private ObjectManager $objectManager,
3233
private RequestStack $flashBagOrRequestStack,
3334
private StateMachineInterface $stateMachineFactory,
3435
private OrderProcessorInterface $orderPaymentProcessor,
36+
private ?PaypalPaymentQueryInterface $paypalPaymentQuery = null,
3537
) {
38+
if (null !== $this->paymentProvider) {
39+
trigger_deprecation(
40+
'sylius/paypal-plugin',
41+
'1.7',
42+
sprintf(
43+
'Passing an instance of "%s" as the first argument is deprecated and will be prohibited in 3.0',
44+
PaymentProviderInterface::class,
45+
),
46+
);
47+
}
48+
if (null === $this->paypalPaymentQuery) {
49+
trigger_deprecation(
50+
'sylius/paypal-plugin',
51+
'1.7',
52+
sprintf(
53+
'Not passing an instance of "%s" is deprecated and will be prohibited in 3.0',
54+
PaypalPaymentQueryInterface::class,
55+
),
56+
);
57+
}
3658
}
3759

3860
public function __invoke(Request $request): Response
3961
{
40-
/**
41-
* @var string $content
42-
*/
62+
/** @var string $content */
4363
$content = $request->getContent();
44-
4564
$content = (array) json_decode($content, true);
4665

47-
$payment = $this->paymentProvider->getByPayPalOrderId((string) $content['payPalOrderId']);
66+
if (null !== $this->paypalPaymentQuery) {
67+
$payment = $this->paypalPaymentQuery->getForCancellationByOrderId((string) $content['payPalOrderId']);
68+
} else {
69+
$payment = $this->paymentProvider->getByPayPalOrderId((string) $content['payPalOrderId']);
70+
}
4871

4972
/** @var OrderInterface $order */
5073
$order = $payment->getOrder();
5174

52-
$this->stateMachineFactory->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CANCEL);
75+
if ($this->stateMachineFactory->can($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CANCEL)) {
76+
$this->stateMachineFactory->apply($payment, PaymentTransitions::GRAPH, PaymentTransitions::TRANSITION_CANCEL);
5377

54-
$this->orderPaymentProcessor->process($order);
55-
$this->objectManager->flush();
78+
$this->orderPaymentProcessor->process($order);
79+
$this->objectManager->flush();
5680

57-
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)
58-
->add('success', 'sylius_paypal.payment_cancelled')
59-
;
81+
FlashBagProvider::getFlashBag($this->flashBagOrRequestStack)
82+
->add('success', 'sylius_paypal.payment_cancelled')
83+
;
84+
}
6085

6186
return new Response('', Response::HTTP_NO_CONTENT);
6287
}

0 commit comments

Comments
 (0)