|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Amelia\Monzo\Api; |
|
4
|
|
|
|
|
5
|
|
|
use Amelia\Monzo\Models\Pot; |
|
6
|
|
|
use Ramsey\Uuid\Uuid; |
|
7
|
|
|
|
|
8
|
|
|
trait Pots |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Get a user's pots. |
|
12
|
|
|
* |
|
13
|
|
|
* @return \Amelia\Monzo\Models\Pot[]|\Illuminate\Support\Collection |
|
14
|
|
|
*/ |
|
15
|
|
|
public function pots() |
|
16
|
|
|
{ |
|
17
|
|
|
$results = $this->call('GET', 'pots', [], [], 'pots'); |
|
18
|
|
|
|
|
19
|
|
|
return collect($results)->map(function ($item) { |
|
20
|
|
|
return new Pot($item, $this); |
|
21
|
|
|
}); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get a pot by ID. |
|
26
|
|
|
* |
|
27
|
|
|
* @param string $id |
|
28
|
|
|
* @return \Amelia\Monzo\Models\Pot |
|
29
|
|
|
*/ |
|
30
|
|
|
public function pot(string $id) |
|
31
|
|
|
{ |
|
32
|
|
|
$results = $this->call('GET', "pots/{$id}"); |
|
33
|
|
|
|
|
34
|
|
|
return new Pot($results, $this); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Fund a pot. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $id |
|
41
|
|
|
* @param int $amount |
|
42
|
|
|
* @param null|string $account |
|
43
|
|
|
* @return \Amelia\Monzo\Models\Pot |
|
44
|
|
|
*/ |
|
45
|
|
|
public function addToPot(string $id, int $amount, ?string $account = null) |
|
46
|
|
|
{ |
|
47
|
|
|
$results = $this->call('PUT', "pots/{$id}/deposit", [], [ |
|
48
|
|
|
'amount' => $amount, |
|
49
|
|
|
'source_account_id' => $account ?? $this->getAccountId(), |
|
50
|
|
|
'dedupe_id' => (string) Uuid::uuid4(), |
|
51
|
|
|
]); |
|
52
|
|
|
|
|
53
|
|
|
return new Pot($results, $this); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Withdraw a given amount from a pot. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $id |
|
60
|
|
|
* @param int $amount |
|
61
|
|
|
* @param null|string $account |
|
62
|
|
|
* @return \Amelia\Monzo\Models\Pot |
|
63
|
|
|
*/ |
|
64
|
|
|
public function withdrawFromPot(string $id, int $amount, ?string $account = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$results = $this->call('PUT', "pots/{$id}/withdraw", [], [ |
|
67
|
|
|
'amount' => $amount, |
|
68
|
|
|
'destination_account_id' => $account ?? $this->getAccountId(), |
|
69
|
|
|
'dedupe_id' => (string) Uuid::uuid4(), |
|
70
|
|
|
]); |
|
71
|
|
|
|
|
72
|
|
|
return new Pot($results, $this); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Update a pot (e.g. the style). |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $pot |
|
79
|
|
|
* @param array $attributes |
|
80
|
|
|
* @return \Amelia\Monzo\Models\Pot |
|
81
|
|
|
*/ |
|
82
|
|
|
public function updatePot(string $pot, array $attributes) |
|
83
|
|
|
{ |
|
84
|
|
|
$results = $this->call('PATCH', "pots/{$pot}", [], $attributes); |
|
85
|
|
|
|
|
86
|
|
|
return new Pot($results, $this); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|