-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHelper.php
More file actions
586 lines (515 loc) · 17 KB
/
Copy pathHelper.php
File metadata and controls
586 lines (515 loc) · 17 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
<?php
/**
* Mutasibank API Helper Class
*
* Comprehensive helper class for Mutasibank API integration
* Documentation: https://mutasibank.co.id/api/docs
*
* @version 2.0
* @updated 2025-01-10
*/
class MutasibankAPI
{
const API_URL = "https://mutasibank.co.id/api/v1";
private $apiKey;
/**
* Constructor
* @param string $apiKey Your API token from Mutasibank dashboard
*/
public function __construct($apiKey)
{
$this->apiKey = $apiKey;
}
// ========================================================================
// AUTHENTICATION & USER
// ========================================================================
/**
* Get current user information
* @return array User data with balance and package info
*/
public function getUser()
{
return $this->httpGet("/user");
}
// ========================================================================
// BANK OPERATIONS
// ========================================================================
/**
* Get list of supported banks
* @return array List of all supported banks with their configuration
*/
public function getListBank()
{
return $this->httpGet("/list_bank");
}
// ========================================================================
// ACCOUNT OPERATIONS
// ========================================================================
/**
* Get all bank accounts
* @return array List of all registered bank accounts
*/
public function getAccounts()
{
return $this->httpGet("/accounts");
}
/**
* Get account by ID
* @param int $accountId Account ID
* @return array Account details
*/
public function getAccount($accountId)
{
return $this->httpGet("/account/{$accountId}");
}
/**
* Create new bank account
* @param array $data Account configuration
* @return array Created account details
*
* Required fields:
* - bank_id: Bank ID from /list_bank
* - account_name: Account holder name
* - account_no: Bank account number
* - user_banking: Internet banking username (if applicable)
* - password_banking: Internet banking password (if applicable)
*
* Optional fields:
* - api_key, api_secret, client_id, client_secret, corp_id: For API-based banks
* - schedule_minutes: Bot check interval (default varies by bank)
* - url_callback: Webhook URL for notifications
* - email_notification, wa_number, telegram_id: Notification channels
* - note: Account notes
*/
public function createAccount($data)
{
return $this->httpPostJson("/account/create", $data);
}
/**
* Update bank account
* @param string $accountId Account UUID or ID
* @param array $data Updated account data
* @return array Response message
*/
public function updateAccount($accountId, $data)
{
return $this->httpPut("/account/{$accountId}", $data);
}
/**
* Delete bank account
* @param string $accountId Account UUID or ID
* @return array Response message
*/
public function deleteAccount($accountId)
{
return $this->httpDelete("/account/{$accountId}");
}
/**
* Toggle account status (on/off)
* @param int $accountId Account ID
* @param int $status 0 = off, 1 = on
* @return array Response message
*/
public function toggleAccountStatus($accountId, $status)
{
$data = ['status' => $status];
return $this->httpPost("/on_off/{$accountId}", $data);
}
/**
* Toggle account status (alternative endpoint)
* @param string $accountId Account UUID
* @return array Response message
*/
public function toggleAccount($accountId)
{
return $this->httpPostJson("/account/{$accountId}/toggle", []);
}
/**
* Input BCA token (for BCA accounts requiring token)
* @param int $accountId Account ID
* @param string $token1 First token from BCA KeyBCA
* @param string $token2 Second token from BCA KeyBCA
* @return array Response message
*/
public function inputToken($accountId, $token1, $token2)
{
$data = [
'token_1' => $token1,
'token_2' => $token2
];
return $this->httpPost("/input_token/{$accountId}", $data);
}
/**
* Rerun bot check for account
* @param int $accountId Account ID
* @return array Response with next schedule time
*/
public function rerunCheck($accountId)
{
return $this->httpGet("/rerun/{$accountId}");
}
/**
* Get bot activity logs
* @param int $accountId Account ID
* @return array Bot activity logs and history
*/
public function getLogBot($accountId)
{
return $this->httpGet("/log_bot/{$accountId}");
}
// ========================================================================
// TRANSACTION & STATEMENT OPERATIONS
// ========================================================================
/**
* Get account statements/transactions
* @param int $accountId Account ID
* @param string $dateFrom Start date (YYYY-MM-DD)
* @param string $dateTo End date (YYYY-MM-DD)
* @return array Transaction data
*/
public function getStatements($accountId, $dateFrom, $dateTo)
{
$data = [
'date_from' => $dateFrom,
'date_to' => $dateTo
];
return $this->httpPost("/statements/{$accountId}", $data);
}
/**
* Match transaction by amount (returns first match)
* @param int $accountId Account ID
* @param int $amount Transaction amount to match
* @param string $dateFrom Optional start date (YYYY-MM-DD)
* @param string $dateTo Optional end date (YYYY-MM-DD)
* @return array Matched transaction or empty if not found
*/
public function matchTransaction($accountId, $amount, $dateFrom = null, $dateTo = null)
{
$data = ['amount' => $amount];
if ($dateFrom) $data['date_from'] = $dateFrom;
if ($dateTo) $data['date_to'] = $dateTo;
return $this->httpPost("/match/{$accountId}", $data, 'application/x-www-form-urlencoded');
}
/**
* Match multiple transactions by amount
* @param int $accountId Account ID
* @param int $amount Transaction amount to match
* @return array All matched transactions
*/
public function matchTransactions($accountId, $amount)
{
$data = ['amount' => $amount];
return $this->httpPost("/matchs/{$accountId}", $data, 'application/x-www-form-urlencoded');
}
/**
* Validate transaction by statement ID
* @param string $transactionId Statement ID (UUID or integer)
* @return array Transaction validation result
*/
public function validateTransaction($transactionId)
{
return $this->httpGet("/validate/{$transactionId}");
}
// ========================================================================
// CATEGORY MANAGEMENT
// ========================================================================
/**
* Get all categories
* @return array List of transaction categories
*/
public function getCategories()
{
return $this->httpGet("/categories");
}
/**
* Get category by ID
* @param string $categoryId Category UUID
* @return array Category details
*/
public function getCategory($categoryId)
{
return $this->httpGet("/category/{$categoryId}");
}
/**
* Create new category
* @param string $name Category name
* @param string $type Transaction type (CR or DB)
* @param string $description Category description (optional)
* @return array Created category
*/
public function createCategory($name, $type, $description = '')
{
$data = [
'name' => $name,
'type' => $type,
'description' => $description
];
return $this->httpPostJson("/category", $data);
}
/**
* Update category
* @param string $categoryId Category UUID
* @param array $data Updated category data
* @return array Response message
*/
public function updateCategory($categoryId, $data)
{
return $this->httpPut("/category/{$categoryId}", $data);
}
/**
* Delete category
* @param string $categoryId Category UUID
* @return array Response message
*/
public function deleteCategory($categoryId)
{
return $this->httpDelete("/category/{$categoryId}");
}
// ========================================================================
// WEBHOOK MANAGEMENT
// ========================================================================
/**
* Get all webhooks
* @return array List of configured webhooks
*/
public function getWebhooks()
{
return $this->httpGet("/webhooks");
}
/**
* Get webhook by ID
* @param int $webhookId Webhook ID
* @return array Webhook details (secret is hidden for security)
*/
public function getWebhook($webhookId)
{
return $this->httpGet("/webhook/{$webhookId}");
}
/**
* Create new webhook
* @param string $url Webhook URL (must be HTTPS)
* @param int $bankAccountId Bank account ID
* @param string $description Webhook description
* @return array Created webhook with secret for signature verification
*/
public function createWebhook($url, $bankAccountId, $description = '')
{
$data = [
'url' => $url,
'bank_account_id' => $bankAccountId,
'description' => $description
];
return $this->httpPostJson("/webhook", $data);
}
/**
* Update webhook
* @param string $webhookId Webhook UUID or ID
* @param array $data Updated webhook data
* @return array Response message
*/
public function updateWebhook($webhookId, $data)
{
return $this->httpPut("/webhook/{$webhookId}", $data);
}
/**
* Delete webhook
* @param string $webhookId Webhook UUID or ID
* @return array Response message
*/
public function deleteWebhook($webhookId)
{
return $this->httpDelete("/webhook/{$webhookId}");
}
// ========================================================================
// WALLET & BILLING
// ========================================================================
/**
* Create top-up transaction
* @param int $amount Amount to top up (min: 10000)
* @param int $paymentId Payment method (1=BCA, 2=Mandiri)
* @return array Top-up details with payment instructions
*/
public function topupKredit($amount, $paymentId)
{
$data = [
'jumlah' => $amount,
'payment_id' => $paymentId
];
return $this->httpPost("/topup_kredit", $data);
}
// ========================================================================
// HTTP REQUEST METHODS (PRIVATE)
// ========================================================================
/**
* HTTP GET request
*/
private function httpGet($endpoint)
{
$headers = ["Authorization: " . $this->apiKey];
return $this->request('GET', self::API_URL . $endpoint, null, $headers);
}
/**
* HTTP POST request (form-urlencoded)
*/
private function httpPost($endpoint, $data = [], $contentType = 'application/x-www-form-urlencoded')
{
$headers = [
"Authorization: " . $this->apiKey,
"Content-Type: " . $contentType
];
if ($contentType === 'application/json') {
$postData = json_encode($data);
} else {
$postData = http_build_query($data);
}
return $this->request('POST', self::API_URL . $endpoint, $postData, $headers);
}
/**
* HTTP POST request (JSON)
*/
private function httpPostJson($endpoint, $data = [])
{
$headers = [
"Authorization: " . $this->apiKey,
"Content-Type: application/json"
];
return $this->request('POST', self::API_URL . $endpoint, json_encode($data), $headers);
}
/**
* HTTP PUT request
*/
private function httpPut($endpoint, $data = [])
{
$headers = [
"Authorization: " . $this->apiKey,
"Content-Type: application/json"
];
return $this->request('PUT', self::API_URL . $endpoint, json_encode($data), $headers);
}
/**
* HTTP DELETE request
*/
private function httpDelete($endpoint)
{
$headers = ["Authorization: " . $this->apiKey];
return $this->request('DELETE', self::API_URL . $endpoint, null, $headers);
}
/**
* Generic HTTP request handler
*/
private function request($method, $url, $data = null, $headers = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
// SECURITY: Enable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
if ($data !== null && in_array($method, ['POST', 'PUT', 'PATCH'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 45);
curl_setopt($ch, CURLOPT_USERAGENT, "MutasibankAPI-PHP/2.0");
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
return [
'error' => true,
'message' => 'cURL Error: ' . $error,
'http_code' => $httpCode
];
}
return json_decode($result, true);
}
}
// ============================================================================
// BACKWARD COMPATIBILITY - OLD Helper class
// ============================================================================
/**
* Legacy Helper class (for backward compatibility)
* @deprecated Use MutasibankAPI class instead
*/
class Helper
{
const API_URL = "https://mutasibank.co.id/api/v1";
const API_KEY = "YOUR_API_TOKEN_HERE";
/**
* Get all accounts (legacy method)
* @deprecated Use MutasibankAPI::getAccounts()
*/
public static function GetAccount()
{
$api = new MutasibankAPI(self::API_KEY);
return $api->getAccounts();
}
/**
* Get user info (legacy method)
* @deprecated Use MutasibankAPI::getUser()
*/
public static function GetUser()
{
$api = new MutasibankAPI(self::API_KEY);
return $api->getUser();
}
/**
* Get account statements (legacy method)
* @deprecated Use MutasibankAPI::getStatements()
*/
public static function GetAccountStatement($accId, $from, $to)
{
$api = new MutasibankAPI(self::API_KEY);
return $api->getStatements($accId, $from, $to);
}
/**
* Legacy HTTP POST method
* @deprecated Use MutasibankAPI methods
*/
public static function http_post($url, $param = [], $headers = [])
{
$fieldsString = http_build_query($param);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// SECURITY: Enable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* Legacy HTTP GET method
* @deprecated Use MutasibankAPI methods
*/
public static function http_get($url, $headers = [])
{
if (!function_exists('curl_init')) {
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// SECURITY: Enable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
}