Skip to content

Commit 2aebd96

Browse files
author
Prosper Otemuyiwa
authored
Merge pull request #23 from sayopaul/master
Added methods to handle Split payments
2 parents 22ee162 + 37f083c commit 2aebd96

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,32 @@ Paystack::getAllTransactions();
214214
* @returns string
215215
*/
216216
Paystack::genTranxRef();
217+
218+
/**
219+
* This method creates a subaccount to be used for split payments
220+
* @return array
221+
*/
222+
Paystack::createSubAccount();
223+
224+
225+
/**
226+
* This method fetches the details of a subaccount
227+
* @return array
228+
*/
229+
Paystack::fetchSubAccount();
230+
231+
232+
/**
233+
* This method lists the subaccounts associated with your paystack account
234+
* @return array
235+
*/
236+
Paystack::listSubAccounts();
237+
238+
/**
239+
* This method Updates a subaccount to be used for split payments
240+
* @return array
241+
*/
242+
Paystack::updateSubAccount();
217243
```
218244

219245
A sample form will look like so:

src/Paystack.php

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ private function setRequestOptions()
100100
);
101101
}
102102

103-
/**
103+
104+
/**
105+
104106
* Initiate a payment request to Paystack
105107
* Included the option to pass the payload to this method for situations
106108
* when the payload is built on the fly (not passed to the controller from a view)
107109
* @return Paystack
108110
*/
111+
109112
public function makePaymentRequest( $data = null)
110113
{
111114
if ( $data == null ) {
@@ -338,6 +341,7 @@ public function createPlan()
338341
$this->setRequestOptions();
339342

340343
$this->setHttpResponse("/plan", 'POST', $data);
344+
341345
}
342346

343347
/**
@@ -583,4 +587,78 @@ public function updatePage($page_id)
583587
$this->setRequestOptions();
584588
return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
585589
}
590+
591+
/**
592+
* Creates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
593+
*
594+
* @return array
595+
*/
596+
597+
public function createSubAccount(){
598+
$data = [
599+
"business_name" => request()->business_name,
600+
"settlement_bank" => request()->settlement_bank,
601+
"account_number" => request()->account_number,
602+
"percentage_charge" => request()->percentage_charge,
603+
"primary_contact_email" => request()->primary_contact_email,
604+
"primary_contact_name" => request()->primary_contact_name,
605+
"primary_contact_phone" => request()->primary_contact_phone,
606+
"metadata" => request()->metadata,
607+
'settlement_schedule' => request()->settlement_schedule
608+
];
609+
610+
$this->setRequestOptions();
611+
return $this->setHttpResponse('/subaccount', 'POST', array_filter($data))->getResponse();
612+
613+
}
614+
615+
/**
616+
* Fetches details of a subaccount
617+
* @param subaccount code
618+
* @return array
619+
*/
620+
public function fetchSubAccount($subaccount_code){
621+
622+
$this->setRequestOptions();
623+
return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse();
624+
625+
}
626+
627+
/**
628+
* Lists all the subaccounts associated with the account
629+
* @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve
630+
* @return array
631+
*/
632+
public function listSubAccounts($per_page,$page){
633+
634+
$this->setRequestOptions();
635+
return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse();
636+
637+
}
638+
639+
640+
/**
641+
* Updates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
642+
* @param subaccount code
643+
* @return array
644+
*/
645+
646+
public function updateSubAccount($subaccount_code){
647+
$data = [
648+
"business_name" => request()->business_name,
649+
"settlement_bank" => request()->settlement_bank,
650+
"account_number" => request()->account_number,
651+
"percentage_charge" => request()->percentage_charge,
652+
"description" => request()->description,
653+
"primary_contact_email" => request()->primary_contact_email,
654+
"primary_contact_name" => request()->primary_contact_name,
655+
"primary_contact_phone" => request()->primary_contact_phone,
656+
"metadata" => request()->metadata,
657+
'settlement_schedule' => request()->settlement_schedule
658+
];
659+
660+
$this->setRequestOptions();
661+
return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse();
662+
663+
}
586664
}

0 commit comments

Comments
 (0)