1
|
|
|
<?php namespace SOSTheBlack\Moip\Controllers; |
2
|
|
|
|
3
|
|
|
use View; |
4
|
|
|
use Moip; |
5
|
|
|
use Input; |
6
|
|
|
use Config; |
7
|
|
|
use Session; |
8
|
|
|
use BaseController; |
9
|
|
|
|
10
|
|
|
class MoipController extends BaseController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* data of configuration of the MoIP |
14
|
|
|
* |
15
|
|
|
* @var [] |
16
|
|
|
**/ |
17
|
|
|
|
18
|
|
|
private $moip; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* array |
22
|
|
|
* |
23
|
|
|
* @var [] |
24
|
|
|
**/ |
25
|
|
|
|
26
|
|
|
private $data = [ |
27
|
|
|
"Forma" => "", |
28
|
|
|
"Instituicao" => "", |
29
|
|
|
"Parcelas" => "", |
30
|
|
|
"CartaoCredito" => [ |
31
|
|
|
"Numero" => "", |
32
|
|
|
"Expiracao" => "", |
33
|
|
|
"Cofre" => "", |
34
|
|
|
"CodigoSeguranca"=> "", |
35
|
|
|
"Portador" => [ |
36
|
|
|
"Nome" => "", |
37
|
|
|
"DataNascimento"=> "", |
38
|
|
|
"Telefone" => "", |
39
|
|
|
"Identidade" => "" |
40
|
|
|
] |
41
|
|
|
] |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* callback do js de pagamento do moip |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
**/ |
49
|
|
|
protected $response; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* response |
53
|
|
|
* Recebe o callback do js de pagamento do moip |
54
|
|
|
* e grava os dados em uma session |
55
|
|
|
* |
56
|
|
|
* @return type |
57
|
|
|
*/ |
58
|
|
|
public function response() |
59
|
|
|
{ |
60
|
|
|
$this->response = Input::all(); |
61
|
|
|
Session::put(Config::get('sostheblack::moip.array_session').'.callback', $this->response['moip']); |
62
|
|
|
return $this->response; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* initialize |
67
|
|
|
* |
68
|
|
|
* @param string|null $token |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
private function initialize(array $data, $token) |
72
|
|
|
{ |
73
|
|
|
$this->moip = Moip::firstOrFail(); |
74
|
|
|
$this->data = array_replace_recursive($this->data, $data); |
75
|
|
|
if (empty($this->data['CartaoCredito']['Cofre'])) { |
76
|
|
|
unset($this->data['CartaoCredito']['Cofre']); |
77
|
|
|
} |
78
|
|
|
$this->data['token'] = $this->token($token); |
79
|
|
|
$this->data['environment'] = $this->environment(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* token |
84
|
|
|
* Define o token que será pago |
85
|
|
|
* |
86
|
|
|
* @param string $token |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
private function token($token) |
90
|
|
|
{ |
91
|
|
|
return $token ? $token : Session::get('pagamento.response.token'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* transparent |
96
|
|
|
* |
97
|
|
|
* @param array $data |
98
|
|
|
* @param string $token |
99
|
|
|
* @return Illuminate\View\Factory |
100
|
|
|
*/ |
101
|
|
|
public function transparent(array $data, $token = null) |
102
|
|
|
{ |
103
|
|
|
$this->initialize($data, $token); |
104
|
|
|
return View::make('sostheblack::moip')->withMoip($this->data); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* environment |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
private function environment() |
113
|
|
|
{ |
114
|
|
|
$environment = ""; |
|
|
|
|
115
|
|
|
|
116
|
|
|
if ((boolean) $this->moip->environment === true) { |
117
|
|
|
$environment = "https://www.moip.com.br/transparente/MoipWidget-v2.js"; |
118
|
|
|
} else { |
119
|
|
|
$environment = "https://desenvolvedor.moip.com.br/sandbox/transparente/MoipWidget-v2.js"; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $environment; |
123
|
|
|
} |
124
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.