-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCreditCardExtention.php
More file actions
77 lines (66 loc) · 2.43 KB
/
CreditCardExtention.php
File metadata and controls
77 lines (66 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* https://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\SamplePayment\Form\Extension;
use Eccube\Entity\Order;
use Eccube\Form\Type\Shopping\OrderType;
use Eccube\Repository\PaymentRepository;
use Plugin\SamplePayment\Service\Method\CreditCard;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* 注文手続き画面のFormを拡張し、カード入力フォームを追加する.
* 支払い方法に応じてエクステンションを作成する.
*/
class CreditCardExtention extends AbstractTypeExtension
{
/**
* @var PaymentRepository
*/
protected $paymentRepository;
public function __construct(PaymentRepository $paymentRepository)
{
$this->paymentRepository = $paymentRepository;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ShoppingController::checkoutから呼ばれる場合は, フォーム項目の定義をスキップする.
if ($options['skip_add_form']) {
return;
}
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
/** @var Order $data */
$form = $event->getForm();
// 支払い方法が一致する場合
$form->add('sample_payment_token', HiddenType::class, [
'required' => false,
'mapped' => true, // Orderエンティティに追加したカラムなので、mappedはtrue
]);
});
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
// サンプル決済では使用しないが、支払い方法に応じて処理を行う場合は
// $event->getData()ではなく、$event->getForm()->getData()でOrderエンティティを取得できる
/** @var Order $Order */
$Order = $event->getForm()->getData();
$Order->getPayment()->getId();
});
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return OrderType::class;
}
}