Skip to content

Commit 1f09529

Browse files
authored
created Charge APIs (#30)
1 parent efb8217 commit 1f09529

File tree

4 files changed

+131
-1
lines changed

4 files changed

+131
-1
lines changed

readme.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,25 @@ ControlPanel::fetchPaymentSessionTimeout($params);
329329
ControlPanel::updatePaymentSessionTimeout($params);
330330
```
331331

332-
### Charge **TODO**
332+
### Charge
333+
```php
334+
use Myckhel\Paystack\Support\Charge;
335+
336+
Charge::create($params);
337+
338+
Charge::submitPin($params);
339+
340+
Charge::submitOtp($params);
341+
342+
Charge::submitPhone($params);
343+
344+
Charge::submitBirthday($params);
345+
346+
Charge::submitAddress($params);
347+
348+
Charge::checkPending($reference, $params);
349+
```
350+
333351
### Disputes **TODO**
334352
### Refunds **TODO**
335353
### Verification **TODO**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Myckhel\Paystack\Http\Controllers;
4+
5+
use Myckhel\Paystack\Support\Charge;
6+
7+
class ChargeController extends Controller
8+
{
9+
function __call($method, $args)
10+
{
11+
return $args
12+
? Charge::$method($args[0], request()->all())
13+
: Charge::$method(request()->all());
14+
}
15+
}

src/Support/Charge.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Myckhel\Paystack\Support;
4+
5+
use Myckhel\Paystack\Traits\Request;
6+
7+
/**
8+
* The Charge API allows you to configure payment channel of your choice when initiating a payment.
9+
*
10+
*/
11+
class Charge
12+
{
13+
use Request;
14+
15+
/**
16+
* Initiate a payment by integrating the payment channel of your choice.
17+
*
18+
* @return \Illuminate\Http\Response
19+
*/
20+
static function create($params = [])
21+
{
22+
return self::post("/charge", $params);
23+
}
24+
25+
/**
26+
* Submit PIN to continue a charge
27+
*
28+
* @return \Illuminate\Http\Response
29+
*/
30+
static function submitPin($params = [])
31+
{
32+
return self::post("/charge/submit_pin", $params);
33+
}
34+
35+
/**
36+
* Submit OTP to complete a charge
37+
*
38+
* @return \Illuminate\Http\Response
39+
*/
40+
static function submitOtp($params = [])
41+
{
42+
return self::post("/charge/submit_otp", $params);
43+
}
44+
45+
/**
46+
* Submit Phone when requested
47+
*
48+
* @return \Illuminate\Http\Response
49+
*/
50+
static function submitPhone($params = [])
51+
{
52+
return self::post("/charge/submit_phone", $params);
53+
}
54+
55+
/**
56+
* Submit Birthday when requested
57+
*
58+
* @return \Illuminate\Http\Response
59+
*/
60+
static function submitBirthday($params = [])
61+
{
62+
return self::post("/charge/submit_birthday", $params);
63+
}
64+
65+
/**
66+
* Submit address to continue a charge
67+
*
68+
* @return \Illuminate\Http\Response
69+
*/
70+
static function submitAddress($params = [])
71+
{
72+
return self::post("/charge/submit_address", $params);
73+
}
74+
75+
/**
76+
* When you get "pending" as a charge status or if there was an exception
77+
* when calling any of the /charge endpoints, wait 10 seconds or more,
78+
* then make a check to see if its status has changed.
79+
* Don't call too early as you may get a lot more pending than you should.
80+
*
81+
* @return \Illuminate\Http\Response
82+
*/
83+
static function checkPending($reference, $params = [])
84+
{
85+
return self::get("/charge/$reference", $params);
86+
}
87+
}

src/routes.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Illuminate\Support\Facades\Route;
44
use Myckhel\Paystack\Http\Controllers\ApplePayController;
55
use Myckhel\Paystack\Http\Controllers\BulkChargeController;
6+
use Myckhel\Paystack\Http\Controllers\ChargeController;
67
use Myckhel\Paystack\Http\Controllers\ControlPanelController;
78
use Myckhel\Paystack\Http\Controllers\CustomerController;
89
use Myckhel\Paystack\Http\Controllers\DedicatedVirtualAccountController;
@@ -140,6 +141,14 @@
140141
// control panel
141142
'get,integration/payment_session_timeout' => 'controlpanel,fetchPaymentSessionTimeout',
142143
'put,integration/payment_session_timeout' => 'controlpanel,updatePaymentSessionTimeout',
144+
// charges
145+
'post,charge' => 'charge,create',
146+
'post,charge/submit_pin' => 'charge,submitPin',
147+
'post,charge/submit_otp' => 'charge,submitOtp',
148+
'post,charge/submit_phone' => 'charge,submitPhone',
149+
'post,charge/submit_birthday' => 'charge,submitBirthday',
150+
'post,charge/submit_address' => 'charge,submitAddress',
151+
'get,charge/{reference}' => 'charge,checkPending',
143152
];
144153

145154
$controls = [
@@ -161,6 +170,7 @@
161170
'control' => TransferControlController::class,
162171
'bulkcharge' => BulkChargeController::class,
163172
'controlpanel' => ControlPanelController::class,
173+
'charge' => ChargeController::class,
164174
];
165175

166176
collect($routes)->map(function ($route, $index) use ($controls) {

0 commit comments

Comments
 (0)