-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginManager.php
87 lines (76 loc) · 2.88 KB
/
PluginManager.php
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
<?php
/**
* This file is part of paypay4
*
* Copyright(c) Akira Kurozumi <info@a-zumi.net>
*
* https://a-zumi.net
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\paypay4;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Entity\Payment;
use Eccube\Plugin\AbstractPluginManager;
use Plugin\paypay4\Entity\PaymentStatus;
use Plugin\paypay4\Service\Method\PayPay;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PluginManager extends AbstractPluginManager
{
public function enable(array $meta, ContainerInterface $container)
{
$this->createPayment($container, 'PayPay', PayPay::class);
$this->createPaymentStatuses($container);
}
private function createPayment(ContainerInterface $container, $method, $methodClass)
{
/** @var EntityManagerInterface $entityManager */
$entityManager = $container->get('doctrine.orm.entity_manager');
$paymentRepository = $entityManager->getRepository(Payment::class);
$Payment = $paymentRepository->findOneBy([], ['sort_no' => 'DESC']);
$sortNo = $Payment ? $Payment->getSortNo() + 1 : 1;
$Payment = $paymentRepository->findOneBy(['method_class' => $methodClass]);
if ($Payment) {
return;
}
$Payment = new Payment();
$Payment->setCharge(0);
$Payment->setSortNo($sortNo);
$Payment->setVisible(true);
$Payment->setMethod($method);
$Payment->setMethodClass($methodClass);
$entityManager->persist($Payment);
$entityManager->flush();
}
private function createMasterData(ContainerInterface $container, array $statuses, $class)
{
/** @var EntityManagerInterface $entityManager */
$entityManager = $container->get('doctrine.orm.entity_manager');
$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();
}
private function createPaymentStatuses(ContainerInterface $container)
{
$statuses = [
PaymentStatus::CREATED => 'QRコード生成',
PaymentStatus::AUTHORIZED => '仮売上',
PaymentStatus::COMPLETED => '実売上',
PaymentStatus::EXPIRED => '有効期限超過',
PaymentStatus::CANCELED => 'キャンセル',
PaymentStatus::REFUNDED => '返金',
PaymentStatus::FAILED => '決済失敗'
];
$this->createMasterData($container, $statuses, PaymentStatus::class);
}
}