Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsegura committed Nov 5, 2024
1 parent c84c54c commit 0c0889d
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 6 deletions.
18 changes: 18 additions & 0 deletions js/app/components/Payment/PaymentMethodIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -25,6 +28,21 @@ export default ({ code, height }) => {
return (
<img src={ cashLogo } height={ height } />
)

case 'restoflash':
return (
<img src={ restoflashLogo } height={ height } style={{ maxWidth: '80px' }} />
)

case 'conecs':
return (
<img src={ conecsLogo } height={ height } />
)

case 'swile':
return (
<img src={ swileLogo } height={ height } style={{ maxWidth: '50px' }} />
)
}

return null
Expand Down
49 changes: 44 additions & 5 deletions js/app/components/Payment/PaymentMethodPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function PaymentMethodPicker({ methods, onSelect }) {
return (
<div style={ methodStyles } key={ m.type }>
<label>{ t('PM_CREDIT_OR_DEBIT_CARD') }</label>
<button key={ m.type } type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === 'card' }) }
<button type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === 'card' }) }
onClick={ () => setMethod('card') }>
<PaymentMethodIcon code={ m.type } height="45" />
</button>
Expand All @@ -57,9 +57,9 @@ export default function PaymentMethodPicker({ methods, onSelect }) {
case 'edenred':

return (
<div style={ methodStyles }key={ m.type }>
<div style={ methodStyles } key={ m.type }>
<label>{ t('PM_EDENRED') }</label>
<button key={ m.type } type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
<button type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
onClick={ () => {

if (!m.data.edenredIsConnected) {
Expand All @@ -77,15 +77,54 @@ export default function PaymentMethodPicker({ methods, onSelect }) {
case 'cash_on_delivery':

return (
<div style={ methodStyles }key={ m.type } data-testid="pm.cash">
<div style={ methodStyles } key={ m.type } data-testid="pm.cash">
<label>{ t('PM_CASH') }</label>
<button key={ m.type } type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
<button type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
onClick={ () => setMethod('cash_on_delivery') }>
<PaymentMethodIcon code={ m.type } height="45" />
</button>
</div>
)

case 'restoflash':

return (
<div style={ methodStyles } key={ m.type } data-testid="pm.restoflash">
<label>{ t('PM_RESTOFLASH') }</label>
<button
type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
onClick={ () => setMethod('restoflash') }>
<PaymentMethodIcon code={ m.type } height="45" />
</button>
</div>
)

case 'conecs':

return (
<div style={ methodStyles } key={ m.type } data-testid="pm.conecs">
<label>{ t('PM_CONECS') }</label>
<button
type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
onClick={ () => setMethod('conecs') }>
<PaymentMethodIcon code={ m.type } height="45" />
</button>
</div>
)

case 'swile':

return (
<div style={ methodStyles } key={ m.type } data-testid="pm.swile">
<label>{ t('PM_SWILE') }</label>
<button
type="button" className={ classNames({ ...methodPickerBtnClassNames, active: method === m.type }) }
onClick={ () => setMethod('swile') }>
<PaymentMethodIcon code={ m.type } height="45" />
</button>
</div>
)

}
}) }
</div>
Expand Down
35 changes: 35 additions & 0 deletions js/app/components/Payment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':

Expand Down
5 changes: 4 additions & 1 deletion js/app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@
"on": "on",
"weekday": "weekday",
"day": "day"
}
},
"PM_RESTOFLASH": "Restoflash",
"PM_CONECS": "Bimpl, Pluxee, UpDéjeuner",
"PM_SWILE": "Swile"
}
}
15 changes: 15 additions & 0 deletions src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions src/Form/Checkout/CheckoutPaymentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,7 @@ public function __construct(
private EdenredAuthentication $edenredAuthentication,
private EdenredPayment $edenredPayment,
private SettingsManager $settingsManager,
private PaygreenManager $paygreenManager,
private bool $cashEnabled)
{ }

Expand Down Expand Up @@ -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';
}

Expand All @@ -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';
}
Expand Down
2 changes: 2 additions & 0 deletions src/Service/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public function supportsCardPayments()
return $supportsStripe;
}

// TODO Add check for Paygreen

return $supportsStripe || $supportsMercadopago;
}

Expand Down
4 changes: 4 additions & 0 deletions templates/order/payment.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
<span>{{ 'paygreen.choose_another_plaform'|trans }}</span>
</a>
</div>
{#
We DO NOT add the methods container on purpose,
because we manage them at a upper level.
#}
<div id="paygreen-methods-container"></div>
<div>
<div id="paygreen-pan-frame" class="mb-3"></div>
Expand Down

0 comments on commit 0c0889d

Please sign in to comment.