Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed Apr 5, 2024
1 parent 68f8f73 commit 467ed22
Show file tree
Hide file tree
Showing 50 changed files with 312 additions and 308 deletions.
10 changes: 5 additions & 5 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
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,
+ private readonly ?StreamFactoryInterface $streamFactory = null,
- private readonly GuzzleClientInterface $client,
+ private readonly GuzzleClientInterface|ClientInterface $client,
private readonly string $baseUrl,
+ private readonly ?RequestFactoryInterface $requestFactory = null,
+ private readonly ?StreamFactoryInterface $streamFactory = null,
)
```

Expand Down
9 changes: 6 additions & 3 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

return static function (ECSConfig $config): void {
$config->paths([
__DIR__ . '/src',
__DIR__ . '/tests/Behat',
__DIR__ . '/ecs.php',
'src',
'spec',
'tests/Behat',
'tests/Functional',
'tests/Service',
'tests/Unit',
]);

$config->import('vendor/sylius-labs/coding-standard/ecs.php');
Expand Down
10 changes: 5 additions & 5 deletions spec/Api/CacheAuthorizeClientApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function let(
ObjectManager $payPalCredentialsManager,
ObjectRepository $payPalCredentialsRepository,
AuthorizeClientApiInterface $authorizeClientApi,
UuidProviderInterface $uuidProvider
UuidProviderInterface $uuidProvider,
): void {
$this->beConstructedWith(
$payPalCredentialsManager,
$payPalCredentialsRepository,
$authorizeClientApi,
$uuidProvider
$uuidProvider,
);
}

Expand All @@ -48,7 +48,7 @@ function it_implements_cache_authorize_client_api_interface(): void
function it_returns_cached_access_token_if_it_is_not_expired(
ObjectRepository $payPalCredentialsRepository,
PayPalCredentialsInterface $payPalCredentials,
PaymentMethodInterface $paymentMethod
PaymentMethodInterface $paymentMethod,
): void {
$payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod])->willReturn($payPalCredentials);

Expand All @@ -64,7 +64,7 @@ function it_gets_access_token_from_api_caches_and_returns_it(
AuthorizeClientApiInterface $authorizeClientApi,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
UuidProviderInterface $uuidProvider
UuidProviderInterface $uuidProvider,
): void {
$payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod])->willReturn(null);

Expand Down Expand Up @@ -98,7 +98,7 @@ function it_returns_expired_token_and_ask_for_a_new_one(
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
PayPalCredentialsInterface $payPalCredentials,
UuidProviderInterface $uuidProvider
UuidProviderInterface $uuidProvider,
): void {
$payPalCredentialsRepository->findOneBy(['paymentMethod' => $paymentMethod])->willReturn($payPalCredentials);
$payPalCredentials->isExpired()->willReturn(true);
Expand Down
2 changes: 1 addition & 1 deletion spec/Api/CompleteOrderApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function it_implements_complete_order_api_interface(): void
function it_completes_pay_pal_order_with_given_id(
PayPalClientInterface $client,
PaymentInterface $payment,
OrderInterface $order
OrderInterface $order,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(10000);
Expand Down
46 changes: 23 additions & 23 deletions spec/Api/CreateOrderApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class CreateOrderApiSpec extends ObjectBehavior
function let(
PayPalClientInterface $client,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$this->beConstructedWith($client, $paymentReferenceNumberProvider, $payPalItemDataProvider);
}
Expand All @@ -47,7 +47,7 @@ function it_creates_pay_pal_order_based_on_given_payment(
OrderInterface $order,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(10000);
Expand Down Expand Up @@ -83,7 +83,7 @@ function it_creates_pay_pal_order_based_on_given_payment(
$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');

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

$client->post(
Expand All @@ -102,7 +102,7 @@ function it_creates_pay_pal_order_based_on_given_payment(
$data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '90.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]);
Expand All @@ -116,7 +116,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment(
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
AddressInterface $shippingAddress,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(10000);
Expand Down Expand Up @@ -158,7 +158,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment(
$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');

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

$client->post(
Expand All @@ -180,7 +180,7 @@ function it_creates_pay_pal_order_with_shipping_address_based_on_given_payment(
$data['purchase_units'][0]['items'][0]['unit_amount']['value'] === '90.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]);
Expand All @@ -194,7 +194,7 @@ function it_creates_pay_pal_order_with_more_than_one_product(
GatewayConfigInterface $gatewayConfig,
AddressInterface $shippingAddress,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(20000);
Expand Down Expand Up @@ -246,7 +246,7 @@ function it_creates_pay_pal_order_with_more_than_one_product(
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);

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

$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');
Expand All @@ -273,7 +273,7 @@ function it_creates_pay_pal_order_with_more_than_one_product(
$data['purchase_units'][0]['items'][1]['unit_amount']['value'] === '40.00' &&
$data['purchase_units'][0]['items'][1]['unit_amount']['currency_code'] === 'PLN'
;
})
}),
)->willReturn(['status' => 'CREATED', 'id' => 123]);

$this->create('TOKEN', $payment, 'REFERENCE_ID')->shouldReturn(['status' => 'CREATED', 'id' => 123]);
Expand All @@ -287,7 +287,7 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity(
GatewayConfigInterface $gatewayConfig,
AddressInterface $shippingAddress,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(13000);
Expand Down Expand Up @@ -339,7 +339,7 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity(
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);

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

$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');
Expand Down Expand Up @@ -370,7 +370,7 @@ function it_creates_pay_pal_order_with_non_neutral_tax_and_changed_quantity(
$data['purchase_units'][0]['items'][1]['tax']['value'] === '10.00' &&
$data['purchase_units'][0]['items'][1]['tax']['currency_code'] === 'PLN'
;
})
}),
)->willReturn(['status' => 'CREATED', 'id' => 123]);

$this->create('TOKEN', $payment, 'REFERENCE_ID')->shouldReturn(['status' => 'CREATED', 'id' => 123]);
Expand All @@ -384,7 +384,7 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_
GatewayConfigInterface $gatewayConfig,
AddressInterface $shippingAddress,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(20400);
Expand Down Expand Up @@ -448,7 +448,7 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);

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

$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');
Expand Down Expand Up @@ -485,7 +485,7 @@ function it_creates_pay_pal_order_with_more_than_one_product_with_different_tax_
$data['purchase_units'][0]['items'][2]['tax']['value'] === '1.00' &&
$data['purchase_units'][0]['items'][2]['tax']['currency_code'] === 'PLN'
;
})
}),
)->willReturn(['status' => 'CREATED', 'id' => 123]);

$this->create('TOKEN', $payment, 'REFERENCE_ID')->shouldReturn(['status' => 'CREATED', 'id' => 123]);
Expand All @@ -499,7 +499,7 @@ function it_allows_to_create_digital_order(
GatewayConfigInterface $gatewayConfig,
AddressInterface $shippingAddress,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(20000);
Expand Down Expand Up @@ -533,7 +533,7 @@ function it_allows_to_create_digital_order(
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);

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

$order->setShippingAddress(Argument::any())->shouldNotBeCalled();
Expand All @@ -550,7 +550,7 @@ function it_allows_to_create_digital_order(
$data['purchase_units'][0]['amount']['currency_code'] === 'PLN' &&
$data['application_context']['shipping_preference'] === 'NO_SHIPPING'
;
})
}),
)->willReturn(['status' => 'CREATED', 'id' => 123]);

$this->create('TOKEN', $payment, 'REFERENCE_ID')->shouldReturn(['status' => 'CREATED', 'id' => 123]);
Expand All @@ -563,7 +563,7 @@ function it_creates_pay_pal_order_with_promotion(
OrderInterface $order,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
PayPalItemDataProviderInterface $payPalItemDataProvider
PayPalItemDataProviderInterface $payPalItemDataProvider,
): void {
$payment->getOrder()->willReturn($order);
$payment->getAmount()->willReturn(2999);
Expand Down Expand Up @@ -599,7 +599,7 @@ function it_creates_pay_pal_order_with_promotion(
$paymentReferenceNumberProvider->provide($payment)->willReturn('REFERENCE-NUMBER');

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

$client->post(
Expand All @@ -621,8 +621,8 @@ function it_creates_pay_pal_order_with_promotion(
$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]);
Expand Down
7 changes: 3 additions & 4 deletions spec/Api/GenericApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace spec\Sylius\PayPalPlugin\Api;

use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use PhpSpec\ObjectBehavior;
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -39,9 +39,8 @@ function it_calls_api_by_url(
RequestFactoryInterface $requestFactory,
RequestInterface $request,
ResponseInterface $response,
StreamInterface $body
StreamInterface $body,
): void {

$requestFactory->createRequest('GET', 'http://url.com/')->willReturn($request);

$request->withHeader('Authorization', 'Bearer TOKEN')->willReturn($request);
Expand All @@ -58,7 +57,7 @@ function it_calls_api_by_url(
function it_calls_api_by_url_using_guzzle_client(
GuzzleClientInterface $client,
ResponseInterface $response,
StreamInterface $body
StreamInterface $body,
): void {
$this->beConstructedWith($client);

Expand Down
2 changes: 1 addition & 1 deletion spec/Api/RefundPaymentApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function it_refunds_pay_pal_payment_with_given_id(PayPalClientInterface $client)
'v2/payments/captures/123123/refund',
'TOKEN',
['amount' => ['value' => '10.99', 'currency_code' => 'USD'], 'invoice_number' => '123-11-11-2010'],
['PayPal-Auth-Assertion' => 'PAY-PAL-AUTH-ASSERTION']
['PayPal-Auth-Assertion' => 'PAY-PAL-AUTH-ASSERTION'],
)
->willReturn(['status' => 'COMPLETED', 'id' => '123123'])
;
Expand Down
10 changes: 5 additions & 5 deletions spec/Api/UpdateOrderApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class UpdateOrderApiSpec extends ObjectBehavior
function let(
PayPalClientInterface $client,
PaymentReferenceNumberProviderInterface $paymentReferenceNumberProvider,
PayPalItemDataProviderInterface $payPalItemsDataProvider
PayPalItemDataProviderInterface $payPalItemsDataProvider,
): void {
$this->beConstructedWith($client, $paymentReferenceNumberProvider, $payPalItemsDataProvider);
}
Expand All @@ -44,7 +44,7 @@ function it_updates_pay_pal_order_with_given_new_total(
PayPalItemDataProviderInterface $payPalItemsDataProvider,
PaymentInterface $payment,
OrderInterface $order,
AddressInterface $shippingAddress
AddressInterface $shippingAddress,
): void {
$payment->getOrder()->willReturn($order);
$order->getShippingAddress()->willReturn($shippingAddress);
Expand Down Expand Up @@ -92,7 +92,7 @@ function it_updates_pay_pal_order_with_given_new_total(
$data[0]['value']['shipping']['address']['country_code'] === 'US' &&
$data[0]['value']['items'] === ['data']
;
})
}),
)->shouldBeCalled();

$this->update('TOKEN', 'ORDER-ID', $payment, 'REFERENCE-ID', 'MERCHANT-ID');
Expand All @@ -104,7 +104,7 @@ function it_updates_digital_order(
PayPalItemDataProviderInterface $payPalItemsDataProvider,
PaymentInterface $payment,
OrderInterface $order,
AddressInterface $shippingAddress
AddressInterface $shippingAddress,
): void {
$payment->getOrder()->willReturn($order);
$order->getShippingAddress()->willReturn($shippingAddress);
Expand Down Expand Up @@ -141,7 +141,7 @@ function it_updates_digital_order(
$data[0]['value']['payee']['merchant_id'] === 'MERCHANT-ID' &&
$data[0]['value']['items'] === ['data']
;
})
}),
)->shouldBeCalled();

$this->update('TOKEN', 'ORDER-ID', $payment, 'REFERENCE-ID', 'MERCHANT-ID');
Expand Down
Loading

0 comments on commit 467ed22

Please sign in to comment.