107 lines
4.5 KiB
PHP
107 lines
4.5 KiB
PHP
<?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;
|
|
|
|
// temorarily
|
|
//$in['bank_code'] = "044";
|
|
//$in['account_no'] = "0690000031";
|
|
// ---- testing
|
|
|
|
// Setup request to send json via POST.
|
|
$payload = json_encode(array(
|
|
"money_transfer_id" => $in['id'],
|
|
"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://host.docker.internal: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);
|
|
|
|
//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"}}}
|
|
*/
|
|
|
|
// 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['status'] = 'Invalid service response: ' . $result;
|
|
}
|
|
// Cannot POST /api/create
|
|
|
|
$out['response'] = $result;
|
|
|
|
return $out;
|
|
}
|
|
}
|