Skip to content

Added methods to handle Split payments #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,32 @@ Paystack::getAllTransactions();
* @returns string
*/
Paystack::genTranxRef();

/**
* This method creates a subaccount to be used for split payments
* @return array
*/
Paystack::createSubAccount();


/**
* This method fetches the details of a subaccount
* @return array
*/
Paystack::fetchSubAccount();


/**
* This method lists the subaccounts associated with your paystack account
* @return array
*/
Paystack::listSubAccounts();

/**
* This method Updates a subaccount to be used for split payments
* @return array
*/
Paystack::updateSubAccount();
```

A sample form will look like so:
Expand Down
80 changes: 79 additions & 1 deletion src/Paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ private function setRequestOptions()
);
}

/**

/**

* Initiate a payment request to Paystack
* Included the option to pass the payload to this method for situations
* when the payload is built on the fly (not passed to the controller from a view)
* @return Paystack
*/

public function makePaymentRequest( $data = null)
{
if ( $data == null ) {
Expand Down Expand Up @@ -338,6 +341,7 @@ public function createPlan()
$this->setRequestOptions();

$this->setHttpResponse("/plan", 'POST', $data);

}

/**
Expand Down Expand Up @@ -583,4 +587,78 @@ public function updatePage($page_id)
$this->setRequestOptions();
return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
}

/**
* Creates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
*
* @return array
*/

public function createSubAccount(){
$data = [
"business_name" => request()->business_name,
"settlement_bank" => request()->settlement_bank,
"account_number" => request()->account_number,
"percentage_charge" => request()->percentage_charge,
"primary_contact_email" => request()->primary_contact_email,
"primary_contact_name" => request()->primary_contact_name,
"primary_contact_phone" => request()->primary_contact_phone,
"metadata" => request()->metadata,
'settlement_schedule' => request()->settlement_schedule
];

$this->setRequestOptions();
return $this->setHttpResponse('/subaccount', 'POST', array_filter($data))->getResponse();

}

/**
* Fetches details of a subaccount
* @param subaccount code
* @return array
*/
public function fetchSubAccount($subaccount_code){

$this->setRequestOptions();
return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse();

}

/**
* Lists all the subaccounts associated with the account
* @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve
* @return array
*/
public function listSubAccounts($per_page,$page){

$this->setRequestOptions();
return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse();

}


/**
* Updates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
* @param subaccount code
* @return array
*/

public function updateSubAccount($subaccount_code){
$data = [
"business_name" => request()->business_name,
"settlement_bank" => request()->settlement_bank,
"account_number" => request()->account_number,
"percentage_charge" => request()->percentage_charge,
"description" => request()->description,
"primary_contact_email" => request()->primary_contact_email,
"primary_contact_name" => request()->primary_contact_name,
"primary_contact_phone" => request()->primary_contact_phone,
"metadata" => request()->metadata,
'settlement_schedule' => request()->settlement_schedule
];

$this->setRequestOptions();
return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse();

}
}