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
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusQuadPayPlugin\Twig\Extension; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusQuadPayPlugin\QuadPayGatewayFactory; |
16
|
|
|
use BitBag\SyliusQuadPayPlugin\Repository\PaymentMethodRepositoryInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
18
|
|
|
use Sylius\Component\Core\Model\PaymentMethodInterface; |
19
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
20
|
|
|
|
21
|
|
|
final class RenderWidgetExtension extends \Twig_Extension |
22
|
|
|
{ |
23
|
|
|
/** @var PaymentMethodRepositoryInterface */ |
24
|
|
|
private $paymentMethodRepository; |
25
|
|
|
|
26
|
|
|
/** @var EngineInterface */ |
27
|
|
|
private $templatingEngine; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
PaymentMethodRepositoryInterface $paymentMethodRepository, |
31
|
|
|
EngineInterface $templatingEngine |
32
|
|
|
) { |
33
|
|
|
$this->paymentMethodRepository = $paymentMethodRepository; |
34
|
|
|
$this->templatingEngine = $templatingEngine; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getFunctions(): array |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
new \Twig_Function('bitbag_quadpay_render_widget', [$this, 'renderQuadPayWidget'], ['is_safe' => ['html']]), |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function renderQuadPayWidget(int $amount, ChannelInterface $channel, PaymentMethodInterface $paymentMethod = null): string |
45
|
|
|
{ |
46
|
|
|
if (null === $paymentMethod) { |
47
|
|
|
$paymentMethod = $this->paymentMethodRepository->findOneByGatewayFactoryNameAndChannel(QuadPayGatewayFactory::FACTORY_NAME, $channel); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (null === $paymentMethod) { |
51
|
|
|
|
52
|
|
|
return ''; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$config = $paymentMethod->getGatewayConfig()->getConfig(); |
56
|
|
|
|
57
|
|
|
return $this->templatingEngine->render('@BitBagSyliusQuadPayPlugin/_widget.html.twig', [ |
58
|
|
|
'amount' => $amount, |
59
|
|
|
'paymentMethod' => $paymentMethod, |
60
|
|
|
'minAmount' => $config['minimumAmount'], |
61
|
|
|
'maxAmount' => $config['maximumAmount'], |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|