Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f4d63b2
Use constructor property promotion
maikrosenthal Jun 11, 2024
a97fada
Fixed wrong attribute invoice_number
maikrosenthal Jun 11, 2024
b7ab860
Also transmit the shipping discount
maikrosenthal Jun 11, 2024
1178884
Implemented suggested changes
maikrosenthal Jun 19, 2024
7c1b1fc
bug #296 Fix and enhance PayPalPurchaseUnit (maikrosenthal)
GSadee Jul 2, 2024
6c00cf2
Removed unused constructor parameter
maikrosenthal Jun 13, 2024
2396d67
Use constructor property promotion
maikrosenthal Jun 13, 2024
5c6905e
Fixed an issue where the parameterBag returns a non-scalar value
maikrosenthal Jun 13, 2024
3e5f710
Added an upgrade note
GSadee Jul 2, 2024
63d31b9
Move note to the proper version in UPGRADE file
GSadee Jul 2, 2024
71c9bc2
bug #297 Fix and clean up UpdatePayPalOrderAction (maikrosenthal, GSa…
GSadee Jul 2, 2024
a75f2d2
Do not add the customer to the address
maikrosenthal Jun 18, 2024
464d258
Save the full name of the shipping address
maikrosenthal Jun 18, 2024
415eda5
Removed unused constructor parameter
maikrosenthal Jun 18, 2024
907e648
bug #299 Fix ProcessPayPalOrderAction (maikrosenthal)
GSadee Jul 18, 2024
b329228
[Shop] Fix paypal checkout when another payment method was selected d…
Wojdylak Mar 13, 2025
b9cea8b
Fix deprecated github action
Wojdylak Mar 13, 2025
b8e8417
Minor improvements
Wojdylak Mar 13, 2025
6b6c8c3
Minor improvements
Wojdylak Mar 14, 2025
ebef1ac
Upgrade update file
Wojdylak Mar 14, 2025
18c95f0
Remove phpstan.neon
Wojdylak Mar 14, 2025
9e97a9b
[Shop] Fix paypal checkout when another payment method was selected d…
GSadee Mar 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ jobs:

-
name: Upload Behat logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: Behat logs
path: etc/build/
if-no-files-found: ignore
overwrite: true
84 changes: 77 additions & 7 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,74 @@
### UPGRADE FROM 1.5.1 to 1.6
### UPGRADE FROM 1.6.1 to 1.6.2

1. The following constructor signatures have been changed:

`Sylius\PayPalPlugin\Controller\CreatePayPalOrderFromCartAction`:
```diff
public function __construct(
private readonly ?Payum $payum,
private readonly ?OrderRepositoryInterface $orderRepository,
private readonly ?FactoryInterface $stateMachineFactory,
private readonly ObjectManager $paymentManager,
private readonly OrderProviderInterface $orderProvider,
private readonly CapturePaymentResolverInterface $capturePaymentResolver,
+ private readonly ?OrderPaymentsRemoverInterface $orderPaymentsRemover = null,
+ private readonly ?OrderProcessorInterface $orderProcessor = null,
)
```

### UPGRADE FROM 1.6.0 to 1.6.1

1. The following constructor signatures have been changed:

`Sylius\PayPalPlugin\Controller\UpdatePayPalOrderAction`:
```diff
public function __construct(
private readonly PaymentProviderInterface $paymentProvider,
private readonly CacheAuthorizeClientApiInterface $authorizeClientApi,
- private readonly OrderDetailsApiInterface $orderDetailsApi,
private readonly UpdateOrderApiInterface $updateOrderApi,
private readonly AddressFactoryInterface $addressFactory,
private readonly OrderProcessorInterface $orderProcessor,
)
```

`Sylius\PayPalPlugin\Model\PayPalPurchaseUnit`:
```diff
public function __construct(
private readonly string $referenceId,
private readonly string $invoiceNumber,
private readonly string $currencyCode,
private readonly int $totalAmount,
private readonly int $shippingValue,
private readonly float $itemTotalValue,
private readonly float $taxTotalValue,
private readonly int $discountValue,
private readonly string $merchantId,
private readonly array $items,
private readonly bool $shippingRequired,
private readonly ?AddressInterface $shippingAddress = null,
private readonly string $softDescriptor = 'Sylius PayPal Payment',
+ private readonly int $shippingDiscountValue = 0,
)
```

`Sylius\PayPalPlugin\Controller\ProcessPayPalOrderAction`:
```diff
public function __construct(
- private readonly OrderRepositoryInterface $orderRepository,
private readonly CustomerRepositoryInterface $customerRepository,
private readonly FactoryInterface $customerFactory,
private readonly AddressFactoryInterface $addressFactory,
private readonly ObjectManager $orderManager,
private readonly StateMachineFactoryInterface|StateMachineInterface $stateMachineFactory,
private readonly PaymentStateManagerInterface $paymentStateManager,
private readonly CacheAuthorizeClientApiInterface $authorizeClientApi,
private readonly OrderDetailsApiInterface $orderDetailsApi,
private readonly OrderProviderInterface $orderProvider,
)
```

### UPGRADE FROM 1.5.1 to 1.6.0

1. Support for Sylius 1.13 has been added, it is now the recommended Sylius version to use.

Expand All @@ -12,9 +82,9 @@
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
private readonly LoggerInterface $logger,
private readonly UuidProviderInterface $uuidProvider,
Expand All @@ -33,7 +103,7 @@
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
Expand All @@ -47,7 +117,7 @@
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
Expand All @@ -62,7 +132,7 @@
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;

public function __construct(
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
Expand All @@ -71,7 +141,7 @@
+ private readonly ?RequestFactoryInterface $requestFactory = null,
)
```

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
90 changes: 87 additions & 3 deletions spec/Api/CreateOrderApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
Expand Down Expand Up @@ -57,6 +58,7 @@ function it_creates_pay_pal_order_based_on_given_payment(
$order->getShippingTotal()->willReturn(1000);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$payPalItemDataProvider->provide($order)->willReturn([
'items' => [
Expand Down Expand Up @@ -92,7 +94,7 @@ function it_creates_pay_pal_order_based_on_given_payment(
Argument::that(function (array $data): bool {
return
$data['intent'] === 'CAPTURE' &&
$data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['invoice_id'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['amount']['value'] === '100.00' &&
$data['purchase_units'][0]['amount']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' &&
Expand Down Expand Up @@ -126,6 +128,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment(
$order->getShippingTotal()->willReturn(1000);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$shippingAddress->getFullName()->willReturn('Gandalf The Grey');
$shippingAddress->getStreet()->willReturn('Hobbit St. 123');
Expand Down Expand Up @@ -167,7 +170,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment(
Argument::that(function (array $data): bool {
return
$data['intent'] === 'CAPTURE' &&
$data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['invoice_id'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['amount']['value'] === '100.00' &&
$data['purchase_units'][0]['amount']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['shipping']['name']['full_name'] === 'Gandalf The Grey' &&
Expand Down Expand Up @@ -204,6 +207,7 @@ function it_creates_pay_pal_order_with_more_than_one_product(
$order->getShippingTotal()->willReturn(3000);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$shippingAddress->getFullName()->willReturn('Gandalf The Grey');
$shippingAddress->getStreet()->willReturn('Hobbit St. 123');
Expand Down Expand Up @@ -297,6 +301,7 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity(
$order->getShippingTotal()->willReturn(1000);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$shippingAddress->getFullName()->willReturn('Gandalf The Grey');
$shippingAddress->getStreet()->willReturn('Hobbit St. 123');
Expand Down Expand Up @@ -394,6 +399,7 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_
$order->getShippingTotal()->willReturn(3000);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$shippingAddress->getFullName()->willReturn('Gandalf The Grey');
$shippingAddress->getStreet()->willReturn('Hobbit St. 123');
Expand Down Expand Up @@ -509,6 +515,7 @@ function it_allows_to_create_digital_order(
$order->getShippingTotal()->willReturn(0);
$order->isShippingRequired()->willReturn(false);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$payPalItemDataProvider->provide($order)->willReturn([
'items' => [
Expand Down Expand Up @@ -573,6 +580,7 @@ function it_creates_pay_pal_order_with_promotion(
$order->getShippingTotal()->willReturn(749);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(-250);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$payPalItemDataProvider->provide($order)->willReturn([
'items' => [
Expand Down Expand Up @@ -608,7 +616,7 @@ function it_creates_pay_pal_order_with_promotion(
Argument::that(function (array $data): bool {
return
$data['intent'] === 'CAPTURE' &&
$data['purchase_units'][0]['invoice_number'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['invoice_id'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['amount']['value'] === '29.99' &&
$data['purchase_units'][0]['amount']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' &&
Expand All @@ -627,4 +635,80 @@ function it_creates_pay_pal_order_with_promotion(

$this->create('TOKEN', $payment, 'REFERENCE_ID')->shouldReturn(['status' => 'CREATED', 'id' => 123]);
}

function it_creates_pay_pal_order_with_shipping_promotion(
PayPalClientInterface $client,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PaymentInterface $payment,
OrderInterface $order,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(3000);
$order->getCurrencyCode()->willReturn('PLN');
$order->getShippingAddress()->willReturn(null);
$order->getItemsTotal()->willReturn(2500);
$order->getShippingTotal()->willReturn(500);
$order->isShippingRequired()->willReturn(true);
$order->getOrderPromotionTotal()->willReturn(0);
$order
->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)
->willReturn(-249)
;

$payPalItemDataProvider->provide($order)->willReturn([
'items' => [
[
'name' => 'PRODUCT_ONE',
'unit_amount' => [
'value' => '25.00',
'currency_code' => 'PLN',
],
'quantity' => 1,
'tax' => [
'value' => '0.00',
'currency_code' => 'PLN',
],
],
],
'total_item_value' => '25.00',
'total_tax' => '0.00',
]);

$payment->getMethod()->willReturn($paymentMethod);
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);

$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');

$gatewayConfig->getConfig()->willReturn(
['merchant_id' => 'merchant-id', 'sylius_merchant_id' => 'sylius-merchant-id'],
);

$client->post(
'v2/checkout/orders',
'TOKEN',
Argument::that(function (array $data): bool {
return
$data['intent'] === 'CAPTURE' &&
$data['purchase_units'][0]['invoice_id'] === 'REFERENCE-NUMBER' &&
$data['purchase_units'][0]['amount']['value'] === '30.00' &&
$data['purchase_units'][0]['amount']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['amount']['breakdown']['shipping']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['amount']['breakdown']['shipping']['value'] === '7.49' &&
$data['purchase_units'][0]['amount']['breakdown']['item_total']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['amount']['breakdown']['item_total']['value'] === '25.00' &&
$data['purchase_units'][0]['amount']['breakdown']['shipping_discount']['currency_code'] === 'PLN' &&
$data['purchase_units'][0]['amount']['breakdown']['shipping_discount']['value'] === '2.49' &&
$data['purchase_units'][0]['items'][0]['name'] === 'PRODUCT_ONE' &&
$data['purchase_units'][0]['items'][0]['quantity'] === 1 &&
$data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '25.00' &&
$data['purchase_units'][0]['items'][0]['unit_amount']['currency_code'] === 'PLN'
;
}),
)->willReturn(['status' => 'CREATED', 'id' => 123]);

$this->create('TOKEN', $payment, 'REFERENCE_ID')->shouldReturn(['status' => 'CREATED', 'id' => 123]);
}
}
2 changes: 1 addition & 1 deletion spec/Api/RefundPaymentApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function it_refunds_pay_pal_payment_with_given_id(PayPalClientInterface $client)
->post(
'v2/payments/captures/123123/refund',
'TOKEN',
['amount' => ['value' => '10.99', 'currency_code' => 'USD'], 'invoice_number' => '123-11-11-2010'],
['amount' => ['value' => '10.99', 'currency_code' => 'USD'], 'invoice_id' => '123-11-11-2010'],
['PayPal-Auth-Assertion' => 'PAY-PAL-AUTH-ASSERTION'],
)
->willReturn(['status' => 'COMPLETED', 'id' => '123123'])
Expand Down
11 changes: 7 additions & 4 deletions spec/Api/UpdateOrderApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\PayPalPlugin\Api\UpdateOrderApiInterface;
Expand Down Expand Up @@ -55,12 +56,13 @@ function it_updates_pay_pal_order_with_given_new_total(
->willReturn(['items' => ['data'], 'total_item_value' => '10.00', 'total_tax' => '1.00'])
;

$paymentReferenceNumberProvider->provide($payment)->willReturn('INVOICE_NUMBER');
$paymentReferenceNumberProvider->provide($payment)->willReturn('INVOICE_ID');

$order->getTotal()->willReturn(1122);
$order->getCurrencyCode()->willReturn('USD');
$order->getShippingTotal()->willReturn(22);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$shippingAddress->getFullName()->willReturn('John Doe');
$shippingAddress->getStreet()->willReturn('Main St. 123');
Expand All @@ -78,7 +80,7 @@ function it_updates_pay_pal_order_with_given_new_total(
$data[0]['op'] === 'replace' &&
$data[0]['path'] === '/purchase_units/@reference_id==\'REFERENCE-ID\'' &&
$data[0]['value']['reference_id'] === 'REFERENCE-ID' &&
$data[0]['value']['invoice_number'] === 'INVOICE_NUMBER' &&
$data[0]['value']['invoice_id'] === 'INVOICE_ID' &&
$data[0]['value']['amount']['value'] === '11.22' &&
$data[0]['value']['amount']['currency_code'] === 'USD' &&
$data[0]['value']['amount']['breakdown']['shipping']['value'] === '0.22' &&
Expand Down Expand Up @@ -115,12 +117,13 @@ function it_updates_digital_order(
->willReturn(['items' => ['data'], 'total_item_value' => '10.00', 'total_tax' => '1.22'])
;

$paymentReferenceNumberProvider->provide($payment)->willReturn('INVOICE_NUMBER');
$paymentReferenceNumberProvider->provide($payment)->willReturn('INVOICE_ID');

$order->getTotal()->willReturn(1122);
$order->getCurrencyCode()->willReturn('USD');
$order->getShippingTotal()->willReturn(0);
$order->getOrderPromotionTotal()->willReturn(0);
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0);

$order->isShippingRequired()->willReturn(false);

Expand All @@ -132,7 +135,7 @@ function it_updates_digital_order(
$data[0]['op'] === 'replace' &&
$data[0]['path'] === '/purchase_units/@reference_id==\'REFERENCE-ID\'' &&
$data[0]['value']['reference_id'] === 'REFERENCE-ID' &&
$data[0]['value']['invoice_number'] === 'INVOICE_NUMBER' &&
$data[0]['value']['invoice_id'] === 'INVOICE_ID' &&
$data[0]['value']['amount']['value'] === '11.22' &&
$data[0]['value']['amount']['currency_code'] === 'USD' &&
$data[0]['value']['amount']['breakdown']['shipping']['value'] === '0.00' &&
Expand Down
Loading