Repository navigation
Expand file tree
/
Copy pathCustomerOverviewService.php
More file actions
98 lines (89 loc) · 3.15 KB
/
Copy pathCustomerOverviewService.php
File metadata and controls
98 lines (89 loc) · 3.15 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
<?php
/**
* Author: Arda Baran
*
* Description:
*
* This service collects and combines customer-related information
* from OIM and the DecisionActions service.
*
* It provides a single overview of the authenticated customer's
* current status, including:
*
* 1) Customer name
* 2) Subscriber number
* 3) Current tariff
* 4) Internet connection status
* 5) Connection start/end time
* 6) Outstanding debt amount
* 7) Payment link
*
* The service acts as an aggregation layer between the chatbot
* and the underlying OIM / ISS API services.
*
* Instead of making the chatbot request each piece of customer
* information separately, this class retrieves the required data
* and combines it into a single structured response.
*/
namespace App\Services\bot;
class CustomerOverviewService
{
public function __construct(
public DecisionActions $actions,
public GetCustomerInfoFromOIM $oimClient,
public BotAuthInfo $authInfo,
)
{
if (!$this->authInfo->get()) {
$this->authInfo->start();
}
}
public function get(): array
{
$auth = $this->authInfo->get();
$defaultUsername = $auth['username'];
$defaultPassword = $auth['password'];
$customer = $this->oimClient->oimLoginAndCustomerInfo($defaultUsername, $defaultPassword);
if (!$customer || !is_array($customer)) {
return [];
}
$fullName = trim($customer['isim'] ?? '');
$parts = explode(' ', $fullName);
$name = mb_convert_case($parts[0], MB_CASE_TITLE, "UTF-8");
$aboneNo = trim($customer['abone_no'] ?? '');
$tarife = trim($customer['tarife'] ?? '');
$connectionData = $this->actions->check_connection_session($aboneNo);
$paymentData = $this->actions->check_payment_session($aboneNo);
$paymentLinkData = $this->actions->check_payment_link_session($aboneNo);
$connectionTime = null;
$borcTutari = "0 ₺";
$paymentLink = null;
if (!empty($connectionData['data']['connection_start'])) {
$connectionTime = $connectionData['data']['connection_start'];
}
if (!empty($connectionData['data']['connection_end'])) {
$connectionTime = $connectionData['data']['connection_end'];
}
$connectionStatus = $connectionData['data']['connection_status'];
if (!empty($paymentData['data']['borc']) && $paymentData['data']['borc'] > 0) {
$borcTutari = number_format(
(float)$paymentData['data']['borc'],
2, // ondalık
',', // ondalık ayırıcı
'.' // binlik ayırıcı
) . ' ₺';
}
if (!empty($paymentLinkData['data']['link'])) {
$paymentLink = $paymentLinkData['data']['link'];
}
return [
'connection_durum' => $connectionStatus,
'debt' => $borcTutari,
'payment_linki' => $paymentLink,
'connection_zaman' => $connectionTime,
'aboneNumarasi' => $aboneNo,
'isim' => $name,
'tarife' => $tarife,
];
}
}