-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefunds.php
More file actions
70 lines (56 loc) 路 1.51 KB
/
Copy pathRefunds.php
File metadata and controls
70 lines (56 loc) 路 1.51 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
<?php
namespace Leaf\Billing\Paystack;
/**
* PayStack Refunds
* ----
* API wrapper for PayStack Refunds API
*/
class Refunds
{
protected $client;
public function __construct($client)
{
$this->client = $client;
}
/**
* Create a new paystack refund
*/
public function create(array $params): Refund
{
$response = $this->client->post('/refund', [
'body' => json_encode($params)
]);
$refund = json_decode($response->getBody(), true);
$refund = $refund['data'];
$refund['transaction'] = (is_numeric($refund['transaction']))
? (new Transactions($this->client))->get($refund['transaction'])
: new Transaction($refund['transaction']);
return new Refund($refund);
}
/**
* Get all paystack refunds
*/
public function all(): array
{
$response = $this->client->get('/refund');
$refunds = json_decode($response->getBody(), true);
return array_map(function ($refund) {
return new Refund($refund);
}, $refunds['data']);
}
/**
* Get a paystack refund by id
*/
public function get($id): Refund
{
$response = $this->client->get("/refund/$id");
$refund = json_decode($response->getBody(), true);
return new Refund($refund['data']);
}
public function toArray()
{
return array_map(function ($transaction) {
return $transaction->toArray();
}, $this->all());
}
}