Skip to content

Commit

Permalink
Payment Restrictions Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej-kuhnel committed Jan 14, 2019
0 parents commit a113904
Show file tree
Hide file tree
Showing 82 changed files with 1,977 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = tab
indent_size = 4

[**.{yml,yaml,yml.dist}]
indent_style = space
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

/vendor/
/node_modules/
/composer.lock

/etc/build/*
!/etc/build/.gitkeep

/tests/Application/yarn.lock

docker-compose.override.yaml
docker-compose.override.dist.yaml
docker-compose.yaml
/bin-docker/
/deploy/
/docker/
/etc/
79 changes: 79 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
language: php

dist: trusty

sudo: false

php:
- 7.2

cache:
yarn: true
directories:
- ~/.composer/cache/files
- $SYLIUS_CACHE_DIR

env:
global:
- SYLIUS_CACHE_DIR=$HOME/.sylius-cache
- SYLIUS_BUILD_DIR=etc/build
matrix:
- SYMFONY_VERSION="3.4.*"
- SYMFONY_VERSION="4.1.*"

before_install:
- phpenv config-rm xdebug.ini
- echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- mkdir -p "${SYLIUS_CACHE_DIR}"

install:
- composer require "symfony/symfony:${SYMFONY_VERSION}" --no-interaction --no-update
- composer install --no-interaction --prefer-dist
- (cd tests/Application && yarn install)

before_script:
- (cd tests/Application && bin/console doctrine:database:create --env=test -vvv)
- (cd tests/Application && bin/console doctrine:schema:create --env=test -vvv)
- (cd tests/Application && bin/console assets:install web --env=test -vvv)
- (cd tests/Application && bin/console cache:warmup --env=test -vvv)
- (cd tests/Application && yarn build)

# Configure display
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1680x1050x16
- export DISPLAY=:99

# Download and configure ChromeDriver
- |
if [ ! -f $SYLIUS_CACHE_DIR/chromedriver ] || [ "$($SYLIUS_CACHE_DIR/chromedriver --version | grep -c 2.34)" = "0" ]; then
curl http://chromedriver.storage.googleapis.com/2.34/chromedriver_linux64.zip > chromedriver.zip
unzip chromedriver.zip
chmod +x chromedriver
mv chromedriver $SYLIUS_CACHE_DIR
fi
# Run ChromeDriver
- $SYLIUS_CACHE_DIR/chromedriver > /dev/null 2>&1 &

# Download and configure Selenium
- |
if [ ! -f $SYLIUS_CACHE_DIR/selenium.jar ] || [ "$(java -jar $SYLIUS_CACHE_DIR/selenium.jar --version | grep -c 3.4.0)" = "0" ]; then
curl http://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar > selenium.jar
mv selenium.jar $SYLIUS_CACHE_DIR
fi
# Run Selenium
- java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &

# Run webserver
- (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web --env=test --quiet > /dev/null 2>&1 &)

script:
- composer validate --strict
- bin/phpstan.phar analyse -c phpstan.neon -l max src/

- bin/phpunit
- bin/phpspec run
- bin/behat --strict -vvv --no-interaction || bin/behat --strict -vvv --no-interaction --rerun

after_failure:
- vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles "${SYLIUS_BUILD_DIR}/*.log"
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<p align="center">
<a href="https://www.mangoweb.cz/en/" target="_blank">
<img src="https://avatars0.githubusercontent.com/u/38423357?s=200&v=4"/>
</a>
</p>
<h1 align="center">Payment Restrictions Plugin</h1>

## Features

xxxx

## Installation

1. Run `$ composer require mangoweb-sylius/sylius-payment-restrictions-plugin`.
2. Register `\MangoSylius\PaymentRestrictionPlugin\MangoSyliusPaymentRestrictionPlugin` in your Kernel.
3. Your Entity `PaymentMethod` has to implement `\MangoSylius\PaymentRestrictionPlugin\Model\PaymentMethodRestrictionInterface`. You can use Trait `MangoSylius\PaymentRestrictionPlugin\Model\PaymentMethodRestrictionTrait`.
4. Add `{{ form_row(form.zone) }}` to `@SyliusAdmin/PaymentMethod/_form.html.twig`.

For guide to use your own entity see [Sylius docs - Customizing Models](https://docs.sylius.com/en/1.3/customization/model.html)

## Development

### Usage

- Create symlink from .env.dist to .env or create your own .env file
- Develop your plugin in `/src`
- See `bin/` for useful commands

### Testing

After your changes you must ensure that the tests are still passing.
* Easy Coding Standard
```bash
bin/ecs.sh
```
* PHPStan
```bash
bin/phpstan.sh
```
License
-------
This library is under the MIT license.

Credits
-------
Developed by [manGoweb](https://www.mangoweb.eu/).
24 changes: 24 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
imports:
- vendor/sylius/sylius/behat.yml.dist
- tests/Behat/Resources/suites.yml

default:
extensions:
FriendsOfBehat\ContextServiceExtension:
imports:
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml
- tests/Behat/Resources/services.xml

FriendsOfBehat\SymfonyExtension:
kernel:
class: \App\Kernel
path: tests/Application/src/Kernel.php
bootstrap: vendor/autoload.php

Lakion\Behat\MinkDebugExtension:
directory: etc/build
clean_start: false
screenshot: true

Behat\MinkExtension:
base_url: "http://nginx"
1 change: 1 addition & 0 deletions bin/behat
1 change: 1 addition & 0 deletions bin/console
12 changes: 12 additions & 0 deletions bin/ecs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# project root
cd "$(dirname "$DIR")"

set -x

rm -rf tests/Application/var/cache/
vendor/bin/ecs check src tests "$@"
15 changes: 15 additions & 0 deletions bin/phpstan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# project root
cd "$(dirname "$DIR")"

set -x
tests/Application/bin/console --env=dev cache:warmup
vendor/bin/phpstan analyse \
--level 7 \
--memory-limit 1G \
--configuration phpstan.neon \
src tests
1 change: 1 addition & 0 deletions bin/phpunit
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "mangoweb-sylius/sylius-payment-restrictions-plugin",
"type": "sylius-plugin",
"description": "Payment restriction plugin for Sylius",
"license": "MIT",
"require": {
"php": "^7.1",
"sylius/sylius": "^1.2.5",
"symfony/symfony": "^4.1"
},
"require-dev": {
"behat/behat": "^3.4",
"behat/mink": "^1.7@dev",
"behat/mink-browserkit-driver": "^1.3",
"behat/mink-extension": "^2.2",
"behat/mink-selenium2-driver": "^1.3",
"friends-of-behat/context-service-extension": "^1.2",
"friends-of-behat/cross-container-extension": "^1.1",
"friends-of-behat/service-container-extension": "^1.0",
"friends-of-behat/symfony-extension": "^1.2.1",
"friends-of-behat/variadic-extension": "^1.1",
"lakion/mink-debug-extension": "^1.2.3",
"phpstan/phpstan-doctrine": "^0.10",
"phpstan/phpstan-shim": "^0.10",
"phpstan/phpstan-symfony": "^0.10",
"phpstan/phpstan-webmozart-assert": "^0.10",
"phpunit/phpunit": "^6.5",
"sylius-labs/coding-standard": "^2.0",
"se/selenium-server-standalone": "^3.12"
},
"prefer-stable": true,
"autoload": {
"psr-4": {
"MangoSylius\\PaymentRestrictionPlugin\\": "src/",
"Tests\\MangoSylius\\PaymentRestrictionPlugin\\": "tests/"
}
},
"autoload-dev": {
"psr-4": {
"App\\": "tests/Application/src/"
}
}
}
Binary file added doc/list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions easy-coding-standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
imports:
- { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' }

parameters:
indentation: tab

Empty file added features/.gitkeep
Empty file.
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions node_modules
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
symfony:
container_xml_path: tests/Application/var/cache/dev/srcApp_KernelDevDebugContainer.xml

excludes_analyse:
# Too slow
- 'src/DependencyInjection/Configuration.php'

# Test dependencies
- '*/tests/Application/var/*'

- '*/tests/Behat/*'
18 changes: 18 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="AcmeSyliusExamplePlugin Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<php>
<server name="KERNEL_CLASS_PATH" value="/tests/Application/src/Kernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
</php>
</phpunit>
19 changes: 19 additions & 0 deletions src/DependencyInjection/MangoSyliusPaymentRestrictionExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace MangoSylius\PaymentRestrictionPlugin\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class MangoSyliusPaymentRestrictionExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
30 changes: 30 additions & 0 deletions src/Form/Extension/RestrictionPaymentMethodExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace MangoSylius\PaymentRestrictionPlugin\Form\Extension;

use Sylius\Bundle\AddressingBundle\Form\Type\ZoneChoiceType;
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

final class RestrictionPaymentMethodExtension extends AbstractTypeExtension
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('zone', ZoneChoiceType::class, [
'label' => 'sylius.form.address.zone',
'constraints' => [
new NotBlank(['groups' => ['sylius']]),
],
]);
}

public function getExtendedType(): string
{
return PaymentMethodType::class;
}
}
13 changes: 13 additions & 0 deletions src/MangoSyliusPaymentRestrictionPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace MangoSylius\PaymentRestrictionPlugin;

use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class MangoSyliusPaymentRestrictionPlugin extends Bundle
{
use SyliusPluginTrait;
}
Loading

0 comments on commit a113904

Please sign in to comment.