webgriffe/sylius-klarna-payments-plugin

Sylius电子商务框架的Klarna支付插件

安装: 596

依赖: 0

建议: 0

安全: 0

星标: 0

关注者: 6

分支: 0

开放问题: 0

类型:sylius-plugin


README

Sylius Klarna 插件

Sylius插件,用于Klarna支付支付方式。

安装

  1. 运行

    composer require webgriffe/sylius-klarna-payments-plugin
  2. 将以下代码添加到您的 config/bundles.php 文件中:

    通常,通过 composer require 命令自动将插件添加到 config/bundles.php 文件。如果没有,您需要手动添加。

  3. 创建一个新文件 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. 导入取消支付的所需路由。将以下内容添加到您的 config/routes.yaml 文件中:

    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"
    

    注意:文件 shop_routing 需要在 _locale 前缀之后,以便可以在正确的语言中显示消息。如果您还没有,还应包括 Payum bundle 中的取消路由!

  5. 运行

    php bin/console sylius:install:assets

    或者,您可以将其添加到您的 webpack.config.js 文件中

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

    然后覆盖模板 WebgriffeSyliusKlarnaPaymentsPlugin/Process/index.html.twig 以包含条目

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

用法

访问管理面板并转到 支付方式 部分。创建一个新的支付方式并选择 Klarna支付 作为网关。然后,使用所需参数配置支付方式。

贡献

有关Sylius插件开发的全面指南,请访问Sylius文档,在那里您可以找到插件开发指南,其中包含大量示例。

快速安装

传统方式

  1. 运行 composer create-project sylius/plugin-skeleton ProjectName

  2. 从插件骨架根目录,运行以下命令

    $ (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)

为了能够设置插件数据库,请记住在 tests/Application/.envtests/Application/.env.test 中配置您的数据库凭据。

Docker

  1. 执行 docker compose up -d

  2. 初始化插件 docker compose exec app make init

  3. 在浏览器中打开 open localhost

用法

运行插件测试

  • PHPUnit

    vendor/bin/phpunit
  • PHPSpec

    vendor/bin/phpspec run
  • Behat(非JS场景)

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

    1. 安装Symfony CLI命令.

    2. 启动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. 安装SSL证书(仅需要一次)并在 127.0.0.1:8080 上运行测试应用程序的web服务器
    symfony server:ca:install
    APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
    1. 运行Behat
    vendor/bin/behat --strict --tags="@javascript"
  • 静态分析

    • Psalm

      vendor/bin/psalm
    • PHPStan

      vendor/bin/phpstan analyse -c phpstan.neon -l max src/  
  • 编码标准

    vendor/bin/ecs check

使用您的插件打开Sylius

  • 使用 test 环境

    (cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load)
    (cd tests/Application && APP_ENV=test bin/console server:run -d public)
  • 使用 dev 环境

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