1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
7
|
|
|
* an email on [email protected]. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\Form\Type; |
13
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Resolver\MolliePaymentsMethodResolverInterface; |
15
|
|
|
use BitBag\SyliusMolliePlugin\Validator\Constraints\PaymentMethodCheckout; |
16
|
|
|
use Symfony\Component\Form\AbstractType; |
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
18
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
19
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
21
|
|
|
|
22
|
|
|
final class PaymentMollieType extends AbstractType |
23
|
|
|
{ |
24
|
|
|
/** @var SessionInterface */ |
25
|
|
|
private $session; |
26
|
|
|
|
27
|
|
|
/** @var MolliePaymentsMethodResolverInterface */ |
28
|
|
|
private $methodResolver; |
29
|
|
|
|
30
|
|
|
public function __construct( |
31
|
|
|
SessionInterface $session, |
32
|
|
|
MolliePaymentsMethodResolverInterface $methodResolver |
33
|
|
|
) { |
34
|
|
|
$this->methodResolver = $methodResolver; |
35
|
|
|
$this->session = $session; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
39
|
|
|
{ |
40
|
|
|
$methods = $this->methodResolver->resolve(); |
41
|
|
|
|
42
|
|
|
$data = $methods['data']; |
43
|
|
|
$images = $methods['image']; |
44
|
|
|
$issuers = $methods['issuers']; |
45
|
|
|
$paymentFee = $methods['paymentFee']; |
46
|
|
|
|
47
|
|
|
$builder |
48
|
|
|
->add('molliePaymentMethods', ChoiceType::class, [ |
49
|
|
|
'constraints' => [ |
50
|
|
|
new PaymentMethodCheckout([ |
51
|
|
|
'groups' => ['sylius'], |
52
|
|
|
]), |
53
|
|
|
], |
54
|
|
|
'label' => false, |
55
|
|
|
'choices' => $data, |
56
|
|
|
'choice_attr' => function ($value) use ($images, $paymentFee) { |
57
|
|
|
return [ |
58
|
|
|
'image' => $images[$value], |
59
|
|
|
'paymentFee' => $paymentFee[$value], |
60
|
|
|
]; |
61
|
|
|
}, |
62
|
|
|
]) |
63
|
|
|
->add('issuers', ChoiceType::class, [ |
64
|
|
|
'label' => false, |
65
|
|
|
'choices' => $issuers['ideal'] ?? null, |
66
|
|
|
'choice_label' => 'name', |
67
|
|
|
'choice_attr' => function ($value) { |
68
|
|
|
return ['image' => $value->image->svg]; |
69
|
|
|
}, |
70
|
|
|
]) |
71
|
|
|
->add('cartToken', HiddenType::class); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|