Skip to content

webgriffe/SyliusKlarnaPaymentsPlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sylius Klarna Plugin

Sylius plugin for Klarna payments payment method.

Installation

  1. Run:

    composer require webgriffe/sylius-klarna-payments-plugin
  2. Add Webgriffe\SyliusKlarnaPlugin\WebgriffeSyliusKlarnaPaymentsPlugin::class => ['all' => true] to your config/bundles.php.

    Normally, the plugin is automatically added to the config/bundles.php file by the composer require command. If it is not, you have to add it manually.

  3. Create a new file config/packages/webgriffe_sylius_klarna_payments_plugin.yaml:

    imports:
        - { resource: "@WebgriffeSyliusKlarnaPaymentsPlugin/config/config.php" }
     
    webgriffe_sylius_klarna_payments:
        product_images:
        type: 'main' # Type of the product image to send to Klarna. If none is specified or the type does not exists on current product then the first image will be used.
        filter: 'sylius_medium' # Liip filter to apply to the image. If none is specified then the original image will be used.
  4. Import the routes needed for cancelling the payments. Add the following to your config/routes.yaml file:

    webgriffe_sylius_klarna_payments_plugin:
        resource: "@WebgriffeSyliusKlarnaPaymentsPlugin/config/shop_routing.php"
        prefix: /{_locale}
        requirements:
            _locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$
    
    webgriffe_sylius_klarna_payments_plugin_ajax:
        resource: "@WebgriffeSyliusKlarnaPaymentsPlugin/config/shop_ajax_routing.php"
    
    sylius_shop_payum_cancel:
        resource: "@PayumBundle/Resources/config/routing/cancel.xml"
    

    NB: The file shop_routing needs to be after the prefix _locale, so that messages can be displayed in the right language. You should also include the cancel routes from the Payum bundle if you do not have it already!

  5. Run:

    php bin/console sylius:install:assets

    Or, you can add the entry to your webpack.config.js file:

    .addEntry(
        'webgriffe-sylius-klarna-payments-entry',
        './vendor/webgriffe/sylius-klarna-payments-plugin/public/poll_payment.js'
    )

    And then override the template WebgriffeSyliusKlarnaPaymentsPlugin/Process/index.html.twig to include the entry:

    {% block javascripts %}
        {{ parent() }}
    
        <script>
            window.afterUrl = "{{ afterUrl }}";
            window.paymentStatusUrl = "{{ paymentStatusUrl }}";
        </script>
        {{ encore_entry_script_tags('webgriffe-sylius-klarna-payments-entry', null, 'sylius.shop') }}
    {% endblock %}

Usage

Access to the admin panel and go to the Payment methods section. Create a new payment method and select Klarna payments as gateway. Then, configure the payment method with the required parameters.

Contributing

For a comprehensive guide on Sylius Plugins development please go to Sylius documentation, there you will find the Plugin Development Guide, that is full of examples.

Quickstart Installation

Traditional

  1. Run composer create-project sylius/plugin-skeleton ProjectName.

  2. From the plugin skeleton root directory, run the following commands:

    $ (cd tests/Application && yarn install)
    $ (cd tests/Application && yarn build)
    $ (cd tests/Application && APP_ENV=test bin/console assets:install public)
    
    $ (cd tests/Application && APP_ENV=test bin/console doctrine:database:create)
    $ (cd tests/Application && APP_ENV=test bin/console doctrine:schema:create)

To be able to set up a plugin's database, remember to configure you database credentials in tests/Application/.env and tests/Application/.env.test.

Docker

  1. Execute docker compose up -d

  2. Initialize plugin docker compose exec app make init

  3. See your browser open localhost

Usage

Running plugin tests

  • PHPUnit

    vendor/bin/phpunit
  • PHPSpec

    vendor/bin/phpspec run
  • Behat (non-JS scenarios)

    vendor/bin/behat --strict --tags="~@javascript"
  • Behat (JS scenarios)

    1. Install Symfony CLI command.

    2. Start Headless Chrome:

    google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
    1. Install SSL certificates (only once needed) and run test application's webserver on 127.0.0.1:8080:
    symfony server:ca:install
    APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
    1. Run Behat:
    vendor/bin/behat --strict --tags="@javascript"
  • Static Analysis

    • Psalm

      vendor/bin/psalm
    • PHPStan

      vendor/bin/phpstan analyse -c phpstan.neon -l max src/  
  • Coding Standard

    vendor/bin/ecs check

Opening Sylius with your plugin

  • Using test environment:

    (cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load)
    (cd tests/Application && APP_ENV=test bin/console server:run -d public)
  • Using dev environment:

    (cd tests/Application && APP_ENV=dev bin/console sylius:fixtures:load)
    (cd tests/Application && APP_ENV=dev bin/console server:run -d public)