|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\LaravelPayum\Action; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Payum\Core\Model\CreditCard; |
|
8
|
|
|
use Payum\Core\Action\ActionInterface; |
|
9
|
|
|
use Payum\Core\Request\ObtainCreditCard; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Payum\Core\Bridge\Symfony\Reply\HttpResponse; |
|
12
|
|
|
use Illuminate\Contracts\View\Factory as ViewFactory; |
|
13
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
|
14
|
|
|
|
|
15
|
|
|
class ObtainCreditCardAction implements ActionInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* $viewFactory. |
|
19
|
|
|
* |
|
20
|
|
|
* @var \Illuminate\Contracts\View\Factory |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $viewFactory; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* $httpRequest. |
|
26
|
|
|
* |
|
27
|
|
|
* @var \Illuminate\Http\Request |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $httpRequest; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* $templateName. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $templateName = 'payum::creditcard'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* __construct. |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Illuminate\Contracts\View\Factory $viewFactory |
|
42
|
|
|
* @param \Illuminate\Http\Request $request |
|
43
|
|
|
*/ |
|
44
|
3 |
|
public function __construct(ViewFactory $viewFactory, Request $request) |
|
45
|
|
|
{ |
|
46
|
3 |
|
$this->viewFactory = $viewFactory; |
|
47
|
3 |
|
$this->httpRequest = $request; |
|
48
|
3 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
3 |
|
public function execute($request) |
|
54
|
|
|
{ |
|
55
|
|
|
/** @var $request ObtainCreditCard */ |
|
56
|
3 |
|
if (false === $this->supports($request)) { |
|
57
|
1 |
|
throw RequestNotSupportedException::createActionNotSupported($this, $request); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
2 |
|
if ($this->httpRequest->isMethod('POST')) { |
|
61
|
1 |
|
$creditCard = new CreditCard(); |
|
62
|
1 |
|
$creditCard->setHolder($this->httpRequest->get('card_holder')); |
|
63
|
1 |
|
$creditCard->setNumber($this->httpRequest->get('card_number')); |
|
64
|
1 |
|
$creditCard->setSecurityCode($this->httpRequest->get('card_cvv')); |
|
65
|
1 |
|
$creditCard->setExpireAt(new DateTime($this->httpRequest->get('card_expire_at'))); |
|
66
|
|
|
|
|
67
|
1 |
|
$request->set($creditCard); |
|
68
|
|
|
|
|
69
|
1 |
|
return; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
$token = $request->getToken(); |
|
73
|
1 |
|
$form = $this->viewFactory->make($this->templateName, [ |
|
74
|
1 |
|
'model' => $request->getModel(), |
|
75
|
1 |
|
'firstModel' => $request->getFirstModel(), |
|
76
|
1 |
|
'actionUrl' => $token ? $token->getTargetUrl() : null, |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
1 |
|
throw new HttpResponse(new Response($form->render(), 200, [ |
|
80
|
1 |
|
'Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', |
|
81
|
|
|
'X-Status-Code' => 200, |
|
82
|
|
|
'Pragma' => 'no-cache', |
|
83
|
|
|
])); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
3 |
|
public function supports($request) |
|
90
|
|
|
{ |
|
91
|
3 |
|
return $request instanceof ObtainCreditCard; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|