1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Iamolayemi\Paystack\Endpoints; |
4
|
|
|
|
5
|
|
|
class Transaction extends Endpoint |
6
|
|
|
{ |
7
|
|
|
protected const ENDPOINT = '/transaction'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Initialize a transaction from your backend |
11
|
|
|
* |
12
|
|
|
* @param array<string, mixed> $payload |
13
|
|
|
* |
14
|
|
|
* @link https://paystack.com/docs/api/#transaction-initialize |
15
|
|
|
*/ |
16
|
|
|
public function initialize(array $payload): self |
17
|
|
|
{ |
18
|
|
|
$this->post($this->url(self::ENDPOINT).'/initialize', $payload); |
19
|
|
|
|
20
|
|
|
return $this; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the authorization url from the 'initialize' endpoint |
25
|
|
|
*/ |
26
|
|
|
public function authorizationURL(): string |
27
|
|
|
{ |
28
|
|
|
return $this->response?->json('data.authorization_url') ?? ''; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Confirm the status of a transaction. |
33
|
|
|
* |
34
|
|
|
* @link https://paystack.com/docs/api/#transaction-verify |
35
|
|
|
*/ |
36
|
|
|
public function verify(string $reference): self |
37
|
|
|
{ |
38
|
|
|
$this->get($this->url(self::ENDPOINT).'/verify/'.$reference); |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the status of a single transaction. |
45
|
|
|
*/ |
46
|
|
|
public function status(string $reference = ''): string |
47
|
|
|
{ |
48
|
|
|
if (! empty($reference)) { |
49
|
|
|
return $this->verify($reference)->status(); |
50
|
|
|
} else { |
51
|
|
|
return $this->response?->json('data.status') ?? ''; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* List transactions carried out on your integration. |
57
|
|
|
* |
58
|
|
|
* @param array<string, mixed> $query |
59
|
|
|
* |
60
|
|
|
* @link https://paystack.com/docs/api/#transaction-list |
61
|
|
|
*/ |
62
|
|
|
public function list(array $query = []): self |
63
|
|
|
{ |
64
|
|
|
$this->get($this->url(self::ENDPOINT), $query); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get details of a transaction carried out on your integration. |
71
|
|
|
* |
72
|
|
|
* @link https://paystack.com/docs/api/#transaction-fetch |
73
|
|
|
*/ |
74
|
|
|
public function fetch(int $transaction_id): self |
75
|
|
|
{ |
76
|
|
|
$this->get($this->url(self::ENDPOINT).'/'.$transaction_id); |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Charge a customer user using his authorization code. |
83
|
|
|
* |
84
|
|
|
* @param array<string, mixed> $payload |
85
|
|
|
* |
86
|
|
|
* @link https://paystack.com/docs/api/#transaction-charge-authorization |
87
|
|
|
*/ |
88
|
|
|
public function chargeAuthorization(array $payload): self |
89
|
|
|
{ |
90
|
|
|
$this->post($this->url(self::ENDPOINT).'/charge_authorization', $payload); |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Check if the authorization code is valid. |
97
|
|
|
* |
98
|
|
|
* @param array<string, mixed> $payload |
99
|
|
|
* |
100
|
|
|
* @link https://paystack.com/docs/api/#transaction-check-authorization |
101
|
|
|
*/ |
102
|
|
|
public function checkAuthorization(array $payload): self |
103
|
|
|
{ |
104
|
|
|
$this->post($this->url(self::ENDPOINT).'/check_authorization', $payload); |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Fetch the timeline of a transaction |
111
|
|
|
* |
112
|
|
|
* @link https://paystack.com/docs/api/#transaction-view-timeline |
113
|
|
|
*/ |
114
|
|
|
public function timeline(string $reference): self |
115
|
|
|
{ |
116
|
|
|
$this->get($this->url(self::ENDPOINT).'/timeline/'.$reference); |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* View the timeline of a transaction. |
123
|
|
|
* |
124
|
|
|
* @param array<string, mixed> $query |
125
|
|
|
* |
126
|
|
|
* @link https://paystack.com/docs/api/#transaction-totals |
127
|
|
|
*/ |
128
|
|
|
public function totals(array $query = []): self |
129
|
|
|
{ |
130
|
|
|
$this->get($this->url(self::ENDPOINT).'/totals', $query); |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* List transactions carried out on your integration. |
137
|
|
|
* |
138
|
|
|
* @param array<string, mixed> $query |
139
|
|
|
* |
140
|
|
|
* @link https://paystack.com/docs/api/#transaction-export |
141
|
|
|
*/ |
142
|
|
|
public function export(array $query = []): self |
143
|
|
|
{ |
144
|
|
|
$this->get($this->url(self::ENDPOINT).'/export', $query); |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Receive part of a payment from a customer. |
151
|
|
|
* |
152
|
|
|
* @param array<string, mixed> $payload |
153
|
|
|
* |
154
|
|
|
* @link https://paystack.com/docs/api/#transaction-partial-debit |
155
|
|
|
*/ |
156
|
|
|
public function partialDebit(array $payload): self |
157
|
|
|
{ |
158
|
|
|
$this->post($this->url(self::ENDPOINT).'/partial_debit', $payload); |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|