-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPluginManager.php
More file actions
180 lines (154 loc) · 6.23 KB
/
PluginManager.php
File metadata and controls
180 lines (154 loc) · 6.23 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?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;
use Eccube\Entity\Payment;
use Eccube\Plugin\AbstractPluginManager;
use Eccube\Repository\PaymentRepository;
use Plugin\SamplePayment\Entity\Config;
use Plugin\SamplePayment\Entity\PaymentStatus;
use Plugin\SamplePayment\Entity\CvsPaymentStatus;
use Plugin\SamplePayment\Entity\CvsType;
use Plugin\SamplePayment\Service\Method\LinkCreditCard;
use Plugin\SamplePayment\Service\Method\Convenience;
use Plugin\SamplePayment\Service\Method\CreditCard;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PluginManager extends AbstractPluginManager
{
public function enable(array $meta, ContainerInterface $container)
{
$this->createTokenPayment($container);
$this->createLinkPayment($container);
$this->createCvsPayment($container);
$this->createConfig($container);
$this->createPaymentStatuses($container);
$this->createCvsPaymentStatuses($container);
$this->createCvsTypes($container);
}
private function createTokenPayment(ContainerInterface $container)
{
$entityManager = $container->get('doctrine')->getManager();
$paymentRepository = $container->get(PaymentRepository::class);
$Payment = $paymentRepository->findOneBy([], ['sort_no' => 'DESC']);
$sortNo = $Payment ? $Payment->getSortNo() + 1 : 1;
$Payment = $paymentRepository->findOneBy(['method_class' => CreditCard::class]);
if ($Payment) {
return;
}
$Payment = new Payment();
$Payment->setCharge(0);
$Payment->setSortNo($sortNo);
$Payment->setVisible(true);
$Payment->setMethod('サンプル決済(トークン)'); // todo nameでいいんじゃないか
$Payment->setMethodClass(CreditCard::class);
$entityManager->persist($Payment);
$entityManager->flush($Payment);
}
private function createLinkPayment(ContainerInterface $container)
{
$entityManager = $container->get('doctrine')->getManager();
$paymentRepository = $container->get(PaymentRepository::class);
$Payment = $paymentRepository->findOneBy([], ['sort_no' => 'DESC']);
$sortNo = $Payment ? $Payment->getSortNo() + 1 : 1;
$Payment = $paymentRepository->findOneBy(['method_class' => LinkCreditCard::class]);
if ($Payment) {
return;
}
$Payment = new Payment();
$Payment->setCharge(0);
$Payment->setSortNo($sortNo);
$Payment->setVisible(true);
$Payment->setMethod('サンプル決済(リンク)'); // todo nameでいいんじゃないか
$Payment->setMethodClass(LinkCreditCard::class);
$entityManager->persist($Payment);
$entityManager->flush($Payment);
}
private function createCvsPayment(ContainerInterface $container)
{
$entityManager = $container->get('doctrine')->getManager();
$paymentRepository = $container->get(PaymentRepository::class);
$Payment = $paymentRepository->findOneBy([], ['sort_no' => 'DESC']);
$sortNo = $Payment ? $Payment->getSortNo() + 1 : 1;
$Payment = $paymentRepository->findOneBy(['method_class' => Cvs::class]);
if ($Payment) {
return;
}
$Payment = new Payment();
$Payment->setCharge(0);
$Payment->setSortNo($sortNo);
$Payment->setVisible(true);
$Payment->setMethod('コンビニ決済');
$Payment->setMethodClass(Convenience::class);
$entityManager->persist($Payment);
$entityManager->flush($Payment);
}
private function createConfig(ContainerInterface $container)
{
$entityManager = $container->get('doctrine.orm.entity_manager');
$Config = $entityManager->find(Config::class, 1);
if ($Config) {
return;
}
$Config = new Config();
$Config->setApiId('api-id');
$Config->setApiPassword('api-password');
$Config->setApiUrl('https://payment.example/com');
$entityManager->persist($Config);
$entityManager->flush($Config);
}
private function createMasterData(ContainerInterface $container, array $statuses, $class)
{
$entityManager = $container->get('doctrine')->getManager();
$i = 0;
foreach ($statuses as $id => $name) {
$PaymentStatus = $entityManager->find($class, $id);
if (!$PaymentStatus) {
$PaymentStatus = new $class;
}
$PaymentStatus->setId($id);
$PaymentStatus->setName($name);
$PaymentStatus->setSortNo($i++);
$entityManager->persist($PaymentStatus);
$entityManager->flush($PaymentStatus);
}
}
private function createPaymentStatuses(ContainerInterface $container)
{
$statuses = [
PaymentStatus::OUTSTANDING => '未決済',
PaymentStatus::ENABLED => '有効性チェック済',
PaymentStatus::PROVISIONAL_SALES => '仮売上',
PaymentStatus::ACTUAL_SALES => '実売上',
PaymentStatus::CANCEL => 'キャンセル',
];
$this->createMasterData($container, $statuses, PaymentStatus::class);
}
private function createCvsPaymentStatuses(ContainerInterface $container)
{
$statuses = [
CvsPaymentStatus::OUTSTANDING => '未決済',
CvsPaymentStatus::REQUEST => '要求成功',
CvsPaymentStatus::COMPLETE => '決済完了',
CvsPaymentStatus::FAILURE => '決済失敗',
CvsPaymentStatus::EXPIRED => '期限切れ',
];
$this->createMasterData($container, $statuses, CvsPaymentStatus::class);
}
private function createCvsTypes(ContainerInterface $container)
{
$statuses = [
CvsType::LAWSON => 'ローソン',
CvsType::MINISTOP => 'ミニストップ',
CvsType::SEVENELEVEN => 'セブンイレブン',
];
$this->createMasterData($container, $statuses, CvsType::class);
}
}