-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathKudabankController.php
More file actions
149 lines (107 loc) · 5.29 KB
/
KudabankController.php
File metadata and controls
149 lines (107 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Modules\Kudabank\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Log;
use Kuda\KudaEncyption\KudaEncyption;
class KudabankController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
$bank_list = $this->bank_list();
dd($bank_list);
$name_enquiry = $this->name_enquiry(["beneficiaryAccountNumber"=> '1100000734','bankCode' => '999129']);
dd($name_enquiry);
$transactions = $this->transactions(["startDate"=> '2019-10-22T10:22:25','endDate' => '2020-10-22T10:22:25']);
dd( $transactions );
dd( (collect($transactions->Data->transactions)->where('part_tran_type', 'C')->sum('total')) );
return view('kudabank::index');
}
public function bank_list($bank_code = null)
{
$BANK_LIST = ["ServiceType" => "BANK_LIST","RequestRef"=>rand()];
$bank_list = $this->fetchkuda($BANK_LIST);
return $bank_list;
}
public function fetchkuda($payload){
$payload = json_encode($payload);
$encryption = new KudaEncyption();
$client_key = 'CGZFw5lPQbMaXf3Y426v';
$random_str = rand();
$aes_password = $client_key.'-'.$random_str;
$ecrypted_data = $encryption->AESEncrypt($payload, $aes_password);
$kuda_public_key = file_get_contents('xml/kuda.xml');
$ecrypted_password = $encryption->RSAEncrypt($aes_password, $kuda_public_key);
$request_body = ['data' => $ecrypted_data];
$request_header = ['password' => $ecrypted_password];
$request = ['header' => $request_header, 'body' => $request_body ];
$headers = array(
"Accept: */*",
"Content-Encoding: gzip",
"Content-Type: application/json",
"password: $ecrypted_password");
$data_string = json_encode($request_body);
$ch = curl_init('https://kudaopenapi.azurewebsites.net/v1');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$response = json_decode($result, true);
if(isset($response['data'])){
$kuda_private_key = file_get_contents('xml/CGZFw5lPQbMaXf3Y426v.xml');
$decrypted_password = $encryption->RSADecrypt($response['password'], $kuda_private_key);
$decrypted_data = $encryption->AESDecrypt($response['data'], $decrypted_password);
return json_decode($decrypted_data);
}
return false;
}
public function name_enquiry($data)
{
$NAME_ENQUIRY = ["ServiceType" => "NAME_ENQUIRY","RequestRef"=>rand(), "Data"=>["beneficiaryAccountNumber"=> '1100000734','bankCode' => '999129']];
$result = $this->fetchkuda($NAME_ENQUIRY);
dd($result);
return $result;
}
public function transactions($data)
{
$TRANSACTIONS_AND_BALANCE_ENQUIRY = ["ServiceType" => "TRANSACTIONS_AND_BALANCE_ENQUIRY","RequestRef"=>rand(), "Data"=> $data];
$transactions = $this->fetchkuda($TRANSACTIONS_AND_BALANCE_ENQUIRY);
return $transactions;
}
public function create_virtual_account($data)
{
$CREATE_VIRTUAL_ACCOUNT = ["ServiceType" => "CREATE_VIRTUAL_ACCOUNT","RequestRef"=>rand(), "Data"=> $data];
$result = $this->fetchkuda($CREATE_VIRTUAL_ACCOUNT);
return $result;
}
public function onboarding($data)
{
$ONBOARDING = ["ServiceType" => "ONBOARDING","RequestRef"=>rand(), "Data"=> $data];
$result = $this->fetchkuda($ONBOARDING);
return $result;
}
public function single_fund_transfer($data)
{
$SINGLE_FUND_TRANSFER = ["ServiceType" => "SINGLE_FUND_TRANSFER","RequestRef"=>rand(), "Data"=> $data];
$result = $this->fetchkuda($SINGLE_FUND_TRANSFER);
return $result;
}
public function retrieve_virtual_account($data = ['trackingReference'=>'000000'])
{
$RETRIEVE_VIRTUAL_ACCOUNT = ["ServiceType" => "RETRIEVE_VIRTUAL_ACCOUNT","RequestRef"=>rand(), "Data"=> $data];
$result = $this->fetchkuda($RETRIEVE_VIRTUAL_ACCOUNT);
return ($result);
}
public function virtual_account_fund_transfer($data)
{
$VIRTUAL_ACCOUNT_FUND_TRANSFER = ["ServiceType" => "VIRTUAL_ACCOUNT_FUND_TRANSFER","RequestRef"=>rand(), "Data"=> $data];
$result = $this->fetchkuda($VIRTUAL_ACCOUNT_FUND_TRANSFER);
return $result;
}
}