1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digikraaft\Flutterwave; |
4
|
|
|
|
5
|
|
|
class Charge extends ApiResource |
6
|
|
|
{ |
7
|
|
|
const OBJECT_NAME = 'charges'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Flutterwave Documentation Reference. |
11
|
|
|
* |
12
|
|
|
* @link https://developer.flutterwave.com/reference#charge-a-card |
13
|
|
|
*/ |
14
|
|
|
use ApiOperations\Create; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param array $params |
18
|
|
|
* |
19
|
|
|
* @link https://developer.flutterwave.com/reference#validate-a-charge |
20
|
|
|
* |
21
|
|
|
* @return array|object |
22
|
|
|
*/ |
23
|
|
|
public static function validate($params) |
24
|
|
|
{ |
25
|
|
|
self::validateParams($params, true); |
26
|
|
|
$url = urlencode('validate-charge'); |
27
|
|
|
|
28
|
|
|
return static::staticRequest('POST', $url, $params); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $params |
33
|
|
|
* |
34
|
|
|
* @link https://developer.flutterwave.com/reference#charge-with-token-1 |
35
|
|
|
* |
36
|
|
|
* @return array|object |
37
|
|
|
*/ |
38
|
|
|
public static function withToken($params) |
39
|
|
|
{ |
40
|
|
|
self::validateParams($params, true); |
41
|
|
|
$url = urlencode('tokenized-charges'); |
42
|
|
|
|
43
|
|
|
return static::staticRequest('POST', $url, $params); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $params |
48
|
|
|
* |
49
|
|
|
* @link https://developer.flutterwave.com/reference#create-bulk-tokenized-charge |
50
|
|
|
* |
51
|
|
|
* @return array|object |
52
|
|
|
*/ |
53
|
|
|
public static function withMultipleTokens($params) |
54
|
|
|
{ |
55
|
|
|
self::validateParams($params, true); |
56
|
|
|
$url = urlencode('bulk-tokenized-charges'); |
57
|
|
|
|
58
|
|
|
return static::staticRequest('POST', $url, $params); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $bulkId |
63
|
|
|
* @return array|object |
64
|
|
|
* |
65
|
|
|
* @link https://developer.flutterwave.com/reference#get-bulk-tokenized-charges |
66
|
|
|
*/ |
67
|
|
|
public static function fetchBulkStatus(string $bulkId) |
68
|
|
|
{ |
69
|
|
|
$url = urlencode("bulk-tokenized-charges/{$bulkId}"); |
70
|
|
|
|
71
|
|
|
return static::staticRequest('GET', $url); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $bulkId |
76
|
|
|
* @return array|object |
77
|
|
|
* |
78
|
|
|
* @link https://developer.flutterwave.com/reference#get-bulk-tokenized-charges-transactions |
79
|
|
|
*/ |
80
|
|
|
public static function fetchBulkTransactions(string $bulkId) |
81
|
|
|
{ |
82
|
|
|
$url = urlencode("bulk-tokenized-charges/{$bulkId}/transactions"); |
83
|
|
|
|
84
|
|
|
return static::staticRequest('GET', $url); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $token |
89
|
|
|
* @param array $params |
90
|
|
|
* |
91
|
|
|
* @return array|object |
92
|
|
|
* @link https://developer.flutterwave.com/reference#update-token-details |
93
|
|
|
*/ |
94
|
|
|
public static function updateToken(string $token, array $params) |
95
|
|
|
{ |
96
|
|
|
self::validateParams($params, true); |
97
|
|
|
$url = urlencode("tokens/{$token}"); |
98
|
|
|
|
99
|
|
|
return static::staticRequest('PUT', $url, $params); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $flw_ref |
104
|
|
|
* @param array $params |
105
|
|
|
* |
106
|
|
|
* @return array|object |
107
|
|
|
* @link https://developer.flutterwave.com/reference#capture-preauth-charge |
108
|
|
|
*/ |
109
|
|
|
public static function capturePreAuthorization(string $flw_ref, array $params) |
110
|
|
|
{ |
111
|
|
|
self::validateParams($params, true); |
112
|
|
|
$url = static::endPointUrl("{$flw_ref}/capture"); |
113
|
|
|
|
114
|
|
|
return static::staticRequest('PUT', $url, $params); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $flw_ref |
119
|
|
|
* @param array $params |
120
|
|
|
* |
121
|
|
|
* @return array|object |
122
|
|
|
* @link https://developer.flutterwave.com/reference#void-preauth-charge |
123
|
|
|
*/ |
124
|
|
|
public static function voidPreAuthorization(string $flw_ref, array $params) |
125
|
|
|
{ |
126
|
|
|
self::validateParams($params); |
127
|
|
|
$url = static::endPointUrl("{$flw_ref}/void"); |
128
|
|
|
|
129
|
|
|
return static::staticRequest('POST', $url, $params); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $flw_ref |
134
|
|
|
* @param array $params |
135
|
|
|
* |
136
|
|
|
* @return array|object |
137
|
|
|
* @link https://developer.flutterwave.com/reference#refund-preauth-charge |
138
|
|
|
*/ |
139
|
|
|
public static function refundPreAuthorization(string $flw_ref, array $params) |
140
|
|
|
{ |
141
|
|
|
self::validateParams($params, true); |
142
|
|
|
$url = static::endPointUrl("{$flw_ref}/refund"); |
143
|
|
|
|
144
|
|
|
return static::staticRequest('POST', $url, $params); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|