Skip to content

Commit 2c688f4

Browse files
author
Okubanjo Oluwafunsho
committed
Modified setHttpResponse to send son encoded body parameters
1 parent 5e1d2ac commit 2c688f4

File tree

1 file changed

+12
-55
lines changed

1 file changed

+12
-55
lines changed

src/Paystack.php

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,14 @@ public function makePaymentRequest()
113113
}
114114

115115

116-
private function setHttpResponse($relativeUrl, $method, $body = []){
117-
116+
private function setHttpResponse($relativeUrl, $method, $body = [])
117+
{
118118
if(is_null($method)){
119-
120119
throw new isNullException("Empty method not allowed");
121-
122-
}else{
123-
124-
$this->response = $this->client->{strtolower($method)}($this->baseUrl . $relativeUrl, $body);
125-
126-
return $this;
127-
128120
}
129121

122+
$this->response = $this->client->{strtolower($method)}($this->baseUrl . $relativeUrl, ["body" => json_encode($body)]);
123+
return $this;
130124
}
131125

132126
/**
@@ -298,11 +292,8 @@ public function createPlan(){
298292
* @return array
299293
*/
300294
public function fetchPlan($plan_code){
301-
302295
$this->setRequestOptions();
303-
304296
return $this->setHttpResponse('/plan/' . $plan_code, 'GET', [])->getResponse();
305-
306297
}
307298

308299
/**
@@ -311,7 +302,6 @@ public function fetchPlan($plan_code){
311302
* @return array
312303
*/
313304
public function updatePlan($plan_code){
314-
315305
$data = [
316306
"name" => request()->name,
317307
"description" => request()->desc,
@@ -323,17 +313,14 @@ public function updatePlan($plan_code){
323313
];
324314

325315
$this->setRequestOptions();
326-
327316
return $this->setHttpResponse('/plan/' . $plan_code, 'PUT', $data)->getResponse();
328-
329317
}
330318

331319
/**
332320
* Create a customer
333321
* @return array
334322
*/
335323
public function createCustomer(){
336-
337324
$data = [
338325
"email" => request()->email,
339326
"first_name" => request()->fname,
@@ -344,22 +331,18 @@ public function createCustomer(){
344331
];
345332

346333
$this->setRequestOptions();
347-
348334
$this->setHttpResponse('/customer', 'POST', $data);
349-
350335
}
351336

352337
/**
353338
* Fetch a customer based on id or code
354339
* @param $customer_id
355340
* @return array
356341
*/
357-
public function fetchCustomer($customer_id){
358-
342+
public function fetchCustomer($customer_id)
343+
{
359344
$this->setRequestOptions();
360-
361345
return $this->setHttpResponse('/customer/'. $customer_id, 'GET', [])->getResponse();
362-
363346
}
364347

365348
/**
@@ -368,7 +351,6 @@ public function fetchCustomer($customer_id){
368351
* @return array
369352
*/
370353
public function updateCustomer($customer_id){
371-
372354
$data = [
373355
"email" => request()->email,
374356
"first_name" => request()->fname,
@@ -379,43 +361,36 @@ public function updateCustomer($customer_id){
379361
];
380362

381363
$this->setRequestOptions();
382-
383364
return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse();
384-
385365
}
386366

387367
/**
388368
* Export tranactions in .CSV
389369
* @return array
390370
*/
391371
public function exportTransactions(){
392-
393372
$data = [
394373
"from" => request()->from,
395374
"to" => request()->to,
396375
'settled' => request()->settled
397376
];
398377

399378
$this->setRequestOptions();
400-
401379
return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse();
402-
403380
}
404381

405382
/**
406383
* Create a subscription to a plan from a customer.
407384
* @return array
408385
*/
409386
public function createSubscription(){
410-
411387
$data = [
412388
"customer" => request()->customer, //Customer email or code
413389
"plan" => request()->plan,
414390
"authorization" => request()->authorization_code
415391
];
416392

417393
$this->setRequestOptions();
418-
419394
$this->setHttpResponse('/subscription', 'POST', $data);
420395
}
421396

@@ -424,89 +399,74 @@ public function createSubscription(){
424399
* @return array
425400
*/
426401
public function enableSubscription(){
427-
428402
$data = [
429403
"code" => request()->code,
430404
"token" => request()->token,
431405
];
432406

433407
$this->setRequestOptions();
434-
435408
return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse();
436-
437409
}
438410

439411
/**
440412
* Disable a subscription using the subscription code and token
441413
* @return array
442414
*/
443415
public function disableSubscription(){
444-
445416
$data = [
446417
"code" => request()->code,
447418
"token" => request()->token,
448419
];
449420

450421
$this->setRequestOptions();
451-
452422
return $this->setHttpResponse('/subscription/disable', 'POST', $data)->getResponse();
453-
454423
}
455424

456425
/**
457426
* Fetch details about a certain subscription
458427
* @param $subscription_id
459428
* @return array
460429
*/
461-
public function fetchSubscription($subscription_id){
462-
430+
public function fetchSubscription($subscription_id)
431+
{
463432
$this->setRequestOptions();
464-
465433
return $this->setHttpResponse('/subscription/'.$subscription_id, 'GET', [])->getResponse();
466-
467434
}
468435

469436
/**
470437
* Create pages you can share with users using the returned slug
471438
* @return array
472439
*/
473440
public function createPage(){
474-
475441
$data = [
476442
"name" => request()->name,
477443
"description" => request()->description,
478444
"amount" => request()->amount
479445
];
480446

481447
$this->setRequestOptions();
482-
483448
$this->setHttpResponse('/page', 'POST', $data);
484-
485449
}
486450

487451
/**
488452
* Fetches all the pages the merchant has
489453
* @return array
490454
*/
491-
public function getAllPages(){
492-
455+
public function getAllPages()
456+
{
493457
$this->setRequestOptions();
494-
495458
return $this->setHttpResponse('/page', 'GET', [])->getResponse();
496-
497459
}
498460

499461
/**
500462
* Fetch details about a certain page using its id or slug
501463
* @param $page_id
502464
* @return array
503465
*/
504-
public function fetchPage($page_id){
505-
466+
public function fetchPage($page_id)
467+
{
506468
$this->setRequestOptions();
507-
508469
return $this->setHttpResponse('/page/'.$page_id, 'GET', [])->getResponse();
509-
510470
}
511471

512472
/**
@@ -515,17 +475,14 @@ public function fetchPage($page_id){
515475
* @return array
516476
*/
517477
public function updatePage($page_id){
518-
519478
$data = [
520479
"name" => request()->name,
521480
"description" => request()->description,
522481
"amount" => request()->amount
523482
];
524483

525484
$this->setRequestOptions();
526-
527485
return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
528-
529486
}
530487

531488
}

0 commit comments

Comments
 (0)