Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
I
IPRSv2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Ngei
IPRSv2
Commits
71928513
Commit
71928513
authored
Mar 26, 2025
by
Michael Ngei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated
parent
76465b78
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
.gitignore
.gitignore
+1
-0
PaymentsAPI.php
app/Http/Controllers/API/PaymentsAPI.php
+11
-11
TokensController.php
app/Http/Controllers/TokensController.php
+19
-2
No files found.
.gitignore
View file @
71928513
...
...
@@ -21,3 +21,4 @@ supervisord.pid
supervisord.log
worker.log
composer.lock
/config
app/Http/Controllers/API/PaymentsAPI.php
View file @
71928513
...
...
@@ -104,13 +104,10 @@ class PaymentsAPI extends Controller
$consumer_name
=
str_replace
(
' '
,
'_'
,
strtoupper
(
$contract
->
client
->
name_sh
));
//$res=Redis::set('name', 'mikee');
//$checkKey = Redis::get('search_quota:countsse:user23');
try
{
if
(
Redis
::
exists
(
"search_quota:max:"
.
$consumer_name
))
{
$tokens
=
$validated
[
'tokens'
];
$maxToken
=
Redis
::
get
(
"search_quota:max:"
.
$consumer_name
);
// added tokens
$newMax
=
$tokens
+
$maxToken
;
//set tokens
...
...
@@ -126,11 +123,16 @@ class PaymentsAPI extends Controller
'contract_id'
=>
$validated
[
'contract_id'
],
'USER_ID'
=>
$validated
[
'user_id'
],
]);
//update tokens
Tokens
::
where
(
'contract_id'
,
$validated
[
'contract_id'
])
->
update
([
'total_tokens'
=>
$newMax
,
]);
// Return success JSON response
return
response
()
->
json
([
'success'
=>
true
,
'message'
=>
'Payment created successfully'
,
$this
->
jsonData
,
],
201
);
}
}
else
{
...
...
@@ -148,7 +150,6 @@ class PaymentsAPI extends Controller
return
response
()
->
json
([
'success'
=>
true
,
'message'
=>
'Payment created successfully'
,
$this
->
jsonData
,
],
201
);
}
}
catch
(
\Predis\Connection\ConnectionException
$redisException
)
{
...
...
@@ -234,17 +235,16 @@ class PaymentsAPI extends Controller
]
]);
if
(
$response
->
successful
())
{
//save it locally
$tokens
=
Tokens
::
create
([
'TOTAL_TOKENS'
=>
$tokens
,
'contract_id'
=>
$cid
,
]);
$tokens
=
Tokens
::
create
([
'TOTAL_TOKENS'
=>
$tokens
,
'contract_id'
=>
$cid
,
]);
return
[
'status'
=>
$response
->
successful
()
,
'body'
=>
$response
->
body
()];
// return response()->json(["message" => "Consumer created successfully.", "data" => $response->json()]);
}
else
{
//return response()->json(["error" => "Failed to create consumer.", "details" => $response->body()], $response->status());
return
[
'status'
=>
false
,
'body'
=>
''
];
}
}
}
...
...
app/Http/Controllers/TokensController.php
View file @
71928513
...
...
@@ -2,6 +2,8 @@
namespace
App\Http\Controllers
;
use
App\Models\Client
;
use
App\Models\Contract
;
use
App\Models\Tokens
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Redis
;
...
...
@@ -29,12 +31,27 @@ class TokensController extends Controller
}
}
while
(
$cursor
!==
'0'
);
dd
(
$searchQuotas
);
$counts
=
[];
foreach
(
$searchQuotas
as
$key
=>
$value
)
{
if
(
str_contains
(
$key
,
'search_quota:count:'
))
{
$clientName
=
str_replace
(
'search_quota:count:'
,
''
,
$key
);
$counts
[
$clientName
]
=
$value
;
}
}
// Update the Tokens table
foreach
(
$counts
as
$clientName
=>
$usedTokens
)
{
$clients_found
=
Client
::
where
(
'name_sh'
,
$clientName
)
->
first
();
if
(
$clients_found
){
$contract
=
Contract
::
where
(
'client_rid'
,
$clients_found
->
rid
)
->
first
();
if
(
$contract
)
{
$updated
=
Tokens
::
where
(
'CONTRACT_ID'
,
$contract
->
rid
)
->
update
([
'USED_TOKENS'
=>
$usedTokens
]);
}
}
}
$tokens
=
Tokens
::
with
(
'contract.client'
)
->
get
();
return
view
(
'tokens.tokens'
,
[
'tokens'
=>
$tokens
,
'searchQuotas'
=>
$searchQuotas
]);
}
/* public function index()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment