Skip to content
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

Add Transfer functions that will implement transfer API #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
122 changes: 117 additions & 5 deletions src/PayantNG/Payant/Payant.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,126 @@ public function deleteInvoice($reference_code){



/**
* [addTransfer description]
* @param array $client_data [description]
* Required fields - 'first_name', 'last_name', 'email', 'phone', 'settlement_bank', 'account_number',
* Optional - 'address', 'company_name', 'type',
* @param [string] $amount [Mandatory]
*/
public function addTransfer(array $client_data, string $amount){
// Mandatory Client fields
$required_client_values = ['first_name', 'last_name', 'email', 'phone', 'settlement_bank', 'account_number'];

if(!array_keys_exist($client_data, $required_client_values)){
throw new Exception\RequiredValuesMissing("Missing required values :( - Provide client_data");
}

if(!$amount){
throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid amount");
}

$url = "/transfers";

$post_data = [
'client' => $client_data,
'amount' => $amount,
];

return $this->sendRequest('post', $url, ['form_params' => $post_data]);
}





/**
* [getTransfer ]
* @param [string] $reference_code [Mandatory - Transfer Reference Code]
* @return [object]
*/
public function getTransfer($reference_code){
if(!$reference_code){
throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
}

$url = "/transfers/{$reference_code}";

return $this->sendRequest('get', $url);
}






/**
* [getTransferHistory]
* @param [string] $period [Mandatory || Valid Options ["today", "week", "month", "30", "90", "year", "custom"]]
* @param [string] $start [Format - DD/MM/YYYY]
* @param [string] $end [Format - DD/MM/YYYY]
* @return [object]
*/
public function getTransferHistory($period, $start = null, $end = null){
if(!$period){
throw new Exception\RequiredValueMissing("Error Processing Request - period Missing");
}

//Validate Period
$valid_period_options = ["today", "week", "month", "30", "90", "year", "custom"];

if (!in_array($period, $valid_period_options)) {
throw new Exception\IsInvalid("Invalid Period - Available options: today, week, month, 30, 90, year or custom");
}

$post_data = [
'period' => $period
];

if ($period == 'custom'){
if (!$start || !$end){
throw new Exception\IsNull("Invalid custom Start or End date");
}
$post_data['start'] = $start;
$post_data['end'] = $end;
}

$url = "/transfers/history";

return $this->sendRequest('post', $url, ['form_params' => $post_data]);
}





/**
* [deleteTransfer]
* @param [string] $reference_code [Mandatory - Invoice Reference Code]
* @return [object]
*/
public function deleteTransfer($reference_code){
if(!$reference_code){
throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
}

$url = "/transfers/{$reference_code}";

return $this->sendRequest('delete', $url);
}





/**
* [addPayment]
* @param [string] $reference_code [Mandatory - Invoice Reference Code]
* @param [string] $date [Mandatory - [Format - DD/MM/YYYY]]
* @param [string] $due_date [Mandatory - [Format - DD/MM/YYYY]]
* @param [string] $amount [Mandatory]
* @param [string] $channel [Mandatory - valid ["Cash", "BankTransfer", "POS", "Cheque"]]
*/
public function addPayment(string $reference_code, string $date, string $amount, string $channel){
public function addPayment(string $reference_code, string $due_date, string $amount, string $channel){
if(!$reference_code){
throw new Exception\IsNullOrInvalid("Error Processing Request - Null/Invalid reference_code");
}
Expand All @@ -350,7 +462,7 @@ public function addPayment(string $reference_code, string $date, string $amount,

$post_data = [
'reference_code' => $reference_code,
'date' => $date,
'date' => $due_date,
'amount' => $amount,
'channel' => $channel
];
Expand Down Expand Up @@ -511,11 +623,11 @@ public function editProduct($product_id, array $product_data){
// Mandatory fields
$required_values = ['name', 'description', 'unit_cost', 'type'];

if(!array_keys_exist($client_data, $required_values)){
if(!array_keys_exist($product_data, $required_values)){
throw new Exception\RequiredValuesMissing("Missing required values :(");
}

return $this->sendRequest('put', $url, ['form_params' => $post_data]);
return $this->sendRequest('put', $url, ['form_params' => $product_data]);
}


Expand Down