Skip to content

Commit

Permalink
Merge pull request #35 from FLUX-SE/stripe-price-api
Browse files Browse the repository at this point in the history
Stripe price api
  • Loading branch information
Prometee authored Sep 15, 2022
2 parents 122c07a + b71882c commit 8e23fa3
Show file tree
Hide file tree
Showing 28 changed files with 494 additions and 111 deletions.
30 changes: 23 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ jobs:
php-version: "${{ matrix.php }}"
ini-values: date.timezone=Europe/Paris, opcache.enable=1, opcache.enable_cli=0, opcache.memory_consumption=512, opcache.max_accelerated_files=65407, opcache.interned_strings_buffer=8, opcache.validate_timestamps=0, opcache.save_comments=1, opcache.fast_shutdown=0
extensions: intl, gd, opcache, mysql, pdo_mysql
tools: symfony
tools: flex,symfony
coverage: none

-
name: Restrict Symfony version
name: Configure global composer
if: matrix.symfony != ''
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
composer config extra.symfony.require "${{ matrix.symfony }}"
-
name: Get Composer cache directory
id: composer-cache
Expand All @@ -68,6 +68,8 @@ jobs:
-
name: Install PHP dependencies
run: composer update --no-interaction --no-scripts
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}
id: end-of-setup

-
Expand Down Expand Up @@ -109,7 +111,7 @@ jobs:
matrix:
php: [7.3, 7.4, 8.0]
symfony: [^4.4, ^5.4]
sylius: [~1.8.0, ~1.9.0, ~1.10.0]
sylius: [~1.8.0, ~1.9.0, ~1.10.0, ~1.11.0]
node: [12.x]
mysql: [5.7]

Expand All @@ -126,6 +128,18 @@ jobs:
-
sylius: ~1.10.0
php: 7.3
-
sylius: ~1.10.0 # issue with a missing service declaration : Service "api_platform.error_listener": Parent definition "exception_listener" does not exist.
symfony: ^4.4
-
sylius: ~1.11.0
php: 7.3
-
sylius: ~1.11.0
php: 7.4
-
sylius: ~1.11.0
symfony: ^4.4

env:
APP_ENV: test
Expand All @@ -141,7 +155,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
extensions: intl
tools: symfony
tools: flex,symfony
coverage: none

-
Expand Down Expand Up @@ -192,11 +206,11 @@ jobs:
${{ runner.os }}-php-${{ matrix.php }}-composer-
-
name: Restrict Symfony version
name: Configure global composer
if: matrix.symfony != ''
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
composer config extra.symfony.require "${{ matrix.symfony }}"
-
name: Restrict Sylius version
Expand Down Expand Up @@ -224,6 +238,8 @@ jobs:
-
name: Install PHP dependencies
run: composer install --no-interaction
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

-
name: Get Yarn cache directory
Expand Down
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
},
"require-dev": {
"ext-json": "*",
"behat/mink": "^1.8",
"behat/behat": "^3.7",
"behat/mink": "^1.8",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
Expand All @@ -33,12 +33,13 @@
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"sylius-labs/coding-standard": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.2",
"symfony/debug-bundle": "^4.4 || ^5.2",
"symfony/dotenv": "^4.4 || ^5.2",
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"symfony/browser-kit": "^4.4 || ^5.4",
"symfony/debug-bundle": "^4.4 || ^5.4",
"symfony/dotenv": "^4.4 || ^5.4",
"symfony/intl": "^4.4 || ^5.4",
"symfony/web-profiler-bundle": "^4.4 || ^5.4",
"vimeo/psalm": "^4.6.4"
},
"autoload": {
Expand All @@ -56,7 +57,13 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"phpstan/extension-installer": true,
"symfony/flex": true,
"symfony/thanks": true
}
},
"scripts": {
"post-install-cmd": [
Expand Down
24 changes: 11 additions & 13 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(__DIR__ . '/vendor/sylius-labs/coding-standard/ecs.php');
return static function (ECSConfig $config): void {
$config->import(__DIR__ . '/vendor/sylius-labs/coding-standard/ecs.php');

$services = $containerConfigurator->services();
/**
* Was added to fix this exception:
*
* PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException: [binary_operator_spaces] Invalid configuration:
* The options "align_double_arrow", "align_equals" do not exist. Defined options are: "default", "operators".
* in vendor/friendsofphp/php-cs-fixer/src/AbstractFixer.php on line 155
*/
$services->set(BinaryOperatorSpacesFixer::class);
$services = $config->services();

// PHP 7 compatibility
$services
->set(TrailingCommaInMultilineFixer::class)
->call('configure', [['elements' => ['arrays']]])
;
};
21 changes: 16 additions & 5 deletions spec/Provider/DetailsProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@
use FluxSE\SyliusPayumStripePlugin\Provider\DetailsProvider;
use FluxSE\SyliusPayumStripePlugin\Provider\DetailsProviderInterface;
use FluxSE\SyliusPayumStripePlugin\Provider\LineItemsProviderInterface;
use FluxSE\SyliusPayumStripePlugin\Provider\ModeProviderInterface;
use FluxSE\SyliusPayumStripePlugin\Provider\PaymentMethodTypesProviderInterface;
use PhpSpec\ObjectBehavior;
use Stripe\Checkout\Session;
use Sylius\Component\Core\Model\OrderInterface;

final class DetailsProviderSpec extends ObjectBehavior
{
public function let(
CustomerEmailProviderInterface $customerEmailProvider,
LineItemsProviderInterface $lineItemsProvider,
PaymentMethodTypesProviderInterface $paymentMethodTypesProvider
PaymentMethodTypesProviderInterface $paymentMethodTypesProvider,
ModeProviderInterface $modeProvider
): void {
$this->beConstructedWith(
$customerEmailProvider,
$lineItemsProvider,
$paymentMethodTypesProvider
$paymentMethodTypesProvider,
$modeProvider
);
}

Expand All @@ -36,14 +40,17 @@ public function it_get_full_details(
OrderInterface $order,
CustomerEmailProviderInterface $customerEmailProvider,
LineItemsProviderInterface $lineItemsProvider,
PaymentMethodTypesProviderInterface $paymentMethodTypesProvider
PaymentMethodTypesProviderInterface $paymentMethodTypesProvider,
ModeProviderInterface $modeProvider
): void {
$customerEmailProvider->getCustomerEmail($order)->willReturn('[email protected]');
$lineItemsProvider->getLineItems($order)->willReturn([]);
$paymentMethodTypesProvider->getPaymentMethodTypes($order)->willReturn(['card']);
$modeProvider->getMode($order)->willReturn(Session::MODE_PAYMENT);

$this->getDetails($order)->shouldReturn([
'customer_email' => '[email protected]',
'mode' => Session::MODE_PAYMENT,
'line_items' => [],
'payment_method_types' => ['card'],
]);
Expand All @@ -53,12 +60,16 @@ public function it_get_minimum_details(
OrderInterface $order,
CustomerEmailProviderInterface $customerEmailProvider,
LineItemsProviderInterface $lineItemsProvider,
PaymentMethodTypesProviderInterface $paymentMethodTypesProvider
PaymentMethodTypesProviderInterface $paymentMethodTypesProvider,
ModeProviderInterface $modeProvider
): void {
$customerEmailProvider->getCustomerEmail($order)->willReturn(null);
$lineItemsProvider->getLineItems($order)->willReturn(null);
$paymentMethodTypesProvider->getPaymentMethodTypes($order)->willReturn([]);
$modeProvider->getMode($order)->willReturn(Session::MODE_PAYMENT);

$this->getDetails($order)->shouldReturn([]);
$this->getDetails($order)->shouldReturn([
'mode' => Session::MODE_PAYMENT,
]);
}
}
24 changes: 12 additions & 12 deletions spec/Provider/LineItemImagesProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
use Doctrine\Common\Collections\ArrayCollection;
use FluxSE\SyliusPayumStripePlugin\Provider\LineItemImagesProvider;
use FluxSE\SyliusPayumStripePlugin\Provider\LineItemImagesProviderInterface;
use Liip\ImagineBundle\Templating\FilterExtension;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\ProductImageInterface;
use Sylius\Component\Core\Model\ProductInterface;

final class LineItemImagesProviderSpec extends ObjectBehavior
{
public function let(FilterExtension $filterExtension): void
public function let(CacheManager $imagineCacheManager): void
{
$this->beConstructedWith(
$filterExtension,
$imagineCacheManager,
'my_filter',
'https://somewhere-online.tld/fallbak.jpg'
);
Expand All @@ -34,15 +34,15 @@ public function it_get_image_urls(
OrderItemInterface $orderItem,
ProductInterface $product,
ProductImageInterface $productImage,
FilterExtension $filterExtension
CacheManager $imagineCacheManager
): void {
$productImage->getPath()->willReturn('/path/image.jpg');
$orderItem->getProduct()->willReturn($product);
$product->getImages()->willReturn(new ArrayCollection([
$productImage->getWrappedObject(),
]));
$filterExtension
->filter('/path/image.jpg', 'my_filter')
$imagineCacheManager
->getBrowserPath('/path/image.jpg', 'my_filter')
->willReturn('https://somewhere-online.tld/path/image.jpg');

$this->getImageUrlFromProduct($product)->shouldReturn('https://somewhere-online.tld/path/image.jpg');
Expand All @@ -56,15 +56,15 @@ public function it_get_fallback_image_urls_on_localhost(
OrderItemInterface $orderItem,
ProductInterface $product,
ProductImageInterface $productImage,
FilterExtension $filterExtension
CacheManager $imagineCacheManager
): void {
$productImage->getPath()->willReturn('/path/image.jpg');
$orderItem->getProduct()->willReturn($product);
$product->getImages()->willReturn(new ArrayCollection([
$productImage->getWrappedObject(),
]));
$filterExtension
->filter('/path/image.jpg', 'my_filter')
$imagineCacheManager
->getBrowserPath('/path/image.jpg', 'my_filter')
->willReturn('https://localhost/path/image.jpg');

$this->getImageUrlFromProduct($product)->shouldReturn('https://somewhere-online.tld/fallbak.jpg');
Expand All @@ -77,12 +77,12 @@ public function it_get_fallback_image_urls_on_localhost(
public function it_get_fallback_image_urls__when_there_is_no_image(
OrderItemInterface $orderItem,
ProductInterface $product,
FilterExtension $filterExtension
CacheManager $imagineCacheManager
): void {
$orderItem->getProduct()->willReturn($product);
$product->getImages()->willReturn(new ArrayCollection());
$filterExtension
->filter('https://somewhere-online.tld/fallbak.jpg', 'my_filter')
$imagineCacheManager
->getBrowserPath('https://somewhere-online.tld/fallbak.jpg', 'my_filter')
->willReturn('https://somewhere-online.tld/fallbak.jpg');

$this->getImageUrlFromProduct($product)->shouldReturn('https://somewhere-online.tld/fallbak.jpg');
Expand Down
40 changes: 26 additions & 14 deletions spec/Provider/LineItemProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ public function it_get_line_item(
$lineItemNameProvider->getItemName($orderItem)->willReturn('1x - My item name');

$this->getLineItem($orderItem)->shouldReturn([
'amount' => 1000,
'currency' => 'USD',
'name' => '1x - My item name',
'quantity' => 1,
'images' => [
'/path/image.jpg',
'price_data' => [
'unit_amount' => 1000,
'currency' => 'USD',
'product_data' => [
'name' => '1x - My item name',
'images' => [
'/path/image.jpg',
],
],
],
'quantity' => 1,
]);
}

Expand All @@ -66,11 +70,15 @@ public function it_get_line_item_with_no_images(
$lineItemNameProvider->getItemName($orderItem)->willReturn('1x - My item name');

$this->getLineItem($orderItem)->shouldReturn([
'amount' => 1000,
'currency' => 'USD',
'name' => '1x - My item name',
'price_data' => [
'unit_amount' => 1000,
'currency' => 'USD',
'product_data' => [
'name' => '1x - My item name',
'images' => [],
],
],
'quantity' => 1,
'images' => [],
]);
}

Expand All @@ -87,11 +95,15 @@ public function it_get_line_item_when_quantity_is_greater_than_1(
$lineItemNameProvider->getItemName($orderItem)->willReturn('2x - My item name');

$this->getLineItem($orderItem)->shouldReturn([
'amount' => 1000,
'currency' => 'USD',
'name' => '2x - My item name',
'price_data' => [
'unit_amount' => 1000,
'currency' => 'USD',
'product_data' => [
'name' => '2x - My item name',
'images' => [],
],
],
'quantity' => 1,
'images' => [],
]);
}

Expand Down
26 changes: 26 additions & 0 deletions spec/Provider/ModeProviderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace spec\FluxSE\SyliusPayumStripePlugin\Provider;

use FluxSE\SyliusPayumStripePlugin\Provider\ModeProvider;
use FluxSE\SyliusPayumStripePlugin\Provider\ModeProviderInterface;
use PhpSpec\ObjectBehavior;
use Stripe\Checkout\Session;
use Sylius\Component\Core\Model\OrderInterface;

final class ModeProviderSpec extends ObjectBehavior
{
public function it_is_initializable(): void
{
$this->shouldHaveType(ModeProvider::class);
$this->shouldHaveType(ModeProviderInterface::class);
}

public function it_get_payment_method_types(
OrderInterface $order
): void {
$this->getMode($order)->shouldReturn(Session::MODE_PAYMENT);
}
}
Loading

0 comments on commit 8e23fa3

Please sign in to comment.