|
1
|
|
|
<?php namespace SOSTheBlack\Moip; |
|
2
|
|
|
|
|
3
|
|
|
use App; |
|
4
|
|
|
use Config; |
|
5
|
|
|
use Session; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Moip's API abstraction class |
|
10
|
|
|
* |
|
11
|
|
|
* Class to use for all abstraction of Moip's API |
|
12
|
|
|
* @package SOSTheBlack\Moip |
|
13
|
|
|
* @author Jean Cesar Garcia <[email protected]> <SOSTheBlack> |
|
14
|
|
|
* @version 1.* |
|
15
|
|
|
* @license <a href="http://www.opensource.org/licenses/bsd-license.php">BSD License</a> |
|
16
|
|
|
**/ |
|
17
|
|
|
class Moip extends MoipAbstract implements MoipInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Retorno da API |
|
21
|
|
|
* |
|
22
|
|
|
* @var object |
|
23
|
|
|
**/ |
|
24
|
|
|
private $response; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* postOrder |
|
28
|
|
|
* |
|
29
|
|
|
* @param string[] $order |
|
30
|
|
|
* @return string[] |
|
31
|
|
|
*/ |
|
32
|
|
|
public function postOrder(array $order) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setData($order); |
|
35
|
|
|
$this->initialize(); |
|
36
|
|
|
$this->getParcel(); |
|
37
|
|
|
$this->billetConf(); |
|
38
|
|
|
$this->getMessage(); |
|
39
|
|
|
$this->getComission(); |
|
40
|
|
|
$this->getPaymentWay(); |
|
41
|
|
|
$this->api->setReason($this->getReason()); |
|
42
|
|
|
$this->api->setUniqueID($this->getUniqueId()); |
|
|
|
|
|
|
43
|
|
|
$this->api->setPayer($this->getParams('payer')); |
|
44
|
|
|
$this->api->setValue($this->data['prices']['value']); |
|
45
|
|
|
$this->api->setAdds($this->getParams('prices', 'adds')); |
|
46
|
|
|
$this->api->setDeduct($this->getParams('prices','deduct')); |
|
47
|
|
|
$this->api->setReceiver($this->getParams('receiver', null, true)); |
|
48
|
|
|
$this->api->setReturnURL($this->getParams('url_return', null, true)); |
|
49
|
|
|
$this->api->setNotificationURL($this->getParams('url_notification', null, true)); |
|
50
|
|
|
$this->api->validate($this->getValidate()); |
|
51
|
|
|
return $this->response($this->api->send()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* response |
|
56
|
|
|
* |
|
57
|
|
|
* @param type $send |
|
58
|
|
|
* @return string[] |
|
59
|
|
|
*/ |
|
60
|
|
|
public function response($send = null) |
|
61
|
|
|
{ |
|
62
|
|
|
if ($send) { |
|
63
|
|
|
$answer = $this->api->getAnswer(); |
|
64
|
|
|
$this->responseValidation($send, $answer); |
|
65
|
|
|
$this->response = App::make('stdClass'); |
|
66
|
|
|
$this->response->getXML = $this->api->getXML(); |
|
67
|
|
|
$this->response->replyXML = $send->xml; |
|
68
|
|
|
$this->response->token = $answer->token; |
|
69
|
|
|
$this->response->url = $answer->payment_url; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
Session::put(Config::get('sostheblack::moip.array_session').'.response', (array) $this->response); |
|
73
|
|
|
return $this->response; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* parcel |
|
78
|
|
|
* |
|
79
|
|
|
* Generete parcel |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $parcel |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
public function parcel(array $parcel) |
|
85
|
|
|
{ |
|
86
|
|
|
$query = $this->api->queryParcel( |
|
87
|
|
|
$parcel['login'], |
|
88
|
|
|
$parcel['maxParcel'], |
|
89
|
|
|
$parcel['rate'], |
|
90
|
|
|
$parcel['simulatedValue'] |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
if ($query['response'] !== true) { |
|
94
|
|
|
throw new Exception('Error: Não foi possível gerar query'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $query['installment']; |
|
98
|
|
|
} |
|
99
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: