-
Notifications
You must be signed in to change notification settings - Fork 14
/
NotificationTransaction.php
71 lines (65 loc) · 1.63 KB
/
NotificationTransaction.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
<?php
namespace Sounoob\pagseguro;
use Sounoob\pagseguro\core\PagSeguro;
/**
* Class NotificationTransaction
* @package Sounoob\pagseguro
*/
class NotificationTransaction extends PagSeguro
{
/**
* @var string
*/
private $code = '';
/**
* @var array
*/
private $seguiment = array(
'v2' => 'v2/transactions/notifications/',
'v3' => 'v3/transactions/notifications/',
);
/**
* @var string
*/
private $version = 'v3';
/**
* @var bool|\SimpleXMLElement|\stdClass
*/
public $result = false;
/**
* NotificationTransaction constructor.
* @param string $code
* @param string $version
* @throws \Exception
*/
public function __construct($code, $version = 'v3')
{
parent::__construct();
$this->code = $code;
if (strlen($this->code) !== 36 && strlen($this->code) !== 39) {
//PagSeguro error code 13001
throw new \InvalidArgumentException('invalid notification code value: ' . $this->code);
}
$this->setVersion($version);
$this->result = $this->send();
}
/**
* @param string $version
*/
public function setVersion($version)
{
if (!isset($this->seguiment[$version])) {
throw new \InvalidArgumentException('invalid API version: ' . $this->version);
}
$this->version = $version;
}
/**
* @return \SimpleXMLElement|\stdClass
* @throws \Exception
*/
public function send()
{
$this->url = $this->seguiment[$this->version] . $this->code;
return parent::send();
}
}