Flutterwave calling from back office
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
if ( ! function_exists('flutterwave_api'))
|
||||
{
|
||||
function flutterwave_api($in)
|
||||
{
|
||||
$out = array();
|
||||
$out['status'] = 'Unhandled error';
|
||||
$out['result'] = -1;
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
/* Example :
|
||||
OrderedMap {
|
||||
"account_bank": "044",
|
||||
"account_number": "0690000040",
|
||||
"amount": 5500,
|
||||
"narration": "Akhlm Pstmn Trnsfr xx007",
|
||||
"currency": "NGN",
|
||||
"reference": "akhlm-pstmnpyt-rfxx007_PMCKDU_1",
|
||||
"debit_currency": "NGN"
|
||||
}
|
||||
*/
|
||||
$reference = str_replace('.','-',$in['id'].'.'.microtime());
|
||||
$out['my_reference'] = $reference;
|
||||
|
||||
// Setup request to send json via POST.
|
||||
$payload = json_encode(array(
|
||||
"account_bank" => $in['bank_code'],
|
||||
"account_number" => $in['account_no'],
|
||||
"amount" => $in['amount'],
|
||||
"narration" => $in['narration'],
|
||||
"currency" => "NGN",
|
||||
"reference" => $reference,
|
||||
"debit_currency" => "NGN"
|
||||
));
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL,"http://10.20.30.32:9086/create");
|
||||
// curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||
|
||||
// Receive server response ...
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close ($ch);
|
||||
|
||||
$data = json_decode($result, true);
|
||||
|
||||
// Further processing ...
|
||||
if ($data!=null && is_array($data)) {
|
||||
if (array_key_exists('status',$data) && $data['status']=='success') {
|
||||
$out['result'] = 0; // OK
|
||||
$out['status'] = 'Transfer successful';
|
||||
if (array_key_exists('message',$data) && $data['message']!='') {
|
||||
$out['status'].= ': '.$data['message'];
|
||||
}
|
||||
} else {
|
||||
$out['result'] = -3;
|
||||
$out['status'] = 'failure';
|
||||
if (array_key_exists('status',$data) && $data['status']!='') {
|
||||
$out['status'] = $data['status'];
|
||||
}
|
||||
if (array_key_exists('message',$data) && $data['message']!='') {
|
||||
$out['status'].= ': '.$data['message'];
|
||||
}
|
||||
if (array_key_exists('details',$data) && $data['details']!='') {
|
||||
$out['status'].= ': '.$data['details'];
|
||||
}
|
||||
if (array_key_exists('data',$data) && is_array($data['data'])
|
||||
&& array_key_exists('message',$data['data']) && $data['data']['message']!='') {
|
||||
$out['status'].= ': '.$data['data']['message'];
|
||||
}
|
||||
if (array_key_exists('data',$data) && is_array($data['data'])
|
||||
&& array_key_exists('data',$data['data']) && is_array($data['data']['data'])
|
||||
&& array_key_exists('complete_message',$data['data']['data']) && $data['data']['data']['complete_message']!='') {
|
||||
$out['status'].= ': '.$data['data']['data']['complete_message'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$out['result'] = -2;
|
||||
$out['stauts'] = 'Invalid service response: ' . $result;
|
||||
}
|
||||
// Cannot POST /api/create
|
||||
|
||||
$out['response'] = $result;
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user