Completed
Push — master ( 79ba6e...7f2508 )
by Rigel Kent
01:04
created

Webhook::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Luigel\Paymongo\Models;
4
5
use Luigel\Paymongo\Paymongo;
6
7
class Webhook
8
{
9
    public const SOURCE_CHARGEABLE = 'source.chargeable';
10
11
    protected $id;
12
    protected $type;
13
    protected $secret_key;
14
    protected $status;
15
    protected $url;
16
    protected $events;
17
    protected $updated_at;
18
    protected $created_at;
19
    protected $data;
20
21
    public function setData($data)
22
    {
23
        if (is_array($data) && isset($data['id']))
24
        {
25
            return $this->setSingleData($data);
26
        }
27
        $webhooks = collect();
28
29
        foreach ($data as $item)
30
        {
31
            $webhooks->push($this->setSingleData($item));
32
        }
33
        return $webhooks;
34
    }
35
36
    protected function setSingleData($data)
37
    {
38
        $this->id = $data['id'];
39
        $this->type = $data['type'];
40
        $this->secret_key = $data['attributes']['secret_key'];
41
        $this->status = $data['attributes']['status'];
42
        $this->url = $data['attributes']['url'];
43
        $this->updated_at = $data['attributes']['updated_at'];
44
        $this->created_at = $data['attributes']['created_at'];
45
46
        $events = collect();
47
        foreach ($data['attributes']['events'] as $event)
48
        {
49
            $events->push($event);
50
        }
51
52
        $this->events = $events;
53
54
        $this->data = [
55
            'id' => $this->id,
56
            'type' => $this->type,
57
            'secret_key' => $this->secret_key,
58
            'status' => $this->status,
59
            'url' => $this->url,
60
            'events' => $this->events,
61
            'created_at' => $this->created_at,
62
            'updated_at' => $this->updated_at
63
        ];
64
65
        return $this;
66
    }
67
68
    public function getId()
69
    {
70
        return $this->id;
71
    }
72
73
    public function getType()
74
    {
75
        return $this->type;
76
    }
77
78
    public function getSecretKey()
79
    {
80
        return $this->secret_key;
81
    }
82
83
    public function getStatus()
84
    {
85
        return $this->status;
86
    }
87
88
    public function getUrl()
89
    {
90
        return $this->url;
91
    }
92
93
    public function getEvents($i = null)
94
    {
95
        if (is_int($i) && $i !== null)
96
        {
97
            return $this->events[$i];
98
        }
99
        
100
        return $this->events;
101
    }
102
103
    public function getCreatedAt()
104
    {
105
        return $this->created_at;
106
    }
107
108
    public function getUpdatedAt()
109
    {
110
        return $this->updated_at;
111
    }
112
113
    public function enable()
114
    {
115
        return (new Paymongo)->webhook()->enable($this);
116
    }
117
118
    public function disable()
119
    {
120
        return (new Paymongo)->webhook()->disable($this);
121
    }
122
123
    public function update($payload)
124
    {
125
        return (new Paymongo)->webhook()->update($this, $payload);
126
    }
127
}
128