-
Notifications
You must be signed in to change notification settings - Fork 11
/
CreditCard.php
163 lines (137 loc) · 3.86 KB
/
CreditCard.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
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
<?php
/**
* This file is part of Stripe4
*
* 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\Stripe4\Service\Method;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Order;
use Eccube\Repository\Master\OrderStatusRepository;
use Eccube\Service\Payment\PaymentDispatcher;
use Eccube\Service\Payment\PaymentMethodInterface;
use Eccube\Service\Payment\PaymentResult;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Plugin\Stripe4\Entity\PaymentStatus;
use Plugin\Stripe4\Repository\PaymentStatusRepository;
use Stripe\Stripe;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
class CreditCard implements PaymentMethodInterface
{
/**
* @var Order
*/
protected $Order;
/**
* @var FormInterface
*/
protected $form;
/**
* @var OrderStatusRepository
*/
protected $orderStatusRepository;
/**
* @var PaymentStatusRepository
*/
protected $paymentStatusRepository;
/**
* @var PurchaseFlow
*/
protected $purchaseFlow;
/**
* @var EccubeConfig
*/
protected $eccubeConfig;
/**
* @var ParameterBag
*/
private $parameterBag;
public function __construct(
OrderStatusRepository $orderStatusRepository,
PaymentStatusRepository $paymentStatusRepository,
PurchaseFlow $shoppingPurchaseFlow,
EccubeConfig $eccubeConfig,
ParameterBag $parameterBag
)
{
$this->eccubeConfig = $eccubeConfig;
Stripe::setApiKey($this->eccubeConfig['stripe_secret_key']);
$this->orderStatusRepository = $orderStatusRepository;
$this->paymentStatusRepository = $paymentStatusRepository;
$this->purchaseFlow = $shoppingPurchaseFlow;
$this->parameterBag = $parameterBag;
}
/**
* @inheritDoc
*
* 注文確認画面遷移時に呼び出される
*
* クレジットカードの有効性チェックを行う
*/
public function verify()
{
// 決済ステータスを有効性チェック済みへ変更
$PaymentStatus = $this->paymentStatusRepository->find(PaymentStatus::ENABLED);
$this->Order->setStripePaymentStatus($PaymentStatus);
$result = new PaymentResult();
$result->setSuccess(true);
return $result;
}
/**
* @inheritDoc
*
* 注文時に呼び出される。
*
* クレジットカードの決済処理を行う。
*/
public function checkout()
{
$result = new PaymentResult();
$result->setSuccess(true);
return $result;
}
/**
* @inheritDoc
*
* 注文時に呼び出される
*
* 注文ステータス、決済ステータスを更新する。
*/
public function apply()
{
// 受注ステーテスを決済処理中へ変更
$OrderStatus = $this->orderStatusRepository->find(OrderStatus::PENDING);
$this->Order->setOrderStatus($OrderStatus);
$this->purchaseFlow->prepare($this->Order, new PurchaseContext());
$this->parameterBag->set('stripe.Order', $this->Order);
// 支払い処理へリダイレクト
$dispatcher = new PaymentDispatcher();
$dispatcher->setRoute('shopping_stripe_payment');
$dispatcher->setForward(true);
return $dispatcher;
}
/**
* @inheritDoc
*/
public function setFormType(FormInterface $form)
{
$this->form = $form;
return $this;
}
/**
* @inheritDoc
*/
public function setOrder(Order $Order)
{
$this->Order = $Order;
return $this;
}
}