From 0c0889dc9e233177960fea0d139ba183b7471360 Mon Sep 17 00:00:00 2001 From: Alexandre Segura Date: Tue, 5 Nov 2024 08:40:10 +0100 Subject: [PATCH] WIP --- .../components/Payment/PaymentMethodIcon.js | 18 +++++++ .../components/Payment/PaymentMethodPicker.js | 49 +++++++++++++++++-- js/app/components/Payment/index.js | 35 +++++++++++++ js/app/i18n/locales/en.json | 5 +- src/Command/SetupCommand.php | 15 ++++++ src/Form/Checkout/CheckoutPaymentType.php | 16 ++++++ src/Service/SettingsManager.php | 2 + templates/order/payment.html.twig | 4 ++ 8 files changed, 138 insertions(+), 6 deletions(-) diff --git a/js/app/components/Payment/PaymentMethodIcon.js b/js/app/components/Payment/PaymentMethodIcon.js index b5e34ff75e..c99dfab41d 100644 --- a/js/app/components/Payment/PaymentMethodIcon.js +++ b/js/app/components/Payment/PaymentMethodIcon.js @@ -4,6 +4,9 @@ import mastercard from 'payment-icons/min/flat/mastercard.svg' import visa from 'payment-icons/min/flat/visa.svg' import edenredLogo from '../../../../assets/svg/Edenred_Logo.svg' import cashLogo from '../../../../assets/svg/dollar-bill-svgrepo-com.svg' +import restoflashLogo from './restoflash.svg' +import conecsLogo from './conecs.svg' +import swileLogo from './swile.svg' export default ({ code, height }) => { switch (code.toLowerCase()) { @@ -25,6 +28,21 @@ export default ({ code, height }) => { return ( ) + + case 'restoflash': + return ( + + ) + + case 'conecs': + return ( + + ) + + case 'swile': + return ( + + ) } return null diff --git a/js/app/components/Payment/PaymentMethodPicker.js b/js/app/components/Payment/PaymentMethodPicker.js index a2b029c63c..1d9b981714 100644 --- a/js/app/components/Payment/PaymentMethodPicker.js +++ b/js/app/components/Payment/PaymentMethodPicker.js @@ -47,7 +47,7 @@ export default function PaymentMethodPicker({ methods, onSelect }) { return (
- @@ -57,9 +57,9 @@ export default function PaymentMethodPicker({ methods, onSelect }) { case 'edenred': return ( -
+
-
) + case 'restoflash': + + return ( +
+ + +
+ ) + + case 'conecs': + + return ( +
+ + +
+ ) + + case 'swile': + + return ( +
+ + +
+ ) + } }) }
diff --git a/js/app/components/Payment/index.js b/js/app/components/Payment/index.js index 40c9d5b8f2..5d1b8d8441 100644 --- a/js/app/components/Payment/index.js +++ b/js/app/components/Payment/index.js @@ -229,6 +229,41 @@ export default function(formSelector, options) { payments = response.data.payments switch (value) { + + case 'restoflash': + case 'swile': + case 'conecs': + + const paygreenStatus = window.paygreenjs.status(); + const isPaygreenInitialized = null !== paygreenStatus.paymentOrder; + + // try { + // window.paygreenjs.unmount(true) + // } catch (e) {} + + axios.post(response.data.paygreen.createPaymentOrderURL) + .then(createPaymentOrderResponse => { + if (!isPaygreenInitialized) { + window.paygreenjs.attachEventListener( + window.paygreenjs.Events.ON_OPEN_POPUP, + (event) => console.log(event.detail.url) + ); + window.paygreenjs.init({ + paymentOrderID: createPaymentOrderResponse.data.id, + objectSecret: createPaymentOrderResponse.data.object_secret, + publicKey: cc.config.gatewayConfig.publicKey, + mode: 'payment', + displayAuthentication: 'modal', + paymentMethod: value + // style, + }); + } else { + window.paygreenjs.setPaymentMethod(value); + } + }); + + break + case 'card': case 'edenred': diff --git a/js/app/i18n/locales/en.json b/js/app/i18n/locales/en.json index a1fe20b0c9..9f3810d750 100644 --- a/js/app/i18n/locales/en.json +++ b/js/app/i18n/locales/en.json @@ -599,6 +599,9 @@ "on": "on", "weekday": "weekday", "day": "day" - } + }, + "PM_RESTOFLASH": "Restoflash", + "PM_CONECS": "Bimpl, Pluxee, UpDéjeuner", + "PM_SWILE": "Swile" } } diff --git a/src/Command/SetupCommand.php b/src/Command/SetupCommand.php index b638ef73b3..77dc269ce4 100644 --- a/src/Command/SetupCommand.php +++ b/src/Command/SetupCommand.php @@ -240,6 +240,21 @@ private function createSyliusPaymentMethods(OutputInterface $output) 'name' => 'Cash on delivery', 'countries' => ['mx','ar'], ], + [ + 'code' => 'RESTOFLASH', + 'name' => 'Restoflash', + 'countries' => ['fr'], + ], + [ + 'code' => 'CONECS', + 'name' => 'Conecs', + 'countries' => ['fr'], + ], + [ + 'code' => 'SWILE', + 'name' => 'Swile', + 'countries' => ['fr'], + ], ]; foreach ($methods as $method) { diff --git a/src/Form/Checkout/CheckoutPaymentType.php b/src/Form/Checkout/CheckoutPaymentType.php index 5fb2c45bc4..e241ff8da9 100644 --- a/src/Form/Checkout/CheckoutPaymentType.php +++ b/src/Form/Checkout/CheckoutPaymentType.php @@ -6,6 +6,7 @@ use AppBundle\Edenred\Client as EdenredPayment; use AppBundle\Form\StripePaymentType; use AppBundle\Payment\GatewayResolver; +use AppBundle\Service\PaygreenManager; use AppBundle\Service\SettingsManager; use AppBundle\Sylius\Customer\CustomerInterface; use Symfony\Component\Form\AbstractType; @@ -24,6 +25,7 @@ public function __construct( private EdenredAuthentication $edenredAuthentication, private EdenredPayment $edenredPayment, private SettingsManager $settingsManager, + private PaygreenManager $paygreenManager, private bool $cashEnabled) { } @@ -54,6 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $choices = []; if ($this->settingsManager->supportsCardPayments()) { + // Card payment is supposedly always supported if gateway is configured, even for Paygreen $choices['Credit card'] = 'card'; } @@ -72,6 +75,19 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } + if (!$order->isMultiVendor() && 'paygreen' === $this->resolver->resolveForOrder($order)) { + $paygreenPlatforms = $this->paygreenManager->getEnabledPlatforms($order->getRestaurant()->getPaygreenShopId()); + if (in_array('restoflash', $paygreenPlatforms)) { + $choices['Restoflash'] = 'restoflash'; + } + if (in_array('conecs', $paygreenPlatforms)) { + $choices['Conecs'] = 'conecs'; + } + if (in_array('restoflash', $paygreenPlatforms)) { + $choices['Swile'] = 'swile'; + } + } + if ($this->cashEnabled || $order->supportsCashOnDelivery()) { $choices['Cash on delivery'] = 'cash_on_delivery'; } diff --git a/src/Service/SettingsManager.php b/src/Service/SettingsManager.php index 3e78d4ce14..dc8a93f47d 100644 --- a/src/Service/SettingsManager.php +++ b/src/Service/SettingsManager.php @@ -234,6 +234,8 @@ public function supportsCardPayments() return $supportsStripe; } + // TODO Add check for Paygreen + return $supportsStripe || $supportsMercadopago; } diff --git a/templates/order/payment.html.twig b/templates/order/payment.html.twig index 1f20ea2232..69eae8667a 100644 --- a/templates/order/payment.html.twig +++ b/templates/order/payment.html.twig @@ -65,6 +65,10 @@ {{ 'paygreen.choose_another_plaform'|trans }}
+ {# + We DO NOT add the methods container on purpose, + because we manage them at a upper level. + #}