-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubaccounts.php
More file actions
79 lines (63 loc) 路 1.72 KB
/
Copy pathSubaccounts.php
File metadata and controls
79 lines (63 loc) 路 1.72 KB
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
72
73
74
75
76
77
78
79
<?php
namespace Leaf\Billing\Paystack;
/**
* PayStack Subaccounts
* ----
* API wrapper for PayStack Subaccounts API
*/
class Subaccounts
{
protected $client;
public function __construct($client)
{
$this->client = $client;
}
/**
* Create a new paystack subaccount
*/
public function create(array $params): Subaccount
{
$response = $this->client->post('/subaccount', [
'body' => json_encode($params)
]);
$subaccount = json_decode($response->getBody(), true);
return new Subaccount($subaccount['data']);
}
/**
* Get all paystack subaccounts
*/
public function all(): array
{
$response = $this->client->get('/subaccount');
$subaccounts = json_decode($response->getBody(), true);
return array_map(function ($subaccount) {
return new Subaccount($subaccount);
}, $subaccounts['data']);
}
/**
* Get a paystack subaccount by id
*/
public function get($id): Subaccount
{
$response = $this->client->get("/subaccount/$id");
$subaccount = json_decode($response->getBody(), true);
return new Subaccount($subaccount['data']);
}
/**
* Update a paystack subaccount
*/
public function update($id, array $params): Subaccount
{
$response = $this->client->put("/subaccount/$id", [
'body' => json_encode($params)
]);
$subaccount = json_decode($response->getBody(), true);
return new Subaccount($subaccount['data']);
}
public function toArray()
{
return array_map(function ($subaccount) {
return $subaccount->toArray();
}, $this->all());
}
}