Check flutterwave transfer status
This commit is contained in:
@@ -58,9 +58,9 @@ if ( ! function_exists('flutterwave_api'))
|
||||
//var_dump( $data);
|
||||
//exit;
|
||||
/*
|
||||
{"account_bank":"044","account_number":"0690000031","amount":"123.00","narration":"Transfer from Olusesan Amey
|
||||
ses66181+1@gmail.com","currency":"NGN","reference":"120-0-97165300 1652605656","debit_currency":"NGN"} //// {"status":200,"statusText":"OK","data":{"status":"success","message":"Transfer Queued Successfully","data":{"id":345332,"account_number":"0690000031","bank_code":"044","full_name":"Forrest Green","created_at":"2022-05-15T09:07:37.000Z","currency":"NGN","debit_currency":"NGN","amount":123,"fee":10.75,"status":"NEW","reference":"120-0-97165300 1652605656","meta":null,"narration":"Transfer from Olusesan Amey
|
||||
ses66181+1@gmail.com","complete_message":"","requires_approval":0,"is_approved":1,"bank_name":"ACCESS BANK NIGERIA"}}}
|
||||
{"account_bank":"044","account_number":"0690000031","amount":"123.00","narration":"Transfer from Olusesan Amey
|
||||
ses66181+1@gmail.com","currency":"NGN","reference":"120-0-97165300 1652605656","debit_currency":"NGN"} //// {"status":200,"statusText":"OK","data":{"status":"success","message":"Transfer Queued Successfully","data":{"id":345332,"account_number":"0690000031","bank_code":"044","full_name":"Forrest Green","created_at":"2022-05-15T09:07:37.000Z","currency":"NGN","debit_currency":"NGN","amount":123,"fee":10.75,"status":"NEW","reference":"120-0-97165300 1652605656","meta":null,"narration":"Transfer from Olusesan Amey
|
||||
ses66181+1@gmail.com","complete_message":"","requires_approval":0,"is_approved":1,"bank_name":"ACCESS BANK NIGERIA"}}}
|
||||
*/
|
||||
|
||||
// Further processing ...
|
||||
@@ -104,3 +104,70 @@ ses66181+1@gmail.com","complete_message":"","requires_approval":0,"is_approved":
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('flutterwave_api_check'))
|
||||
{
|
||||
function flutterwave_api_check($in)
|
||||
{
|
||||
$out = array();
|
||||
$out['status'] = 'Unhandled error';
|
||||
$out['result'] = -1;
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
$url = "http://host.docker.internal:9086/status/".$in['id'];
|
||||
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$result = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
//var_dump($result);
|
||||
/*
|
||||
string(592) "{"status":200,"statusText":"OK","data":{"status":"success","message":"Transfer fetched","data":{"id":348032,"account_number":"0690000031","bank_code":"044","full_name":"Forrest Green","created_at":"2022-06-05T04:22:49.000Z","currency":"NGN","debit_currency":"NGN","amount":123,"fee":10.75,"status":"FAILED","reference":"120-0-37263200 1654402969","meta":null,"narration":"Transfer from Olusesan Amey
|
||||
ses66181+1@gmail.com","approver":null,"complete_message":"DISBURSE FAILED: Insufficient funds in customer balance","requires_approval":0,"is_approved":1,"bank_name":"ACCESS BANK NIGERIA"}}}"
|
||||
*/
|
||||
|
||||
$data = json_decode($result, true);
|
||||
|
||||
// Further processing ...
|
||||
if ($data!=null && is_array($data)) {
|
||||
if (array_key_exists('status',$data) && $data['status']=='200') {
|
||||
if (array_key_exists('data',$data) && is_array($data['data'])) {
|
||||
$raw = $data['data'];
|
||||
if (array_key_exists('status',$raw) && $raw['status']=='success') {
|
||||
$out['result'] = 0; // OK
|
||||
$out['status'] = $raw['message'];
|
||||
if (array_key_exists('data',$raw) && is_array($raw['data'])) {
|
||||
$out['status'].= ': '.$raw['data']['complete_message'];
|
||||
} else {
|
||||
$out['status'].= ': No transfer data found -> ' . json_encode($raw);
|
||||
}
|
||||
} else {
|
||||
$out['result'] = -5;
|
||||
$out['status'] = 'Flutterwave response failure: ' . json_encode($raw);
|
||||
}
|
||||
} else {
|
||||
$out['result'] = -4;
|
||||
$out['status'] = 'Missing flutterwave response: ' . $result;
|
||||
}
|
||||
} else {
|
||||
// Error response
|
||||
$out['result'] = -3;
|
||||
if (array_key_exists('status',$data)) {
|
||||
$out['status'] = $data['status'];
|
||||
} else {
|
||||
$out['status'] = 'Missing starus response: ' . $result;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$out['result'] = -2;
|
||||
$out['status'] = 'Invalid service response: ' . $result;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user