1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpMob package. |
5
|
|
|
* |
6
|
|
|
* (c) Ishmael Doss <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace PhpMob\Omise\Domain; |
15
|
|
|
|
16
|
|
|
use PhpMob\Omise\Model; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Ishmael Doss <[email protected]> |
20
|
|
|
* |
21
|
|
|
* @property string object |
22
|
|
|
* @property string id |
23
|
|
|
* @property bool livemode |
24
|
|
|
* @property string location |
25
|
|
|
* @property string defaultCard |
26
|
|
|
* @property string email |
27
|
|
|
* @property string description |
28
|
|
|
* @property string metadata |
29
|
|
|
* @property string created |
30
|
|
|
* @property Pagination cards |
31
|
|
|
* @property bool deleted |
32
|
|
|
* @property string cardToken |
33
|
|
|
*/ |
34
|
|
|
class Customer extends Model |
35
|
|
|
{ |
36
|
|
|
const EVENT_CREATE = 'charge.create'; |
37
|
|
|
const EVENT_UPDATE = 'charge.update'; |
38
|
|
|
const EVENT_UPDATE_CARD = 'charge.update.card'; |
39
|
|
|
const EVENT_DESTROY = 'charge.destroy'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $cardToken; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
6 |
|
public function getCreateData() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
6 |
|
'email' => $this->email, |
53
|
6 |
|
'description' => $this->description, |
54
|
6 |
|
'metadata' => $this->metadata, |
55
|
6 |
|
'card' => $this->__get('cardToken'), |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
2 |
|
public function getUpdateData() |
63
|
|
|
{ |
64
|
2 |
|
return $this->getCreateData(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array|Card[] |
69
|
|
|
*/ |
70
|
|
|
public function getCards() |
71
|
|
|
{ |
72
|
|
|
if (count($this->cards)) { |
73
|
|
|
return $this->cards->data; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return []; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param $id |
81
|
|
|
* |
82
|
|
|
* @return Card|null |
83
|
|
|
*/ |
84
|
|
|
public function findCard($id) |
85
|
|
|
{ |
86
|
|
|
$cards = array_filter( |
87
|
|
|
$this->getCards(), |
88
|
|
|
function (Card $card) use ($id) { |
89
|
|
|
return $card->id === $id; |
90
|
|
|
} |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
if (empty($cards)) { |
94
|
|
|
return null; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $cards[0]; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|