Skip to content

Commit f5b94dd

Browse files
authored
[UPMERGE] 1.7 -> 2.0 (#361)
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 063d669 + cd7faa3 commit f5b94dd

File tree

11 files changed

+314
-12
lines changed

11 files changed

+314
-12
lines changed

UPGRADE-2.0.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
### UPGRADE FROM 2.0.2 to 2.0.3
2+
3+
1. #### Removed overwriting of shipping address in `CompleteOrderAction` and introduced shipping address update to PayPal.
4+
Previously, the `Sylius\PayPalPlugin\Payum\Action\CompleteOrderAction` class retrieved the shipping address from PayPal after order completion and overwrote
5+
the existing shipping address in Sylius. This behavior was incorrect because if a customer changed their address after completing the PayPal checkout,
6+
the system would revert it back to the PayPal-provided address.
7+
8+
This mechanism has been removed. Instead, a new mechanism has been introduced: if shipping is required, the order completion process now updates
9+
the PayPal shipping address with the one stored in Sylius. This ensures that the shipping address remains consistent with the one confirmed in the store.
10+
11+
1. The following classes have been deprecated and will be removed in Sylius/PayPalPlugin 3.0:
12+
- `Sylius\PayPalPlugin\Processor\PayPalAddressProcessor`
13+
- `Sylius\PayPalPlugin\Processor\PayPalAddressProcessorInterface`
14+
15+
1. The following constructor signatures have been changed:
16+
17+
`Sylius\PayPalPlugin\Payum\Action\CompleteOrderAction`:
18+
```diff
19+
public function __construct(
20+
private CacheAuthorizeClientApiInterface $authorizeClientApi,
21+
private UpdateOrderApiInterface $updateOrderApi,
22+
private CompleteOrderApiInterface $completeOrderApi,
23+
private OrderDetailsApiInterface $orderDetailsApi,
24+
- private PayPalAddressProcessorInterface $payPalAddressProcessor,
25+
+ private ?PayPalAddressProcessorInterface $payPalAddressProcessor,
26+
private PaymentUpdaterInterface $payPalPaymentUpdater,
27+
private StateResolverInterface $orderPaymentStateResolver,
28+
+ private ?UpdateOrderAddressApiInterface $updateOrderAddressApi = null,
29+
)
30+
```
31+
132
### UPGRADE FROM 2.0.0 to 2.0.1
233

334
1. The following constructor signatures have been changed:

config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227

228228
<service id="sylius_paypal.processor.paypal_address" class="Sylius\PayPalPlugin\Processor\PayPalAddressProcessor">
229229
<argument type="service" id="doctrine.orm.entity_manager" />
230+
<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>
230231
</service>
231232

232233
<service

config/services/api.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@
128128
</service>
129129
<service id="Sylius\PayPalPlugin\Api\UpdateOrderApiInterface" alias="sylius_paypal.api.update_order" />
130130

131+
<service
132+
id="sylius_paypal.api.update_order_address"
133+
class="Sylius\PayPalPlugin\Api\UpdateOrderAddressApi"
134+
>
135+
<argument type="service" id="sylius_paypal.client.paypal" />
136+
</service>
137+
131138
<service
132139
id="sylius_paypal.api.refund_payment"
133140
class="Sylius\PayPalPlugin\Api\RefundPaymentApi"

config/services/payum.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
<argument type="service" id="sylius_paypal.api.update_order" />
4242
<argument type="service" id="sylius_paypal.api.complete_order" />
4343
<argument type="service" id="sylius_paypal.api.order_details" />
44-
<argument type="service" id="sylius_paypal.processor.paypal_address" />
44+
<argument>null</argument>
4545
<argument type="service" id="sylius_paypal.updater.payment" />
4646
<argument type="service" id="sylius.state_resolver.order_payment" />
47+
<argument type="service" id="sylius_paypal.api.update_order_address" />
4748
<tag name="payum.action" factory="sylius_paypal" alias="payum.action.complete_order" />
4849
</service>
4950

spec/Payum/Action/CompleteOrderActionSpec.php

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515

1616
use Payum\Core\Action\ActionInterface;
1717
use PhpSpec\ObjectBehavior;
18+
use Sylius\Component\Core\Model\AddressInterface;
1819
use Sylius\Component\Core\Model\OrderInterface;
1920
use Sylius\Component\Core\Model\PaymentInterface;
2021
use Sylius\Component\Core\Model\PaymentMethodInterface;
2122
use Sylius\Component\Order\StateResolver\StateResolverInterface;
2223
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface;
2324
use Sylius\PayPalPlugin\Api\CompleteOrderApiInterface;
2425
use Sylius\PayPalPlugin\Api\OrderDetailsApiInterface;
26+
use Sylius\PayPalPlugin\Api\UpdateOrderAddressApiInterface;
2527
use Sylius\PayPalPlugin\Api\UpdateOrderApiInterface;
2628
use Sylius\PayPalPlugin\Payum\Action\StatusAction;
2729
use Sylius\PayPalPlugin\Payum\Request\CompleteOrder;
28-
use Sylius\PayPalPlugin\Processor\PayPalAddressProcessorInterface;
29-
use Sylius\PayPalPlugin\Provider\PayPalItemDataProviderInterface;
3030
use Sylius\PayPalPlugin\Updater\PaymentUpdaterInterface;
3131

3232
final class CompleteOrderActionSpec extends ObjectBehavior
@@ -36,20 +36,18 @@ function let(
3636
UpdateOrderApiInterface $updateOrderApi,
3737
CompleteOrderApiInterface $completeOrderApi,
3838
OrderDetailsApiInterface $orderDetailsApi,
39-
PayPalAddressProcessorInterface $payPalAddressProcessor,
4039
PaymentUpdaterInterface $payPalPaymentUpdater,
4140
StateResolverInterface $orderPaymentStateResolver,
42-
PayPalItemDataProviderInterface $payPalItemsDataProvider,
4341
): void {
4442
$this->beConstructedWith(
4543
$authorizeClientApi,
4644
$updateOrderApi,
4745
$completeOrderApi,
4846
$orderDetailsApi,
49-
$payPalAddressProcessor,
47+
null,
5048
$payPalPaymentUpdater,
5149
$orderPaymentStateResolver,
52-
$payPalItemsDataProvider,
50+
null,
5351
);
5452
}
5553

@@ -143,4 +141,67 @@ function it_completes_order_and_saves_transaction_id(
143141

144142
$this->execute($request);
145143
}
144+
145+
function it_updates_paypal_shipping_address_and_completes_order(
146+
CacheAuthorizeClientApiInterface $authorizeClientApi,
147+
UpdateOrderApiInterface $updateOrderApi,
148+
CompleteOrderApiInterface $completeOrderApi,
149+
OrderDetailsApiInterface $orderDetailsApi,
150+
PaymentUpdaterInterface $payPalPaymentUpdater,
151+
StateResolverInterface $orderPaymentStateResolver,
152+
UpdateOrderAddressApiInterface $updateOrderAddressApi,
153+
CompleteOrder $request,
154+
PaymentInterface $payment,
155+
PaymentMethodInterface $paymentMethod,
156+
OrderInterface $order,
157+
AddressInterface $shippingAddress,
158+
): void {
159+
$this->beConstructedWith(
160+
$authorizeClientApi,
161+
$updateOrderApi,
162+
$completeOrderApi,
163+
$orderDetailsApi,
164+
null,
165+
$payPalPaymentUpdater,
166+
$orderPaymentStateResolver,
167+
$updateOrderAddressApi,
168+
);
169+
170+
$request->getModel()->willReturn($payment);
171+
$payment->getMethod()->willReturn($paymentMethod);
172+
$payment->getDetails()->willReturn([
173+
'paypal_order_id' => '123123',
174+
'reference_id' => 'REFERENCE_ID',
175+
]);
176+
$payment->getOrder()->willReturn($order);
177+
178+
$authorizeClientApi->authorize($paymentMethod)->willReturn('TOKEN');
179+
180+
$request->getOrderId()->willReturn('123123');
181+
182+
$payment->getAmount()->willReturn(1000);
183+
$order->getTotal()->willReturn(1000);
184+
185+
$completeOrderApi->complete('TOKEN', '123123')->shouldBeCalled();
186+
$orderDetailsApi->get('TOKEN', '123123')->willReturn([
187+
'status' => 'COMPLETED',
188+
'id' => '123123',
189+
'purchase_units' => [
190+
['reference_id' => 'REFERENCE_ID'],
191+
],
192+
]);
193+
194+
$payment->setDetails([
195+
'status' => StatusAction::STATUS_COMPLETED,
196+
'paypal_order_id' => '123123',
197+
'reference_id' => 'REFERENCE_ID',
198+
])->shouldBeCalled();
199+
200+
$order->isShippingRequired()->willReturn(true);
201+
$order->getShippingAddress()->willReturn($shippingAddress);
202+
203+
$this->execute($request);
204+
205+
$updateOrderAddressApi->update('TOKEN', '123123', 'REFERENCE_ID', $shippingAddress)->shouldHaveBeenCalled();
206+
}
146207
}

src/Api/UpdateOrderAddressApi.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\PayPalPlugin\Api;
15+
16+
use Sylius\Component\Core\Model\AddressInterface;
17+
use Sylius\PayPalPlugin\Client\PayPalClientInterface;
18+
19+
final class UpdateOrderAddressApi implements UpdateOrderAddressApiInterface
20+
{
21+
public function __construct(
22+
private PayPalClientInterface $client,
23+
) {
24+
}
25+
26+
public function update(
27+
string $token,
28+
string $orderId,
29+
string $referenceId,
30+
AddressInterface $shippingAddress,
31+
): void {
32+
$this->client->patch(
33+
sprintf('v2/checkout/orders/%s', $orderId),
34+
$token,
35+
[
36+
[
37+
'op' => 'replace',
38+
'path' => sprintf('/purchase_units/@reference_id==\'%s\'/shipping/address', $referenceId),
39+
'value' => [
40+
'address_line_1' => $shippingAddress->getStreet(),
41+
'admin_area_2' => $shippingAddress->getCity(),
42+
'postal_code' => $shippingAddress->getPostcode(),
43+
'country_code' => $shippingAddress->getCountryCode(),
44+
],
45+
],
46+
],
47+
);
48+
49+
$this->client->patch(
50+
sprintf('v2/checkout/orders/%s', $orderId),
51+
$token,
52+
[
53+
[
54+
'op' => 'replace',
55+
'path' => sprintf('/purchase_units/@reference_id==\'%s\'/shipping/name', $referenceId),
56+
'value' => [
57+
'full_name' => $shippingAddress->getFullName(),
58+
],
59+
],
60+
],
61+
);
62+
}
63+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\PayPalPlugin\Api;
15+
16+
use Sylius\Component\Core\Model\AddressInterface;
17+
18+
interface UpdateOrderAddressApiInterface
19+
{
20+
public function update(
21+
string $token,
22+
string $orderId,
23+
string $referenceId,
24+
AddressInterface $shippingAddress,
25+
): void;
26+
}

src/Payum/Action/CompleteOrderAction.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface;
2424
use Sylius\PayPalPlugin\Api\CompleteOrderApiInterface;
2525
use Sylius\PayPalPlugin\Api\OrderDetailsApiInterface;
26+
use Sylius\PayPalPlugin\Api\UpdateOrderAddressApiInterface;
2627
use Sylius\PayPalPlugin\Api\UpdateOrderApiInterface;
2728
use Sylius\PayPalPlugin\Payum\Request\CompleteOrder;
2829
use Sylius\PayPalPlugin\Processor\PayPalAddressProcessorInterface;
@@ -35,10 +36,31 @@ public function __construct(
3536
private UpdateOrderApiInterface $updateOrderApi,
3637
private CompleteOrderApiInterface $completeOrderApi,
3738
private OrderDetailsApiInterface $orderDetailsApi,
38-
private PayPalAddressProcessorInterface $payPalAddressProcessor,
39+
private ?PayPalAddressProcessorInterface $payPalAddressProcessor,
3940
private PaymentUpdaterInterface $payPalPaymentUpdater,
4041
private StateResolverInterface $orderPaymentStateResolver,
42+
private ?UpdateOrderAddressApiInterface $updateOrderAddressApi = null,
4143
) {
44+
if (null !== $this->payPalAddressProcessor) {
45+
trigger_deprecation(
46+
'sylius/paypal-plugin',
47+
'1.7',
48+
sprintf(
49+
'Passing an instance of "%s" as the fifth argument is deprecated and will be prohibited in 3.0',
50+
PayPalAddressProcessorInterface::class,
51+
),
52+
);
53+
}
54+
if (null === $this->updateOrderAddressApi) {
55+
trigger_deprecation(
56+
'sylius/paypal-plugin',
57+
'1.7',
58+
sprintf(
59+
'Not passing $updateOrderAddressApi to "%s" constructor is deprecated and will be prohibited in 3.0',
60+
self::class,
61+
),
62+
);
63+
}
4264
}
4365

4466
/** @param CompleteOrder $request */
@@ -73,6 +95,14 @@ public function execute($request): void
7395
$this->orderPaymentStateResolver->resolve($order);
7496
}
7597

98+
if (null !== $this->updateOrderAddressApi && $order->isShippingRequired()) {
99+
$this->updateOrderAddressApi->update(
100+
$token,
101+
(string) $details['paypal_order_id'],
102+
(string) $details['reference_id'],
103+
$order->getShippingAddress(),
104+
);
105+
}
76106
$this->completeOrderApi->complete($token, $request->getOrderId());
77107
$orderDetails = $this->orderDetailsApi->get($token, $request->getOrderId());
78108

@@ -89,10 +119,6 @@ public function execute($request): void
89119
}
90120

91121
$payment->setDetails($details);
92-
93-
if ($order->isShippingRequired()) {
94-
$this->payPalAddressProcessor->process($orderDetails['purchase_units'][0]['shipping']['address'], $order);
95-
}
96122
}
97123

98124
public function supports($request): bool

src/Processor/PayPalAddressProcessor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
use Sylius\Component\Core\Model\OrderInterface;
1818
use Webmozart\Assert\Assert;
1919

20+
trigger_deprecation(
21+
'sylius/paypal-plugin',
22+
'1.7',
23+
'The "%s" class is deprecated and will be removed in Sylius/PayPalPlugin 3.0.',
24+
PayPalAddressProcessor::class,
25+
);
26+
27+
/** @deprecated since Sylius/PayPalPlugin 1.7 and will be removed in Sylius/PayPalPlugin 3.0. */
2028
final readonly class PayPalAddressProcessor implements PayPalAddressProcessorInterface
2129
{
2230
public function __construct(private ObjectManager $objectManager)

src/Processor/PayPalAddressProcessorInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515

1616
use Sylius\Component\Core\Model\OrderInterface;
1717

18+
trigger_deprecation(
19+
'sylius/paypal-plugin',
20+
'1.7',
21+
'The "%s" class is deprecated and will be removed in Sylius/PayPalPlugin 3.0.',
22+
PayPalAddressProcessorInterface::class,
23+
);
24+
25+
/** @deprecated since Sylius/PayPalPlugin 1.7 and will be removed in Sylius/PayPalPlugin 3.0. */
1826
interface PayPalAddressProcessorInterface
1927
{
2028
/**

0 commit comments

Comments
 (0)