From 67b39e03d826b5516ab27b8759df347a0bb86484 Mon Sep 17 00:00:00 2001 From: Wojdylak Date: Fri, 8 Nov 2024 14:42:57 +0100 Subject: [PATCH] [Maintenance] Add sylius/paypal-plugin --- composer.json | 1 + config/bundles.php | 1 + config/packages/_sylius.yaml | 1 + config/packages/http_discovery.yaml | 10 +++++ config/routes.yaml | 2 + config/routes/sylius_admin.yaml | 4 ++ config/routes/sylius_shop.yaml | 6 +++ symfony.lock | 15 +++++++ .../Gateways/paymentGateways.html.twig | 5 +++ .../Checkout/SelectPayment/_choice.html.twig | 18 +++++++++ .../Common/Order/_addresses.html.twig | 23 +++++++++++ .../Common/Order/_payments.html.twig | 29 ++++++++++++++ .../SyliusShopBundle/Order/thankYou.html.twig | 40 +++++++++++++++++++ 13 files changed, 155 insertions(+) create mode 100644 config/packages/http_discovery.yaml create mode 100644 templates/bundles/SyliusAdminBundle/PaymentMethod/Gateways/paymentGateways.html.twig create mode 100644 templates/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig create mode 100644 templates/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig create mode 100644 templates/bundles/SyliusShopBundle/Common/Order/_payments.html.twig create mode 100644 templates/bundles/SyliusShopBundle/Order/thankYou.html.twig diff --git a/composer.json b/composer.json index 5c2c226094..aad086d035 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ ], "require": { "php": "^8.1", + "sylius/paypal-plugin": "^1.7.x-dev", "sylius/sylius": "~1.14.0", "symfony/dotenv": "^5.4 || ^6.4", "symfony/flex": "^2.4", diff --git a/config/bundles.php b/config/bundles.php index a211a992e2..754403fa82 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -60,4 +60,5 @@ SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], League\FlysystemBundle\FlysystemBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Sylius\PayPalPlugin\SyliusPayPalPlugin::class => ['all' => true], ]; diff --git a/config/packages/_sylius.yaml b/config/packages/_sylius.yaml index 6d5fbf8988..74c4dc0f7d 100644 --- a/config/packages/_sylius.yaml +++ b/config/packages/_sylius.yaml @@ -5,6 +5,7 @@ imports: - { resource: "@SyliusApiBundle/Resources/config/app/config.yaml" } - { resource: "@SyliusShopBundle/Resources/config/app/config.yml" } + - { resource: "@SyliusPayPalPlugin/Resources/config/config.yaml" } - { resource: "../parameters.yaml" } diff --git a/config/packages/http_discovery.yaml b/config/packages/http_discovery.yaml new file mode 100644 index 0000000000..2a789e73c9 --- /dev/null +++ b/config/packages/http_discovery.yaml @@ -0,0 +1,10 @@ +services: + Psr\Http\Message\RequestFactoryInterface: '@http_discovery.psr17_factory' + Psr\Http\Message\ResponseFactoryInterface: '@http_discovery.psr17_factory' + Psr\Http\Message\ServerRequestFactoryInterface: '@http_discovery.psr17_factory' + Psr\Http\Message\StreamFactoryInterface: '@http_discovery.psr17_factory' + Psr\Http\Message\UploadedFileFactoryInterface: '@http_discovery.psr17_factory' + Psr\Http\Message\UriFactoryInterface: '@http_discovery.psr17_factory' + + http_discovery.psr17_factory: + class: Http\Discovery\Psr17Factory diff --git a/config/routes.yaml b/config/routes.yaml index e69de29bb2..b69bca4578 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -0,0 +1,2 @@ +sylius_paypal_webhook: + resource: "@SyliusPayPalPlugin/Resources/config/webhook_routing.yaml" diff --git a/config/routes/sylius_admin.yaml b/config/routes/sylius_admin.yaml index b9c12c2244..7d3f858119 100644 --- a/config/routes/sylius_admin.yaml +++ b/config/routes/sylius_admin.yaml @@ -1,3 +1,7 @@ sylius_admin: resource: "@SyliusAdminBundle/Resources/config/routing.yml" prefix: '/%sylius_admin.path_name%' + +sylius_paypal_admin: + resource: "@SyliusPayPalPlugin/Resources/config/admin_routing.yml" + prefix: '/%sylius_admin.path_name%' diff --git a/config/routes/sylius_shop.yaml b/config/routes/sylius_shop.yaml index 22e7a4a9a9..eefe9454e5 100644 --- a/config/routes/sylius_shop.yaml +++ b/config/routes/sylius_shop.yaml @@ -21,3 +21,9 @@ sylius_shop_request_password_reset_token_redirect: defaults: route: sylius_shop_request_password_reset_token permanent: false + +sylius_paypal: + resource: "@SyliusPayPalPlugin/Resources/config/shop_routing.yaml" + prefix: /{_locale} + requirements: + _locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$ diff --git a/symfony.lock b/symfony.lock index 947947f06c..6843d333fe 100644 --- a/symfony.lock +++ b/symfony.lock @@ -326,6 +326,18 @@ "phar-io/version": { "version": "1.0.1" }, + "php-http/discovery": { + "version": "1.20", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "1.18", + "ref": "f45b5dd173a27873ab19f5e3180b2f661c21de02" + }, + "files": [ + "config/packages/http_discovery.yaml" + ] + }, "php-http/httplug": { "version": "v1.1.0" }, @@ -518,6 +530,9 @@ "sylius/mailer-bundle": { "version": "v1.4.4" }, + "sylius/paypal-plugin": { + "version": "1.7.x-dev" + }, "sylius/registry": { "version": "v1.4.1" }, diff --git a/templates/bundles/SyliusAdminBundle/PaymentMethod/Gateways/paymentGateways.html.twig b/templates/bundles/SyliusAdminBundle/PaymentMethod/Gateways/paymentGateways.html.twig new file mode 100644 index 0000000000..ea0e1d4b95 --- /dev/null +++ b/templates/bundles/SyliusAdminBundle/PaymentMethod/Gateways/paymentGateways.html.twig @@ -0,0 +1,5 @@ +{% for name, gateway in gatewayFactories %} + + {{ gateway|trans }} + +{% endfor %} diff --git a/templates/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/templates/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig new file mode 100644 index 0000000000..6b23abe8a0 --- /dev/null +++ b/templates/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -0,0 +1,18 @@ +
+
+
+ {{ form_widget(form, sylius_test_form_attribute('payment-method-select')) }} +
+
+
+ {{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} + {% if method.description is not null %} +
+

{{ method.description }}

+
+ {% endif %} + {% if order.checkoutState != constant('Sylius\\Component\\Core\\OrderCheckoutStates::STATE_COMPLETED') and method.gatewayConfig.factoryName == 'sylius.pay_pal' %} + {{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController::renderPaymentPageButtonsAction', {'orderId': order.id})) }} + {% endif %} +
+
diff --git a/templates/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig b/templates/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig new file mode 100644 index 0000000000..6d7ee9f4d3 --- /dev/null +++ b/templates/bundles/SyliusShopBundle/Common/Order/_addresses.html.twig @@ -0,0 +1,23 @@ +
+
+
+
{{ 'sylius.ui.billing_address'|trans }}
+ {% include '@SyliusShop/Common/_address.html.twig' with {'address': order.billingAddress} %} +
+ {% if order.isShippingRequired() %} +
+
{{ 'sylius.ui.shipping_address'|trans }}
+ {% include '@SyliusShop/Common/_address.html.twig' with {'address': order.shippingAddress} %} +
+ {% endif %} +
+
+{% if sylius_is_billing_address_missing(order) %} +
+ +
+
{{ 'sylius.pay_pal.missing_billing_address_header'|trans }}
+

{{ 'sylius.pay_pal.missing_billing_address_content'|trans }}

+
+
+{% endif %} diff --git a/templates/bundles/SyliusShopBundle/Common/Order/_payments.html.twig b/templates/bundles/SyliusShopBundle/Common/Order/_payments.html.twig new file mode 100644 index 0000000000..1591a7dfda --- /dev/null +++ b/templates/bundles/SyliusShopBundle/Common/Order/_payments.html.twig @@ -0,0 +1,29 @@ +{% import "@SyliusShop/Common/Macro/money.html.twig" as money %} + +{% set state = order.paymentState %} + +{% if state != 'cart' %} + {% include "@SyliusShop/Common/Order/Label/PaymentState/orderPaymentState.html.twig" %} +{% endif %} + +{% for payment in order.payments %} + {% set state = payment.state %} + +
+ +
+
+ {{ payment.method }} +
+

{{ money.format(payment.amount, payment.currencyCode) }}

+ {% if payment.amount != payment.order.total and state == 'processing' %} + {{ 'sylius.pay_pal.different_amount'|trans }} + {% endif %} + {% if state != 'cart' %} +

+ {% include "@SyliusShop/Common/Order/Label/PaymentState/singlePaymentState.html.twig" with { 'state': state } %} +

+ {% endif %} +
+
+{% endfor %} diff --git a/templates/bundles/SyliusShopBundle/Order/thankYou.html.twig b/templates/bundles/SyliusShopBundle/Order/thankYou.html.twig new file mode 100644 index 0000000000..3c29c3aba6 --- /dev/null +++ b/templates/bundles/SyliusShopBundle/Order/thankYou.html.twig @@ -0,0 +1,40 @@ +{% extends '@SyliusShop/layout.html.twig' %} + +{% block content %} + +
+
+

+ {% set lastPayment = order.payments.last() %} + +
+ {{ 'sylius.ui.thank_you'|trans }} +
{{ 'sylius.ui.placed_an_order'|trans }}
+
+

+ + {{ sylius_template_event('sylius.shop.order.thank_you.after_message', {'order': order}) }} + + {% if lastPayment != false %} + {% if lastPayment.method.instructions is not null %} +
+ {{ lastPayment.method.instructions }} +
+ {% endif %} + + {% endif %} + + {% if order.customer.user is not null %} + {{ 'sylius.ui.view_order'|trans }} + {% else %} + {% if lastPayment.state != 'completed' %} + {{ 'sylius.ui.change_payment_method'|trans }} + {% endif %} + + + {{ 'sylius.ui.create_an_account'|trans }} + + {% endif %} +
+
+{% endblock %}