From e092f8be2facc487990509ea4d09e5e9d17dd6c8 Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Fri, 25 Aug 2023 14:18:15 +0200 Subject: [PATCH 01/43] add p10/12x --- src/Form/Type/AlmaGatewayConfigurationType.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Form/Type/AlmaGatewayConfigurationType.php b/src/Form/Type/AlmaGatewayConfigurationType.php index 4676fb5..47286c2 100644 --- a/src/Form/Type/AlmaGatewayConfigurationType.php +++ b/src/Form/Type/AlmaGatewayConfigurationType.php @@ -89,6 +89,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ['%installments_count%' => 3]) => 3, $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_choice_label', ['%installments_count%' => 4]) => 4, + $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_choice_label', + ['%installments_count%' => 10]) => 10, + $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_choice_label', + ['%installments_count%' => 12]) => 12, ], 'label' => $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_label'), ] From 3b9186f9e796acd4b55a5209290082bfe4d46bab Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Tue, 5 Sep 2023 18:42:55 +0200 Subject: [PATCH 02/43] WIP: add controller look like paypal to add data under button payment --- src/Controller/InstallmentPlanController.php | 79 +++++++++++++++++++ src/Form/Type/SelectPaymentType.php | 25 ++++++ src/Resources/config/services/controller.xml | 15 ++++ src/Resources/config/shop_routing.yaml | 17 ++++ .../Checkout/SelectPayment/_choice.html.twig | 20 +++++ 5 files changed, 156 insertions(+) create mode 100644 src/Controller/InstallmentPlanController.php create mode 100644 src/Form/Type/SelectPaymentType.php create mode 100644 src/Resources/config/services/controller.xml create mode 100644 src/Resources/config/shop_routing.yaml create mode 100644 src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig diff --git a/src/Controller/InstallmentPlanController.php b/src/Controller/InstallmentPlanController.php new file mode 100644 index 0000000..58af475 --- /dev/null +++ b/src/Controller/InstallmentPlanController.php @@ -0,0 +1,79 @@ +twig = $twig; + $this->router = $router; + $this->channelContext = $channelContext; + $this->localeContext = $localeContext; + $this->orderRepository = $orderRepository; + $this->availableCountriesProvider = $availableCountriesProvider; + $this->localeProcessor = $localeProcessor; + } + + public function renderPaymentPageInstallmentPlanAction(Request $request): Response + { + $orderId = $request->attributes->getInt('orderId'); + /** @var ChannelInterface $channel */ + $channel = $this->channelContext->getChannel(); + /** @var OrderInterface $order */ + $order = $this->orderRepository->find($orderId); + + try { + return new Response($this->twig->render('@SyliusPayPalPlugin/payFromPaymentPage.html.twig', [ + 'available_countries' => $this->availableCountriesProvider->provide(), + 'cancelPayPalPaymentUrl' => $this->router->generate('sylius_paypal_plugin_cancel_payment'), + 'clientId' => $this->payPalConfigurationProvider->getClientId($channel), + 'currency' => $order->getCurrencyCode(), + 'completePayPalOrderFromPaymentPageUrl' => $this->router->generate('sylius_paypal_plugin_complete_paypal_order_from_payment_page', ['id' => $orderId]), + 'createPayPalOrderFromPaymentPageUrl' => $this->router->generate('sylius_paypal_plugin_create_paypal_order_from_payment_page', ['id' => $orderId]), + 'errorPayPalPaymentUrl' => $this->router->generate('sylius_paypal_plugin_payment_error'), + 'locale' => $this->localeProcessor->process((string) $order->getLocaleCode()), + 'orderId' => $orderId, + 'partnerAttributionId' => $this->payPalConfigurationProvider->getPartnerAttributionId($channel), + ])); + } catch (\InvalidArgumentException $exception) { + return new Response(''); + } + } +} diff --git a/src/Form/Type/SelectPaymentType.php b/src/Form/Type/SelectPaymentType.php new file mode 100644 index 0000000..2f94ae8 --- /dev/null +++ b/src/Form/Type/SelectPaymentType.php @@ -0,0 +1,25 @@ +add('payments', ChangePaymentMethodType::class, [ + 'entry_type' => PaymentType::class, + 'label' => false, + ]); + } + + public function getBlockPrefix(): string + { + return 'sylius_checkout_select_payment'; + } +} diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml new file mode 100644 index 0000000..eca142e --- /dev/null +++ b/src/Resources/config/services/controller.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/Resources/config/shop_routing.yaml b/src/Resources/config/shop_routing.yaml new file mode 100644 index 0000000..3ad5b0d --- /dev/null +++ b/src/Resources/config/shop_routing.yaml @@ -0,0 +1,17 @@ +sylius_shop_checkout_select_payment: + path: /checkout/select-payment + methods: [GET, PUT] + defaults: + _controller: sylius.controller.order::updateAction + _sylius: + event: payment + flash: false + template: "@SyliusShop/Checkout/selectPayment.html.twig" + form: Alma\SyliusPaymentPlugin\Form\Type\SelectPaymentType + repository: + method: findCartForSelectingPayment + arguments: + - "expr:service('sylius.context.cart').getCart().getId()" + state_machine: + graph: sylius_order_checkout + transition: select_payment diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig new file mode 100644 index 0000000..4b23dd8 --- /dev/null +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -0,0 +1,20 @@ +
+
+
+ {{ form_widget(form, sylius_test_form_attribute('payment-method-select')) }} +
+
+
+ {{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} + {{ dump(method.description) }} + {% if method.description is not null %} +
+

{{ method.description }} toto

+
+ {% endif %} + {{ dump(method.gatewayConfig.factoryName) }} + {% if method.gatewayConfig.factoryName == 'sylius.pay_pal' %} + {{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController:renderPaymentPageButtonsAction', {'orderId': order.id})) }} + {% endif %} +
+
From 927315701608797dc4ecb79e1524379a9237db2b Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Mon, 11 Sep 2023 16:22:44 +0200 Subject: [PATCH 03/43] wip : p10/12x --- src/Controller/InstallmentPlanController.php | 19 ++----------------- src/Resources/config/config.yaml | 3 +++ src/Resources/config/services/controller.xml | 2 +- src/Resources/config/services/controller.yml | 4 ++++ src/Resources/config/shop_routing.yaml | 1 - .../Checkout/SelectPayment/_choice.html.twig | 3 ++- 6 files changed, 12 insertions(+), 20 deletions(-) create mode 100644 src/Resources/config/config.yaml create mode 100644 src/Resources/config/services/controller.yml diff --git a/src/Controller/InstallmentPlanController.php b/src/Controller/InstallmentPlanController.php index 58af475..7a92620 100644 --- a/src/Controller/InstallmentPlanController.php +++ b/src/Controller/InstallmentPlanController.php @@ -53,24 +53,9 @@ public function __construct( public function renderPaymentPageInstallmentPlanAction(Request $request): Response { - $orderId = $request->attributes->getInt('orderId'); - /** @var ChannelInterface $channel */ - $channel = $this->channelContext->getChannel(); - /** @var OrderInterface $order */ - $order = $this->orderRepository->find($orderId); - try { - return new Response($this->twig->render('@SyliusPayPalPlugin/payFromPaymentPage.html.twig', [ - 'available_countries' => $this->availableCountriesProvider->provide(), - 'cancelPayPalPaymentUrl' => $this->router->generate('sylius_paypal_plugin_cancel_payment'), - 'clientId' => $this->payPalConfigurationProvider->getClientId($channel), - 'currency' => $order->getCurrencyCode(), - 'completePayPalOrderFromPaymentPageUrl' => $this->router->generate('sylius_paypal_plugin_complete_paypal_order_from_payment_page', ['id' => $orderId]), - 'createPayPalOrderFromPaymentPageUrl' => $this->router->generate('sylius_paypal_plugin_create_paypal_order_from_payment_page', ['id' => $orderId]), - 'errorPayPalPaymentUrl' => $this->router->generate('sylius_paypal_plugin_payment_error'), - 'locale' => $this->localeProcessor->process((string) $order->getLocaleCode()), - 'orderId' => $orderId, - 'partnerAttributionId' => $this->payPalConfigurationProvider->getPartnerAttributionId($channel), + return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ + 'toto' => 'toto', ])); } catch (\InvalidArgumentException $exception) { return new Response(''); diff --git a/src/Resources/config/config.yaml b/src/Resources/config/config.yaml new file mode 100644 index 0000000..467e463 --- /dev/null +++ b/src/Resources/config/config.yaml @@ -0,0 +1,3 @@ +twig: + paths: + '%kernel.project_dir%/vendor/alma/sylius-payment-plugin/src/Resources/views/bundles/SyliusShopBundle': SyliusShop \ No newline at end of file diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml index eca142e..0477926 100644 --- a/src/Resources/config/services/controller.xml +++ b/src/Resources/config/services/controller.xml @@ -3,7 +3,7 @@ - + diff --git a/src/Resources/config/services/controller.yml b/src/Resources/config/services/controller.yml new file mode 100644 index 0000000..e7768ac --- /dev/null +++ b/src/Resources/config/services/controller.yml @@ -0,0 +1,4 @@ +services: + Alma\SyliusPaymentPlugin\Controller\installmentPlanController: + arguments: + $twig: '@alma_sylius_payment_plugin.twig' \ No newline at end of file diff --git a/src/Resources/config/shop_routing.yaml b/src/Resources/config/shop_routing.yaml index 3ad5b0d..f448304 100644 --- a/src/Resources/config/shop_routing.yaml +++ b/src/Resources/config/shop_routing.yaml @@ -7,7 +7,6 @@ sylius_shop_checkout_select_payment: event: payment flash: false template: "@SyliusShop/Checkout/selectPayment.html.twig" - form: Alma\SyliusPaymentPlugin\Form\Type\SelectPaymentType repository: method: findCartForSelectingPayment arguments: diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index 4b23dd8..a9f98fe 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -12,9 +12,10 @@

{{ method.description }} toto

{% endif %} + method.gatewayConfig.factoryName = {{ dump(method.gatewayConfig.factoryName) }} {% if method.gatewayConfig.factoryName == 'sylius.pay_pal' %} - {{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController:renderPaymentPageButtonsAction', {'orderId': order.id})) }} + {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentPlanController:renderPaymentPageInstallmentPlanAction', {'orderId': order.id})) }} {% endif %} From e2c1971b34ecbe3c0274a696aa0fde9bcc12fc42 Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Mon, 11 Sep 2023 16:23:23 +0200 Subject: [PATCH 04/43] wip : p10/12x --- src/Resources/views/installmentPlan.html.twig | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/Resources/views/installmentPlan.html.twig diff --git a/src/Resources/views/installmentPlan.html.twig b/src/Resources/views/installmentPlan.html.twig new file mode 100644 index 0000000..e6b276d --- /dev/null +++ b/src/Resources/views/installmentPlan.html.twig @@ -0,0 +1,3 @@ +
+ Installment Plan {{ toto }} +
\ No newline at end of file From 23fcb9117e4ecbc891cebec0fa984495bbf02d5e Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Tue, 12 Sep 2023 11:28:15 +0200 Subject: [PATCH 05/43] Add route to form chekout --- .gitignore | 2 +- composer.json | 2 +- src/Form/Type/ChangePaymentMethodType.php | 46 +++++++++++++++++++ src/Resources/config/services.yml | 2 + src/Resources/config/services/forms.yml | 8 ++++ src/Resources/config/shop_routing.yaml | 1 + .../Checkout/SelectPayment/_choice.html.twig | 7 +-- 7 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 src/Form/Type/ChangePaymentMethodType.php create mode 100644 src/Resources/config/services/forms.yml diff --git a/.gitignore b/.gitignore index f486a1f..821270a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /vendor/ /node_modules/ /composer.lock - +.idea/* /etc/build/* !/etc/build/.gitignore diff --git a/composer.json b/composer.json index e4144f5..5ce69d8 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "license": "MIT", "require": { "php": ">=7.1", - "alma/alma-php-client": "^1.11.1", + "alma/alma-php-client": ">=1.11.1", "sylius/sylius": ">=1.6.9", "ext-json": "*" }, diff --git a/src/Form/Type/ChangePaymentMethodType.php b/src/Form/Type/ChangePaymentMethodType.php new file mode 100644 index 0000000..64d3455 --- /dev/null +++ b/src/Form/Type/ChangePaymentMethodType.php @@ -0,0 +1,46 @@ +addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event): void { + /** @var PaymentInterface[] $payments */ + $payments = $event->getData(); + $form = $event->getForm(); + + foreach ($payments as $key => $payment) { + if (!in_array( + $payment->getState(), + [PaymentInterface::STATE_NEW, PaymentInterface::STATE_CART, PaymentInterface::STATE_PROCESSING] + )) { + $form->remove((string) $key); + } + } + }) + ; + } + + public function getParent(): string + { + return CollectionType::class; + } + + public function getBlockPrefix(): string + { + return 'sylius_change_payment_method'; + } +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 4f6caa7..9f8c35c 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -5,3 +5,5 @@ imports: - services/extensions.yml - services/resolvers.yml - services/data_builders.yml + - services/forms.yml + diff --git a/src/Resources/config/services/forms.yml b/src/Resources/config/services/forms.yml new file mode 100644 index 0000000..9227689 --- /dev/null +++ b/src/Resources/config/services/forms.yml @@ -0,0 +1,8 @@ +services: + sylius.form.type.checkout_select_payment: + class: Alma\SyliusPaymentPlugin\Form\Type\SelectPaymentType + arguments: + $dataClass: '%sylius.model.order.class%' + $validationGroups: '%sylius.form.type.cart.validation_groups%' + tags: + - { name: 'form.type' } \ No newline at end of file diff --git a/src/Resources/config/shop_routing.yaml b/src/Resources/config/shop_routing.yaml index f448304..3ad5b0d 100644 --- a/src/Resources/config/shop_routing.yaml +++ b/src/Resources/config/shop_routing.yaml @@ -7,6 +7,7 @@ sylius_shop_checkout_select_payment: event: payment flash: false template: "@SyliusShop/Checkout/selectPayment.html.twig" + form: Alma\SyliusPaymentPlugin\Form\Type\SelectPaymentType repository: method: findCartForSelectingPayment arguments: diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index a9f98fe..5301501 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -6,16 +6,11 @@
{{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} - {{ dump(method.description) }} {% if method.description is not null %}

{{ method.description }} toto

{% endif %} - method.gatewayConfig.factoryName = - {{ dump(method.gatewayConfig.factoryName) }} - {% if method.gatewayConfig.factoryName == 'sylius.pay_pal' %} - {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentPlanController:renderPaymentPageInstallmentPlanAction', {'orderId': order.id})) }} - {% endif %} + dfsfsdfdsdsffds
From 61ded6c018faada6e4b25c87ff2a647af98c9c71 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Tue, 12 Sep 2023 11:46:28 +0200 Subject: [PATCH 06/43] suite --- src/Controller/InstallmentPlanController.php | 51 +++++++++++++------ src/Resources/config/services.yml | 1 + src/Resources/config/services/controller.yml | 4 -- src/Resources/config/services/controllers.yml | 5 ++ .../Checkout/SelectPayment/_choice.html.twig | 6 ++- 5 files changed, 47 insertions(+), 20 deletions(-) delete mode 100644 src/Resources/config/services/controller.yml create mode 100644 src/Resources/config/services/controllers.yml diff --git a/src/Controller/InstallmentPlanController.php b/src/Controller/InstallmentPlanController.php index 7a92620..fc7c499 100644 --- a/src/Controller/InstallmentPlanController.php +++ b/src/Controller/InstallmentPlanController.php @@ -9,9 +9,9 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\Component\Locale\Context\LocaleContextInterface; -use Sylius\PayPalPlugin\Processor\LocaleProcessorInterface; -use Sylius\PayPalPlugin\Provider\AvailableCountriesProviderInterface; -use Sylius\PayPalPlugin\Provider\PayPalConfigurationProviderInterface; +//use Sylius\PayPalPlugin\Processor\LocaleProcessorInterface; +//use Sylius\PayPalPlugin\Provider\AvailableCountriesProviderInterface; +//use Sylius\PayPalPlugin\Provider\PayPalConfigurationProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -19,36 +19,57 @@ final class InstallmentPlanController { - private Environment $twig; + /** + * @var Environment + */ + private $twig; - private UrlGeneratorInterface $router; + /** + * @var UrlGeneratorInterface + */ + private $router; - private ChannelContextInterface $channelContext; + /** + * @var ChannelContextInterface + */ + private $channelContext; - private LocaleContextInterface $localeContext; + /** + * @var LocaleContextInterface + */ + private $localeContext; - private OrderRepositoryInterface $orderRepository; + /** + * @var OrderRepositoryInterface + */ + private $orderRepository; - private AvailableCountriesProviderInterface $availableCountriesProvider; + /** + * @var AvailableCountriesProviderInterface + */ + private $availableCountriesProvider; - private LocaleProcessorInterface $localeProcessor; + /** + * @var LocaleProcessorInterface + */ + private $localeProcessor; public function __construct( Environment $twig, UrlGeneratorInterface $router, ChannelContextInterface $channelContext, LocaleContextInterface $localeContext, - OrderRepositoryInterface $orderRepository, - AvailableCountriesProviderInterface $availableCountriesProvider, - LocaleProcessorInterface $localeProcessor + OrderRepositoryInterface $orderRepository + // , AvailableCountriesProviderInterface $availableCountriesProvider, + // LocaleProcessorInterface $localeProcessor ) { $this->twig = $twig; $this->router = $router; $this->channelContext = $channelContext; $this->localeContext = $localeContext; $this->orderRepository = $orderRepository; - $this->availableCountriesProvider = $availableCountriesProvider; - $this->localeProcessor = $localeProcessor; + // $this->availableCountriesProvider = $availableCountriesProvider; + // $this->localeProcessor = $localeProcessor; } public function renderPaymentPageInstallmentPlanAction(Request $request): Response diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 9f8c35c..6f932d3 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -6,4 +6,5 @@ imports: - services/resolvers.yml - services/data_builders.yml - services/forms.yml + - services/controllers.yml diff --git a/src/Resources/config/services/controller.yml b/src/Resources/config/services/controller.yml deleted file mode 100644 index e7768ac..0000000 --- a/src/Resources/config/services/controller.yml +++ /dev/null @@ -1,4 +0,0 @@ -services: - Alma\SyliusPaymentPlugin\Controller\installmentPlanController: - arguments: - $twig: '@alma_sylius_payment_plugin.twig' \ No newline at end of file diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml new file mode 100644 index 0000000..6718e06 --- /dev/null +++ b/src/Resources/config/services/controllers.yml @@ -0,0 +1,5 @@ +services: + alma.syliuspaymentplugin.controller.installmentplancontroller: + class: Alma\SyliusPaymentPlugin\Controller\InstallmentPlanController + arguments: + $twig: '@alma_sylius_payment_plugin.twig' \ No newline at end of file diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index 5301501..bd04924 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -8,9 +8,13 @@ {{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} {% if method.description is not null %}
-

{{ method.description }} toto

+

{{ method.description }}

{% endif %} + {% if method.gatewayConfig.factoryName == 'alma_payments' %} + [ {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentPlanController:renderPaymentPageInstallmentPlanAction', {'orderId': order.id})) }} + {% endif %} dfsfsdfdsdsffds + From 777aa4c169e695ead4ce4470fcb4e1aca26c470b Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Tue, 12 Sep 2023 15:57:13 +0200 Subject: [PATCH 07/43] suite --- src/Controller/InstallmentPlanController.php | 85 ------------------- src/Controller/InstallmentsController.php | 25 ++++++ src/Resources/config/services.yml | 5 +- src/Resources/config/services/controller.xml | 15 ---- src/Resources/config/services/controllers.yml | 12 ++- src/Resources/config/shop_routing.yaml | 6 ++ .../Checkout/SelectPayment/_choice.html.twig | 5 +- 7 files changed, 44 insertions(+), 109 deletions(-) delete mode 100644 src/Controller/InstallmentPlanController.php create mode 100644 src/Controller/InstallmentsController.php delete mode 100644 src/Resources/config/services/controller.xml diff --git a/src/Controller/InstallmentPlanController.php b/src/Controller/InstallmentPlanController.php deleted file mode 100644 index fc7c499..0000000 --- a/src/Controller/InstallmentPlanController.php +++ /dev/null @@ -1,85 +0,0 @@ -twig = $twig; - $this->router = $router; - $this->channelContext = $channelContext; - $this->localeContext = $localeContext; - $this->orderRepository = $orderRepository; - // $this->availableCountriesProvider = $availableCountriesProvider; - // $this->localeProcessor = $localeProcessor; - } - - public function renderPaymentPageInstallmentPlanAction(Request $request): Response - { - try { - return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ - 'toto' => 'toto', - ])); - } catch (\InvalidArgumentException $exception) { - return new Response(''); - } - } -} diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php new file mode 100644 index 0000000..ab8e8a9 --- /dev/null +++ b/src/Controller/InstallmentsController.php @@ -0,0 +1,25 @@ +render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ + 'toto' => 'VICTOIREEEE', + ]); + } catch (\InvalidArgumentException $exception) { + return new Response(''); + } + } +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 6f932d3..ad6f6f0 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,10 +1,9 @@ imports: - services/api.yml + - services/controllers.yml - services/gateway.yml - services/actions.yml - services/extensions.yml - services/resolvers.yml - services/data_builders.yml - - services/forms.yml - - services/controllers.yml - + - services/forms.yml \ No newline at end of file diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml deleted file mode 100644 index 0477926..0000000 --- a/src/Resources/config/services/controller.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml index 6718e06..ddbe24f 100644 --- a/src/Resources/config/services/controllers.yml +++ b/src/Resources/config/services/controllers.yml @@ -1,5 +1,9 @@ services: - alma.syliuspaymentplugin.controller.installmentplancontroller: - class: Alma\SyliusPaymentPlugin\Controller\InstallmentPlanController - arguments: - $twig: '@alma_sylius_payment_plugin.twig' \ No newline at end of file + _defaults: + public: true + autowire: true + + alma_sylius_payment_plugin.controller.installments: + class: Alma\SyliusPaymentPlugin\Controller\InstallmentsController + public: true + tags: [ 'controller.service_arguments' ] diff --git a/src/Resources/config/shop_routing.yaml b/src/Resources/config/shop_routing.yaml index 3ad5b0d..89c823a 100644 --- a/src/Resources/config/shop_routing.yaml +++ b/src/Resources/config/shop_routing.yaml @@ -15,3 +15,9 @@ sylius_shop_checkout_select_payment: state_machine: graph: sylius_order_checkout transition: select_payment + +alma_sylius_payment_plugin_render_plans: + path: /alma-render-plans + methods: [GET] + defaults: + _controller: alma_sylius_payment_plugin.controller.installments::renderInstallmentPlanAction diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index bd04924..653d131 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -12,9 +12,10 @@ {% endif %} {% if method.gatewayConfig.factoryName == 'alma_payments' %} - [ {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentPlanController:renderPaymentPageInstallmentPlanAction', {'orderId': order.id})) }} + {{ render(url('alma_sylius_payment_plugin_render_plans')) }} + + {% endif %} - dfsfsdfdsdsffds From 460c2b363cd7e543931bce588f1f70b3eaaf4cb2 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Tue, 12 Sep 2023 16:20:01 +0200 Subject: [PATCH 08/43] suite --- .../SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index 653d131..51520b4 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -13,8 +13,6 @@ {% endif %} {% if method.gatewayConfig.factoryName == 'alma_payments' %} {{ render(url('alma_sylius_payment_plugin_render_plans')) }} - - {% endif %} From 10104f5b980e3507be27e056c456d4955d305e30 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Tue, 12 Sep 2023 17:31:19 +0200 Subject: [PATCH 09/43] VICTOIRE --- src/Controller/InstallmentsController.php | 20 +++++++++++++------ src/Resources/config/services/controllers.yml | 4 +++- src/Resources/config/shop_routing.yaml | 2 +- .../Checkout/SelectPayment/_choice.html.twig | 5 ++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index ab8e8a9..f29131b 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -4,20 +4,28 @@ namespace Alma\SyliusPaymentPlugin\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; -class InstallmentsController extends AbstractController +final class InstallmentsController { + /** + * @var Environment + */ + private $twig; - public function renderInstallmentPlanAction(): Response + public function __construct( + Environment $twig + ) { + $this->twig = $twig; + } + public function renderInstallmentPlanAction(Request $request): Response { try { - return $this->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ - 'toto' => 'VICTOIREEEE', - ]); + return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ + 'toto' => 'VICTOIRE', + ])); } catch (\InvalidArgumentException $exception) { return new Response(''); } diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml index ddbe24f..10715f9 100644 --- a/src/Resources/config/services/controllers.yml +++ b/src/Resources/config/services/controllers.yml @@ -3,7 +3,9 @@ services: public: true autowire: true - alma_sylius_payment_plugin.controller.installments: + Alma\SyliusPaymentPlugin\Controller\InstallmentsController: class: Alma\SyliusPaymentPlugin\Controller\InstallmentsController public: true + arguments: + $twig: '@twig' tags: [ 'controller.service_arguments' ] diff --git a/src/Resources/config/shop_routing.yaml b/src/Resources/config/shop_routing.yaml index 89c823a..2864e43 100644 --- a/src/Resources/config/shop_routing.yaml +++ b/src/Resources/config/shop_routing.yaml @@ -17,7 +17,7 @@ sylius_shop_checkout_select_payment: transition: select_payment alma_sylius_payment_plugin_render_plans: - path: /alma-render-plans + path: /alma-render-plans/{orderId} methods: [GET] defaults: _controller: alma_sylius_payment_plugin.controller.installments::renderInstallmentPlanAction diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index 51520b4..5dc594b 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -12,7 +12,10 @@ {% endif %} {% if method.gatewayConfig.factoryName == 'alma_payments' %} - {{ render(url('alma_sylius_payment_plugin_render_plans')) }} + {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentsController::renderInstallmentPlanAction', {'orderId': order.id})) }} + {% endif %} + {% if method.gatewayConfig.factoryName == 'sylius.pay_pal' %} + {{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController::renderPaymentPageButtonsAction', {'orderId': order.id})) }} {% endif %} From b23e0d27e51d2576667b313bd847b372e6dc1023 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Tue, 12 Sep 2023 17:53:58 +0200 Subject: [PATCH 10/43] suite --- src/Controller/InstallmentsController.php | 19 +++++++++++++++++-- src/Resources/config/services/controllers.yml | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index f29131b..3dbcc72 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -4,6 +4,9 @@ namespace Alma\SyliusPaymentPlugin\Controller; +use Payum\Core\Request\Capture; +use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; @@ -15,16 +18,28 @@ final class InstallmentsController */ private $twig; + /** + * @var OrderRepositoryInterface + */ + private $orderRepository; + public function __construct( - Environment $twig + Environment $twig, + OrderRepositoryInterface $orderRepository, ) { $this->twig = $twig; + $this->orderRepository = $orderRepository; } public function renderInstallmentPlanAction(Request $request): Response { try { + $orderId = $request->attributes->getInt('orderId'); + /** @var OrderInterface $order */ + $order = $this->orderRepository->find($orderId); + var_dump($request->attributes);die; + return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ - 'toto' => 'VICTOIRE', + 'toto' => $order->getTotal(), ])); } catch (\InvalidArgumentException $exception) { return new Response(''); diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml index 10715f9..b1b1c4a 100644 --- a/src/Resources/config/services/controllers.yml +++ b/src/Resources/config/services/controllers.yml @@ -8,4 +8,5 @@ services: public: true arguments: $twig: '@twig' + $orderRepository: '@sylius.repository.order' tags: [ 'controller.service_arguments' ] From e0cb785a37441ca6648c47dca936e5d2683b9ba0 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Wed, 13 Sep 2023 10:02:15 +0200 Subject: [PATCH 11/43] Add template payments --- src/Controller/InstallmentsController.php | 2 +- .../Checkout/SelectPayment/_choice.html.twig | 3 --- .../SelectPayment/_choiceAlma.html.twig | 17 +++++++++++++++++ .../Checkout/SelectPayment/_payment.html.twig | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig create mode 100644 src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index 3dbcc72..86e968b 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -36,7 +36,7 @@ public function renderInstallmentPlanAction(Request $request): Response $orderId = $request->attributes->getInt('orderId'); /** @var OrderInterface $order */ $order = $this->orderRepository->find($orderId); - var_dump($request->attributes);die; + return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ 'toto' => $order->getTotal(), diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig index 5dc594b..1e2ced6 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig @@ -11,9 +11,6 @@

{{ method.description }}

{% endif %} - {% if method.gatewayConfig.factoryName == 'alma_payments' %} - {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentsController::renderInstallmentPlanAction', {'orderId': order.id})) }} - {% endif %} {% if method.gatewayConfig.factoryName == 'sylius.pay_pal' %} {{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController::renderPaymentPageButtonsAction', {'orderId': order.id})) }} {% endif %} diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig new file mode 100644 index 0000000..a2166ca --- /dev/null +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig @@ -0,0 +1,17 @@ +
+
+
+ {{ 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 %} + {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentsController::renderInstallmentPlanAction', {'orderId': order.id})) }} +
+
+ diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig new file mode 100644 index 0000000..5275bcb --- /dev/null +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig @@ -0,0 +1,15 @@ +
+
{{ 'sylius.ui.payment'|trans }} #{{ loop.index }}
+
+ {{ form_errors(form.method) }} + {% for key, choice_form in form.method %} + {% if form.method.vars.choices[key].data.gatewayConfig.factoryName == 'alma_payments' %} + {% include '@SyliusShop/Checkout/SelectPayment/_choiceAlma.html.twig' with {'form': choice_form, 'method': form.method.vars.choices[key].data} %} + {% else %} + {% include '@SyliusShop/Checkout/SelectPayment/_choice.html.twig' with {'form': choice_form, 'method': form.method.vars.choices[key].data} %} + {% endif %} + {% else %} + {% include '@SyliusShop/Checkout/SelectPayment/_unavailable.html.twig' %} + {% endfor %} +
+
From 7e7471273d416074ce6a8b41a42745541ef437bb Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Wed, 13 Sep 2023 11:58:33 +0200 Subject: [PATCH 12/43] suite --- src/Bridge/AlmaBridge.php | 17 +++++ src/Controller/InstallmentsController.php | 63 ++++++++++++++++++- src/Resources/config/services/controllers.yml | 4 ++ .../SelectPayment/_choiceAlma.html.twig | 2 +- src/Resources/views/installmentPlan.html.twig | 2 +- 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/Bridge/AlmaBridge.php b/src/Bridge/AlmaBridge.php index 9492920..10ed236 100644 --- a/src/Bridge/AlmaBridge.php +++ b/src/Bridge/AlmaBridge.php @@ -141,6 +141,23 @@ function getEligibilities(PaymentInterface $payment, array $installmentsCounts): return []; } + /** + * Retrieve the eligibilities from the data array sent + * + * @param array $data + * @return \Alma\API\Endpoints\Results\Eligibility|\Alma\API\Endpoints\Results\Eligibility[]|array + */ + public function retrieveEligibilities(array $data) + { + $alma = $this->getDefaultClient(); + try { + return $alma->payments->eligibility($data, true); + } catch (RequestError $e) { + $this->logger->error("[Alma] Eligibility call failed with error: " . $e->getMessage()); + } + + return []; + } /** * @inheritDoc */ diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index 86e968b..08d33ac 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -4,9 +4,13 @@ namespace Alma\SyliusPaymentPlugin\Controller; -use Payum\Core\Request\Capture; +use Alma\SyliusPaymentPlugin\Bridge\AlmaBridgeInterface; +use Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentMethodRepository; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; +use Sylius\Component\Locale\Context\LocaleContextInterface; +use Sylius\PayPalPlugin\Processor\LocaleProcessorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; @@ -23,23 +27,78 @@ final class InstallmentsController */ private $orderRepository; + /** + * @var PaymentMethodRepository + */ + private $paymentMethodRepository; + + /** + * @var AlmaBridgeInterface + */ + private $almaBridge; + + /** + * @var LocaleContextInterface + */ + private $localeContext; + + /** + * @var LocaleProcessorInterface + */ + private $localeProcessor; + + public function __construct( Environment $twig, OrderRepositoryInterface $orderRepository, + PaymentMethodRepository $paymentMethodRepository, + AlmaBridgeInterface $almaBridge, + LocaleContextInterface $localeContext, + LocaleProcessorInterface $localeProcessor ) { $this->twig = $twig; $this->orderRepository = $orderRepository; + $this->paymentMethodRepository = $paymentMethodRepository; + $this->almaBridge = $almaBridge; + $this->localeContext = $localeContext; + $this->localeProcessor = $localeProcessor; } + public function renderInstallmentPlanAction(Request $request): Response { try { $orderId = $request->attributes->getInt('orderId'); + $methodId = $request->attributes->getInt('methodPaymentId'); + /** @var OrderInterface $order */ $order = $this->orderRepository->find($orderId); + /** @var PaymentMethodInterface $paymentMethod */ + $paymentMethod = $this->paymentMethodRepository->find($methodId); + + $installmentCounts = $paymentMethod->getGatewayConfig()->getConfig()["installments_count"]; +var_dump( $this->localeProcessor->process($this->localeContext->getLocaleCode()));die; + $data = [ + "purchase_amount" => $order->getTotal(), + "queries" => [ + [ + "installments_count" => $installmentCounts, + "deferred_days" => "0", + "deferred_months" => "0" + ] + ], + "billing_address" => [ + "country" => $order->getBillingAddress()->getCountryCode(), + ], + "shipping_address" => [ + "country" => $order->getShippingAddress()->getCountryCode() + ], + "locale" => $this->localeContext->getLocaleCode(), + ]; + $eligibilities = $this->almaBridge->retrieveEligibilities($data); return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ - 'toto' => $order->getTotal(), + 'eligibilities' => $eligibilities ])); } catch (\InvalidArgumentException $exception) { return new Response(''); diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml index b1b1c4a..ed81add 100644 --- a/src/Resources/config/services/controllers.yml +++ b/src/Resources/config/services/controllers.yml @@ -9,4 +9,8 @@ services: arguments: $twig: '@twig' $orderRepository: '@sylius.repository.order' + $paymentMethodRepository: '@sylius.repository.payment_method' + $almaBridge: '@alma_sylius_payment_plugin.bridge' + $localeContext: '@sylius.context.locale' + $localeProcessor: '@Sylius\PayPalPlugin\Processor\LocaleProcessorInterface' tags: [ 'controller.service_arguments' ] diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig index a2166ca..9b9bee8 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig @@ -11,7 +11,7 @@

{{ method.description }}

{% endif %} - {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentsController::renderInstallmentPlanAction', {'orderId': order.id})) }} + {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentsController::renderInstallmentPlanAction', {'orderId': order.id, 'methodPaymentId': method.id})) }} diff --git a/src/Resources/views/installmentPlan.html.twig b/src/Resources/views/installmentPlan.html.twig index e6b276d..d69da80 100644 --- a/src/Resources/views/installmentPlan.html.twig +++ b/src/Resources/views/installmentPlan.html.twig @@ -1,3 +1,3 @@
- Installment Plan {{ toto }} + Installment Plan {{ dump(eligibilities) }}
\ No newline at end of file From 099db4c8c21cb1f4f89baa648d98c9bb9daeef7f Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Thu, 14 Sep 2023 09:32:44 +0200 Subject: [PATCH 13/43] suite --- src/Controller/InstallmentsController.php | 64 +++++++------------ src/Helper/EligibilityHelper.php | 56 ++++++++++++++++ src/Resources/config/services.yml | 1 + src/Resources/config/services/controllers.yml | 4 +- src/Resources/config/services/helpers.yml | 5 ++ 5 files changed, 87 insertions(+), 43 deletions(-) create mode 100644 src/Helper/EligibilityHelper.php create mode 100644 src/Resources/config/services/helpers.yml diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index 08d33ac..925be27 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -5,12 +5,11 @@ namespace Alma\SyliusPaymentPlugin\Controller; use Alma\SyliusPaymentPlugin\Bridge\AlmaBridgeInterface; +use Alma\SyliusPaymentPlugin\Helper\EligibilityHelper; use Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentMethodRepository; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; -use Sylius\Component\Locale\Context\LocaleContextInterface; -use Sylius\PayPalPlugin\Processor\LocaleProcessorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; @@ -33,37 +32,35 @@ final class InstallmentsController private $paymentMethodRepository; /** - * @var AlmaBridgeInterface + * @var EligibilityHelper */ - private $almaBridge; + private $eligibilityHelper; /** - * @var LocaleContextInterface + * @param Environment $twig + * @param OrderRepositoryInterface $orderRepository + * @param PaymentMethodRepository $paymentMethodRepository + * @param EligibilityHelper $eligibilityHelper */ - private $localeContext; - - /** - * @var LocaleProcessorInterface - */ - private $localeProcessor; - - public function __construct( Environment $twig, OrderRepositoryInterface $orderRepository, PaymentMethodRepository $paymentMethodRepository, - AlmaBridgeInterface $almaBridge, - LocaleContextInterface $localeContext, - LocaleProcessorInterface $localeProcessor + EligibilityHelper $eligibilityHelper ) { $this->twig = $twig; $this->orderRepository = $orderRepository; $this->paymentMethodRepository = $paymentMethodRepository; - $this->almaBridge = $almaBridge; - $this->localeContext = $localeContext; - $this->localeProcessor = $localeProcessor; + $this->eligibilityHelper = $eligibilityHelper; } + /** + * @param Request $request + * @return Response + * @throws \Twig\Error\LoaderError + * @throws \Twig\Error\RuntimeError + * @throws \Twig\Error\SyntaxError + */ public function renderInstallmentPlanAction(Request $request): Response { try { @@ -72,30 +69,17 @@ public function renderInstallmentPlanAction(Request $request): Response /** @var OrderInterface $order */ $order = $this->orderRepository->find($orderId); + /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $this->paymentMethodRepository->find($methodId); - $installmentCounts = $paymentMethod->getGatewayConfig()->getConfig()["installments_count"]; -var_dump( $this->localeProcessor->process($this->localeContext->getLocaleCode()));die; - $data = [ - "purchase_amount" => $order->getTotal(), - "queries" => [ - [ - "installments_count" => $installmentCounts, - "deferred_days" => "0", - "deferred_months" => "0" - ] - ], - "billing_address" => [ - "country" => $order->getBillingAddress()->getCountryCode(), - ], - "shipping_address" => [ - "country" => $order->getShippingAddress()->getCountryCode() - ], - "locale" => $this->localeContext->getLocaleCode(), - ]; - - $eligibilities = $this->almaBridge->retrieveEligibilities($data); + $eligibilities = $this->eligibilityHelper->getEligibilities( + $order->getTotal(), + $paymentMethod->getGatewayConfig()->getConfig()["installments_count"], + $order->getBillingAddress()->getCountryCode(), + $order->getShippingAddress()->getCountryCode(), + substr($request->getLocale(), 0, 2) + ); return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ 'eligibilities' => $eligibilities diff --git a/src/Helper/EligibilityHelper.php b/src/Helper/EligibilityHelper.php new file mode 100644 index 0000000..69d3d4c --- /dev/null +++ b/src/Helper/EligibilityHelper.php @@ -0,0 +1,56 @@ +almaBridge = $almaBridge; + } + + /** + * @param int $amount + * @param int $installmentCounts + * @param string $billingCountryCode + * @param string $shippingCountryCode + * @param string $locale + * @return \Alma\API\Endpoints\Results\Eligibility|\Alma\API\Endpoints\Results\Eligibility[]|array + */ + public function getEligibilities(int $amount, int $installmentCounts, string $billingCountryCode, string $shippingCountryCode, string $locale) + { + $data = [ + "purchase_amount" => $amount, + "queries" => [ + [ + "installments_count" => $installmentCounts, + "deferred_days" => "0", + "deferred_months" => "0" + ] + ], + "billing_address" => [ + "country" => $billingCountryCode, + ], + "shipping_address" => [ + "country" => $shippingCountryCode + ], + "locale" => $locale, + ]; + + return $this->almaBridge->retrieveEligibilities($data); + } +} \ No newline at end of file diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index ad6f6f0..6caf169 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,5 +1,6 @@ imports: - services/api.yml + - services/helpers.yml - services/controllers.yml - services/gateway.yml - services/actions.yml diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml index ed81add..25dc5f3 100644 --- a/src/Resources/config/services/controllers.yml +++ b/src/Resources/config/services/controllers.yml @@ -10,7 +10,5 @@ services: $twig: '@twig' $orderRepository: '@sylius.repository.order' $paymentMethodRepository: '@sylius.repository.payment_method' - $almaBridge: '@alma_sylius_payment_plugin.bridge' - $localeContext: '@sylius.context.locale' - $localeProcessor: '@Sylius\PayPalPlugin\Processor\LocaleProcessorInterface' + $eligibilityHelper: '@alma.sylius_payment_plugin.helper.eligibility' tags: [ 'controller.service_arguments' ] diff --git a/src/Resources/config/services/helpers.yml b/src/Resources/config/services/helpers.yml new file mode 100644 index 0000000..99ead7c --- /dev/null +++ b/src/Resources/config/services/helpers.yml @@ -0,0 +1,5 @@ +services: + alma.sylius_payment_plugin.helper.eligibility: + class: Alma\SyliusPaymentPlugin\Helper\EligibilityHelper + arguments: + $almaBridge: '@alma_sylius_payment_plugin.bridge' \ No newline at end of file From 0da1d84af71f950d8fcfea37ba617d4fe2acd9a8 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Thu, 14 Sep 2023 09:38:45 +0200 Subject: [PATCH 14/43] suite --- .../Checkout/SelectPayment/_choice.html.twig | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig deleted file mode 100644 index 1e2ced6..0000000 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choice.html.twig +++ /dev/null @@ -1,19 +0,0 @@ -
-
-
- {{ 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 method.gatewayConfig.factoryName == 'sylius.pay_pal' %} - {{ render(controller('Sylius\\PayPalPlugin\\Controller\\PayPalButtonsController::renderPaymentPageButtonsAction', {'orderId': order.id})) }} - {% endif %} -
-
- From 4bc349e6abc78b319a54961ee9a7d16cee0e5650 Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Thu, 14 Sep 2023 09:55:20 +0200 Subject: [PATCH 15/43] suite --- src/Controller/InstallmentsController.php | 6 ++++-- src/Resources/views/_partials/_almaPnx.html.twig | 1 + src/Resources/views/_partials/_almaPnxPlus4.html.twig | 1 + src/Resources/views/installmentPlan.html.twig | 7 ++++++- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/Resources/views/_partials/_almaPnx.html.twig create mode 100644 src/Resources/views/_partials/_almaPnxPlus4.html.twig diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index 925be27..eff63b0 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -72,17 +72,19 @@ public function renderInstallmentPlanAction(Request $request): Response /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $this->paymentMethodRepository->find($methodId); + $installmentsCount = $paymentMethod->getGatewayConfig()->getConfig()["installments_count"]; $eligibilities = $this->eligibilityHelper->getEligibilities( $order->getTotal(), - $paymentMethod->getGatewayConfig()->getConfig()["installments_count"], + $installmentsCount, $order->getBillingAddress()->getCountryCode(), $order->getShippingAddress()->getCountryCode(), substr($request->getLocale(), 0, 2) ); return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ - 'eligibilities' => $eligibilities + 'eligibilities' => $eligibilities, + 'installmentsCount' => $installmentsCount ])); } catch (\InvalidArgumentException $exception) { return new Response(''); diff --git a/src/Resources/views/_partials/_almaPnx.html.twig b/src/Resources/views/_partials/_almaPnx.html.twig new file mode 100644 index 0000000..96d3a5b --- /dev/null +++ b/src/Resources/views/_partials/_almaPnx.html.twig @@ -0,0 +1 @@ +{{ dump(installmentsCount) }} \ No newline at end of file diff --git a/src/Resources/views/_partials/_almaPnxPlus4.html.twig b/src/Resources/views/_partials/_almaPnxPlus4.html.twig new file mode 100644 index 0000000..6bbf05d --- /dev/null +++ b/src/Resources/views/_partials/_almaPnxPlus4.html.twig @@ -0,0 +1 @@ +{{ dump(eligibilities) }} \ No newline at end of file diff --git a/src/Resources/views/installmentPlan.html.twig b/src/Resources/views/installmentPlan.html.twig index d69da80..3750daf 100644 --- a/src/Resources/views/installmentPlan.html.twig +++ b/src/Resources/views/installmentPlan.html.twig @@ -1,3 +1,8 @@
- Installment Plan {{ dump(eligibilities) }} + Installment Plan + {% if installmentsCount <= 4 %} + {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnx.html.twig' with {'installmentsCount': installmentsCount, 'eligibilities': eligibilities} %} + {% else %} + {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnxPlus4.html.twig' with {'installmentsCount': installmentsCount, 'eligibilities': eligibilities} %} + {% endif %}
\ No newline at end of file From 57d7052ce0edaeb10cdb4589638dbc8f23866501 Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Thu, 14 Sep 2023 14:31:38 +0200 Subject: [PATCH 16/43] integration list installment --- src/Resources/translations/checkout.en.yml | 4 +++ src/Resources/translations/checkout.fr.yml | 4 +++ .../views/_partials/_almaPnx.html.twig | 17 ++++++++++++- .../views/_partials/_almaPnxPlus4.html.twig | 25 ++++++++++++++++++- src/Resources/views/installmentPlan.html.twig | 1 - 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/Resources/translations/checkout.en.yml create mode 100644 src/Resources/translations/checkout.fr.yml diff --git a/src/Resources/translations/checkout.en.yml b/src/Resources/translations/checkout.en.yml new file mode 100644 index 0000000..32ee5a3 --- /dev/null +++ b/src/Resources/translations/checkout.en.yml @@ -0,0 +1,4 @@ +alma_sylius_payment_plugin: + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit diff --git a/src/Resources/translations/checkout.fr.yml b/src/Resources/translations/checkout.fr.yml new file mode 100644 index 0000000..bc7b779 --- /dev/null +++ b/src/Resources/translations/checkout.fr.yml @@ -0,0 +1,4 @@ +alma_sylius_payment_plugin: + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Votre crédit diff --git a/src/Resources/views/_partials/_almaPnx.html.twig b/src/Resources/views/_partials/_almaPnx.html.twig index 96d3a5b..bdccac4 100644 --- a/src/Resources/views/_partials/_almaPnx.html.twig +++ b/src/Resources/views/_partials/_almaPnx.html.twig @@ -1 +1,16 @@ -{{ dump(installmentsCount) }} \ No newline at end of file +
+

Fast and secure payment by credit card.

+ {% for count, plan in eligibilities['general_3_0_0'].paymentPlan %} +
+ + {{ plan.due_date }} + + + {{ plan.purchase_amount }} + {% if count == 0 %} + (Including fees: {{ plan.customer_fee }}) + {% endif %} + +
+ {% endfor %} +
\ No newline at end of file diff --git a/src/Resources/views/_partials/_almaPnxPlus4.html.twig b/src/Resources/views/_partials/_almaPnxPlus4.html.twig index 6bbf05d..ba20e33 100644 --- a/src/Resources/views/_partials/_almaPnxPlus4.html.twig +++ b/src/Resources/views/_partials/_almaPnxPlus4.html.twig @@ -1 +1,24 @@ -{{ dump(eligibilities) }} \ No newline at end of file +{{ dump(eligibilities) }} +{% set firstAmount = eligibilities['general_10_0_0'].paymentPlan[0].total_amount %} +{% set nextAmount = eligibilities['general_10_0_0'].paymentPlan[1].total_amount %} +
+

Fast and secure payment by credit card.

+ {# {{ message|trans({'%name%': 'Fabien'}, 'app') }}{{ "%s today then %d x %s"|trans(firstAmount, installmentsCount - 1, nextAmount) }}#} + {{ 'alma_sylius_payment_plugin.checkout.your_credit'|trans }} + + Cart total + + + + Cost of credit + + + + Fixed APR + + + + Total + + +
\ No newline at end of file diff --git a/src/Resources/views/installmentPlan.html.twig b/src/Resources/views/installmentPlan.html.twig index 3750daf..c4fba66 100644 --- a/src/Resources/views/installmentPlan.html.twig +++ b/src/Resources/views/installmentPlan.html.twig @@ -1,5 +1,4 @@
- Installment Plan {% if installmentsCount <= 4 %} {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnx.html.twig' with {'installmentsCount': installmentsCount, 'eligibilities': eligibilities} %} {% else %} From 1a012103738e5a414ba402ff377219f0a4610bcc Mon Sep 17 00:00:00 2001 From: ClaireAlma Date: Thu, 14 Sep 2023 15:57:11 +0200 Subject: [PATCH 17/43] Add crowdin configuration --- .gitignore | 1 + crowdin.example.yaml | 13 +++++++++++++ src/Resources/translations/checkout.en.yml | 4 ---- src/Resources/translations/checkout.fr.yml | 4 ---- 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 crowdin.example.yaml delete mode 100644 src/Resources/translations/checkout.en.yml delete mode 100644 src/Resources/translations/checkout.fr.yml diff --git a/.gitignore b/.gitignore index 821270a..bc9be13 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /behat.yml /phpspec.yml /phpunit.xml +/crowdin.yaml diff --git a/crowdin.example.yaml b/crowdin.example.yaml new file mode 100644 index 0000000..63dc09e --- /dev/null +++ b/crowdin.example.yaml @@ -0,0 +1,13 @@ +"project_id" : "35" +"api_token" : "MY_API_TOKEN" +"base_path" : "src/" +"base_url" : "https://mycompany.crowdin.com" +"preserve_hierarchy": true + +files: + - + source: Resources/translations/messages.en.yml + translation: Resources/translations/messages.%two_letters_code%.yml + - + source: Resources/translations/flashes.en.yml + translation: Resources/translations/flashes.%two_letters_code%.yml \ No newline at end of file diff --git a/src/Resources/translations/checkout.en.yml b/src/Resources/translations/checkout.en.yml deleted file mode 100644 index 32ee5a3..0000000 --- a/src/Resources/translations/checkout.en.yml +++ /dev/null @@ -1,4 +0,0 @@ -alma_sylius_payment_plugin: - checkout: - installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' - your_credit: Your credit diff --git a/src/Resources/translations/checkout.fr.yml b/src/Resources/translations/checkout.fr.yml deleted file mode 100644 index bc7b779..0000000 --- a/src/Resources/translations/checkout.fr.yml +++ /dev/null @@ -1,4 +0,0 @@ -alma_sylius_payment_plugin: - checkout: - installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' - your_credit: Votre crédit From 2806b1990ab28ac925551fe9b1bd9c50312119f3 Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Thu, 14 Sep 2023 17:19:06 +0200 Subject: [PATCH 18/43] wip: integration plan credit --- src/Controller/InstallmentsController.php | 17 +++++- src/Resources/translations/messages.en.yml | 14 +++-- src/Resources/translations/messages.fr.yml | 10 ++++ .../views/_partials/_almaPnx.html.twig | 40 ++++++++----- .../views/_partials/_almaPnxPlus4.html.twig | 60 ++++++++++++------- .../SelectPayment/_choiceAlma.html.twig | 2 +- src/Resources/views/installmentPlan.html.twig | 12 +++- 7 files changed, 106 insertions(+), 49 deletions(-) diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php index eff63b0..c6d830b 100644 --- a/src/Controller/InstallmentsController.php +++ b/src/Controller/InstallmentsController.php @@ -73,18 +73,29 @@ public function renderInstallmentPlanAction(Request $request): Response /** @var PaymentMethodInterface $paymentMethod */ $paymentMethod = $this->paymentMethodRepository->find($methodId); $installmentsCount = $paymentMethod->getGatewayConfig()->getConfig()["installments_count"]; + $totalCart = $order->getTotal(); $eligibilities = $this->eligibilityHelper->getEligibilities( - $order->getTotal(), + $totalCart, $installmentsCount, $order->getBillingAddress()->getCountryCode(), $order->getShippingAddress()->getCountryCode(), substr($request->getLocale(), 0, 2) ); + $plan = $eligibilities['general_'.$installmentsCount.'_0_0']; + + $creditInfo = [ + 'totalCart' => $totalCart, + 'costCredit' => $plan->customerTotalCostAmount, + 'totalCredit' => $plan->customerTotalCostAmount + $totalCart, + 'taeg' => $plan->annualInterestRate, + ]; + return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ - 'eligibilities' => $eligibilities, - 'installmentsCount' => $installmentsCount + 'plans' => $plan, + 'installmentsCount' => $installmentsCount, + 'creditInfo' => $creditInfo ])); } catch (\InvalidArgumentException $exception) { return new Response(''); diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 55b9228..b37deaa 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -3,21 +3,25 @@ alma_sylius_payment_plugin: live_api_key_label: Live API key test_api_key_label: Test API key find_api_keys_in_dashboard: You can find your API keys on your dashboard. - api_mode_label: API mode api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. - installments_count_label: Installments count installments_count_choice_label: '%installments_count% installments' - payment_page_mode_label: Payment page mode payment_page_mode_in_page: Iframe payment_page_mode_redirect: Redirect to Alma - errors: invalid_api_key: API key is invalid empty_api_key: Please provide an API key - api: live_mode: Live test_mode: Test + checkout: + fast_and_secure_payment_by_credit_card: Fast and secure payment by credit card + today: Today + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit + cart_total: Cart total + cost_of_credit: Cost of credit + fixed_apr: Fixed APR + total: Total diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 3b71c65..16a5bd5 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -21,3 +21,13 @@ alma_sylius_payment_plugin: api: live_mode: Live test_mode: Test + checkout: + fast_and_secure_payment_by_credit_card: Paiement rapide et sécurisé, par carte bancaire. + today: "Aujourd'hui" + installment_one_line: "%firstAmount% aujourd'hui puis %installment% x %nextAmount%" + your_credit: Votre crédit + cart_total: Votre panier + cost_of_credit: Coût du crédit + fixed_apr: TAEG fixe + total: Total + diff --git a/src/Resources/views/_partials/_almaPnx.html.twig b/src/Resources/views/_partials/_almaPnx.html.twig index bdccac4..4698118 100644 --- a/src/Resources/views/_partials/_almaPnx.html.twig +++ b/src/Resources/views/_partials/_almaPnx.html.twig @@ -1,16 +1,26 @@ -
-

Fast and secure payment by credit card.

- {% for count, plan in eligibilities['general_3_0_0'].paymentPlan %} -
- - {{ plan.due_date }} - - - {{ plan.purchase_amount }} - {% if count == 0 %} - (Including fees: {{ plan.customer_fee }}) - {% endif %} - -
- {% endfor %} +
+

{{ 'alma_sylius_payment_plugin.checkout.fast_and_secure_payment_by_credit_card'|trans }}

+ {% for count, plan in plans.paymentPlan %} + {% set total_amount = plan.total_amount / 100 %} +
+
+
+ {% if count == 0 %} + {{ 'alma_sylius_payment_plugin.checkout.today'|trans }} + {% else %} + {{ plan.due_date|date("d/m/Y") }} + {% endif %} +
+
+ {{ total_amount|format_currency('EUR') }} + {% if count == 0 %} +
+ (Including fees: {{ plan.customer_fee }}) +
+ {% endif %} +
+
+
+
+ {% endfor %}
\ No newline at end of file diff --git a/src/Resources/views/_partials/_almaPnxPlus4.html.twig b/src/Resources/views/_partials/_almaPnxPlus4.html.twig index ba20e33..868a6e0 100644 --- a/src/Resources/views/_partials/_almaPnxPlus4.html.twig +++ b/src/Resources/views/_partials/_almaPnxPlus4.html.twig @@ -1,24 +1,38 @@ -{{ dump(eligibilities) }} -{% set firstAmount = eligibilities['general_10_0_0'].paymentPlan[0].total_amount %} -{% set nextAmount = eligibilities['general_10_0_0'].paymentPlan[1].total_amount %} -
-

Fast and secure payment by credit card.

- {# {{ message|trans({'%name%': 'Fabien'}, 'app') }}{{ "%s today then %d x %s"|trans(firstAmount, installmentsCount - 1, nextAmount) }}#} - {{ 'alma_sylius_payment_plugin.checkout.your_credit'|trans }} - - Cart total - - - - Cost of credit - - - - Fixed APR - - - - Total - - +{% set firstAmount = plans.paymentPlan[0].total_amount / 100 %} +{% set nextAmount = plans.paymentPlan[1].total_amount / 100 %} +{% set totalCart = creditInfo.totalCart / 100 %} +{% set costCredit = creditInfo.costCredit / 100 %} +{% set taeg = creditInfo.taeg / 10000 %} +{% set totalCredit = creditInfo.totalCredit / 100 %} +
+

{{ 'alma_sylius_payment_plugin.checkout.fast_and_secure_payment_by_credit_card'|trans }}

+
{{ 'alma_sylius_payment_plugin.checkout.installment_one_line'|trans({'%firstAmount%': firstAmount|format_currency('EUR'), '%installment%': installmentsCount - 1, '%nextAmount%': nextAmount|format_currency('EUR')}) }}
+

{{ 'alma_sylius_payment_plugin.checkout.your_credit'|trans }}

+
+
+ {{ 'alma_sylius_payment_plugin.checkout.cart_total'|trans }} + {{ totalCart|format_currency('EUR') }} +
+
+
+
+
+ {{ 'alma_sylius_payment_plugin.checkout.cost_of_credit'|trans }} + {{ costCredit|format_currency('EUR') }} +
+
+
+
+
+ {{ 'alma_sylius_payment_plugin.checkout.fixed_apr'|trans }} + {{ taeg|format_percent_number({rounding_mode: 'floor', fraction_digit: 2}) }} +
+
+
+
+
+ {{ 'alma_sylius_payment_plugin.checkout.total'|trans }} + {{ totalCredit|format_currency('EUR') }} +
+
\ No newline at end of file diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig index 9b9bee8..4446961 100644 --- a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig @@ -5,7 +5,7 @@
- {{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} + {{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} logo Alma {% if method.description is not null %}

{{ method.description }}

diff --git a/src/Resources/views/installmentPlan.html.twig b/src/Resources/views/installmentPlan.html.twig index c4fba66..f43d4d7 100644 --- a/src/Resources/views/installmentPlan.html.twig +++ b/src/Resources/views/installmentPlan.html.twig @@ -1,7 +1,15 @@ +
{% if installmentsCount <= 4 %} - {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnx.html.twig' with {'installmentsCount': installmentsCount, 'eligibilities': eligibilities} %} + {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnx.html.twig' with {'installmentsCount': installmentsCount, 'plans': plans} %} {% else %} - {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnxPlus4.html.twig' with {'installmentsCount': installmentsCount, 'eligibilities': eligibilities} %} + {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnxPlus4.html.twig' with {'installmentsCount': installmentsCount, 'plans': plans, 'creditInfo': creditInfo} %} {% endif %}
\ No newline at end of file From ff743cfd97d0d495bae9493968f08915684dfddd Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Thu, 14 Sep 2023 17:20:46 +0200 Subject: [PATCH 19/43] add translations --- src/Resources/translations/flashes.de.yml | 5 +++++ src/Resources/translations/flashes.es.yml | 5 +++++ src/Resources/translations/flashes.it.yml | 5 +++++ src/Resources/translations/flashes.nl.yml | 5 +++++ src/Resources/translations/flashes.pt.yml | 5 +++++ src/Resources/translations/messages.de.yml | 21 +++++++++++++++++++++ src/Resources/translations/messages.es.yml | 21 +++++++++++++++++++++ src/Resources/translations/messages.it.yml | 21 +++++++++++++++++++++ src/Resources/translations/messages.nl.yml | 21 +++++++++++++++++++++ src/Resources/translations/messages.pt.yml | 21 +++++++++++++++++++++ 10 files changed, 130 insertions(+) create mode 100644 src/Resources/translations/flashes.de.yml create mode 100644 src/Resources/translations/flashes.es.yml create mode 100644 src/Resources/translations/flashes.it.yml create mode 100644 src/Resources/translations/flashes.nl.yml create mode 100644 src/Resources/translations/flashes.pt.yml create mode 100644 src/Resources/translations/messages.de.yml create mode 100644 src/Resources/translations/messages.es.yml create mode 100644 src/Resources/translations/messages.it.yml create mode 100644 src/Resources/translations/messages.nl.yml create mode 100644 src/Resources/translations/messages.pt.yml diff --git a/src/Resources/translations/flashes.de.yml b/src/Resources/translations/flashes.de.yml new file mode 100644 index 0000000..650fb91 --- /dev/null +++ b/src/Resources/translations/flashes.de.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: An error occurred. Your Alma payment has been fully refunded. Please try again. + failed_not_refunded: 'An error occurred and your Alma payment could not be refunded. Please contact us and provide the following reference: %pid%' + creation_failed: An error occurred during payment initialization. Please try again or choose another payment method. diff --git a/src/Resources/translations/flashes.es.yml b/src/Resources/translations/flashes.es.yml new file mode 100644 index 0000000..650fb91 --- /dev/null +++ b/src/Resources/translations/flashes.es.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: An error occurred. Your Alma payment has been fully refunded. Please try again. + failed_not_refunded: 'An error occurred and your Alma payment could not be refunded. Please contact us and provide the following reference: %pid%' + creation_failed: An error occurred during payment initialization. Please try again or choose another payment method. diff --git a/src/Resources/translations/flashes.it.yml b/src/Resources/translations/flashes.it.yml new file mode 100644 index 0000000..650fb91 --- /dev/null +++ b/src/Resources/translations/flashes.it.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: An error occurred. Your Alma payment has been fully refunded. Please try again. + failed_not_refunded: 'An error occurred and your Alma payment could not be refunded. Please contact us and provide the following reference: %pid%' + creation_failed: An error occurred during payment initialization. Please try again or choose another payment method. diff --git a/src/Resources/translations/flashes.nl.yml b/src/Resources/translations/flashes.nl.yml new file mode 100644 index 0000000..650fb91 --- /dev/null +++ b/src/Resources/translations/flashes.nl.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: An error occurred. Your Alma payment has been fully refunded. Please try again. + failed_not_refunded: 'An error occurred and your Alma payment could not be refunded. Please contact us and provide the following reference: %pid%' + creation_failed: An error occurred during payment initialization. Please try again or choose another payment method. diff --git a/src/Resources/translations/flashes.pt.yml b/src/Resources/translations/flashes.pt.yml new file mode 100644 index 0000000..650fb91 --- /dev/null +++ b/src/Resources/translations/flashes.pt.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: An error occurred. Your Alma payment has been fully refunded. Please try again. + failed_not_refunded: 'An error occurred and your Alma payment could not be refunded. Please contact us and provide the following reference: %pid%' + creation_failed: An error occurred during payment initialization. Please try again or choose another payment method. diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml new file mode 100644 index 0000000..e708d6a --- /dev/null +++ b/src/Resources/translations/messages.de.yml @@ -0,0 +1,21 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live API key + test_api_key_label: Test API key + find_api_keys_in_dashboard: You can find your API keys on your dashboard. + api_mode_label: API mode + api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. + installments_count_label: Installments count + installments_count_choice_label: '%installments_count% installments' + payment_page_mode_label: Payment page mode + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirect to Alma + errors: + invalid_api_key: API key is invalid + empty_api_key: Please provide an API key + api: + live_mode: Live + test_mode: Test + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml new file mode 100644 index 0000000..e708d6a --- /dev/null +++ b/src/Resources/translations/messages.es.yml @@ -0,0 +1,21 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live API key + test_api_key_label: Test API key + find_api_keys_in_dashboard: You can find your API keys on your dashboard. + api_mode_label: API mode + api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. + installments_count_label: Installments count + installments_count_choice_label: '%installments_count% installments' + payment_page_mode_label: Payment page mode + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirect to Alma + errors: + invalid_api_key: API key is invalid + empty_api_key: Please provide an API key + api: + live_mode: Live + test_mode: Test + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit diff --git a/src/Resources/translations/messages.it.yml b/src/Resources/translations/messages.it.yml new file mode 100644 index 0000000..e708d6a --- /dev/null +++ b/src/Resources/translations/messages.it.yml @@ -0,0 +1,21 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live API key + test_api_key_label: Test API key + find_api_keys_in_dashboard: You can find your API keys on your dashboard. + api_mode_label: API mode + api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. + installments_count_label: Installments count + installments_count_choice_label: '%installments_count% installments' + payment_page_mode_label: Payment page mode + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirect to Alma + errors: + invalid_api_key: API key is invalid + empty_api_key: Please provide an API key + api: + live_mode: Live + test_mode: Test + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml new file mode 100644 index 0000000..e708d6a --- /dev/null +++ b/src/Resources/translations/messages.nl.yml @@ -0,0 +1,21 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live API key + test_api_key_label: Test API key + find_api_keys_in_dashboard: You can find your API keys on your dashboard. + api_mode_label: API mode + api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. + installments_count_label: Installments count + installments_count_choice_label: '%installments_count% installments' + payment_page_mode_label: Payment page mode + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirect to Alma + errors: + invalid_api_key: API key is invalid + empty_api_key: Please provide an API key + api: + live_mode: Live + test_mode: Test + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit diff --git a/src/Resources/translations/messages.pt.yml b/src/Resources/translations/messages.pt.yml new file mode 100644 index 0000000..e708d6a --- /dev/null +++ b/src/Resources/translations/messages.pt.yml @@ -0,0 +1,21 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live API key + test_api_key_label: Test API key + find_api_keys_in_dashboard: You can find your API keys on your dashboard. + api_mode_label: API mode + api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. + installments_count_label: Installments count + installments_count_choice_label: '%installments_count% installments' + payment_page_mode_label: Payment page mode + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirect to Alma + errors: + invalid_api_key: API key is invalid + empty_api_key: Please provide an API key + api: + live_mode: Live + test_mode: Test + checkout: + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit From 4ba4f3c345b0de2eb03f9991b4305a795ebc03a4 Mon Sep 17 00:00:00 2001 From: Benjamin Freoua Date: Fri, 15 Sep 2023 15:59:49 +0200 Subject: [PATCH 20/43] wip: add assets --- src/Resources/config/config.yaml | 3 --- src/Resources/config/services.yml | 1 + src/Resources/config/services/assets.yml | 10 ++++++++++ src/Resources/public/css/alma.css | 9 +++++++++ src/Resources/public/js/alma.js | 7 +++++++ src/Resources/translations/messages.en.yml | 1 + src/Resources/translations/messages.fr.yml | 1 + src/Resources/views/_partials/_almaPnx.html.twig | 6 ++++-- .../views/_partials/_almaPnxPlus4.html.twig | 2 +- .../views/_partials/_javascript.html.twig | 1 + src/Resources/views/assets/shop/entry.js | 7 +++++++ .../Checkout/SelectPayment/_choiceAlma.html.twig | 7 +++++-- src/Resources/views/installmentPlan.html.twig | 14 +++++--------- 13 files changed, 52 insertions(+), 17 deletions(-) delete mode 100644 src/Resources/config/config.yaml create mode 100644 src/Resources/config/services/assets.yml create mode 100644 src/Resources/public/css/alma.css create mode 100644 src/Resources/public/js/alma.js create mode 100644 src/Resources/views/_partials/_javascript.html.twig create mode 100644 src/Resources/views/assets/shop/entry.js diff --git a/src/Resources/config/config.yaml b/src/Resources/config/config.yaml deleted file mode 100644 index 467e463..0000000 --- a/src/Resources/config/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -twig: - paths: - '%kernel.project_dir%/vendor/alma/sylius-payment-plugin/src/Resources/views/bundles/SyliusShopBundle': SyliusShop \ No newline at end of file diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 6caf169..c2d7d9f 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,6 +1,7 @@ imports: - services/api.yml - services/helpers.yml + - services/assets.yml - services/controllers.yml - services/gateway.yml - services/actions.yml diff --git a/src/Resources/config/services/assets.yml b/src/Resources/config/services/assets.yml new file mode 100644 index 0000000..b79c54f --- /dev/null +++ b/src/Resources/config/services/assets.yml @@ -0,0 +1,10 @@ +services: + sylius.shop.block_event_listener.javascripts: + class: Sylius\Bundle\UiBundle\Block\BlockEventListener + arguments: + - '@AlmaSyliusPaymentPlugin/_partials/_javascript.html.twig' + tags: + - + name: kernel.event_listener, + event: sylius.shop.layout.javascripts, + method: onBlockEvent diff --git a/src/Resources/public/css/alma.css b/src/Resources/public/css/alma.css new file mode 100644 index 0000000..65dbf27 --- /dev/null +++ b/src/Resources/public/css/alma.css @@ -0,0 +1,9 @@ +.alma .grey { + color: #7a7a7a; +} +.alma .ui.tiny.header{ + font-size: 1rem !important; +} +.alma .hidden{ + display: none; +} \ No newline at end of file diff --git a/src/Resources/public/js/alma.js b/src/Resources/public/js/alma.js new file mode 100644 index 0000000..9876b4c --- /dev/null +++ b/src/Resources/public/js/alma.js @@ -0,0 +1,7 @@ + +$(function() { + console.log('TOTO !!!!'); + $('input[data-payment*=alma-method]').on('click', function() { + $(this).parents('.item').next('.content').show(); + }); +}); \ No newline at end of file diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index b37deaa..ca037b5 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -25,3 +25,4 @@ alma_sylius_payment_plugin: cost_of_credit: Cost of credit fixed_apr: Fixed APR total: Total + including_fees: "Including fees: %includingFees%" diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 16a5bd5..52b7480 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -30,4 +30,5 @@ alma_sylius_payment_plugin: cost_of_credit: Coût du crédit fixed_apr: TAEG fixe total: Total + including_fees: "Dont frais inclus: %includingFees%" diff --git a/src/Resources/views/_partials/_almaPnx.html.twig b/src/Resources/views/_partials/_almaPnx.html.twig index 4698118..a35a675 100644 --- a/src/Resources/views/_partials/_almaPnx.html.twig +++ b/src/Resources/views/_partials/_almaPnx.html.twig @@ -1,4 +1,4 @@ -
+ diff --git a/src/Resources/views/_partials/_almaPnxPlus4.html.twig b/src/Resources/views/_partials/_almaPnxPlus4.html.twig index 868a6e0..dd2a459 100644 --- a/src/Resources/views/_partials/_almaPnxPlus4.html.twig +++ b/src/Resources/views/_partials/_almaPnxPlus4.html.twig @@ -4,7 +4,7 @@ {% set costCredit = creditInfo.costCredit / 100 %} {% set taeg = creditInfo.taeg / 10000 %} {% set totalCredit = creditInfo.totalCredit / 100 %} -
+