Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
89d38ac
add NER tables
akaone Jan 2, 2021
0b9ae22
w.i.p tokenisation logic
akaone Jan 12, 2021
0d86af2
Merge branch 'develop' of https://github.com/akaone/ryok into named-e…
akaone Jan 20, 2021
9617da9
w.i.p annotation logic
akaone Jan 24, 2021
577868b
correct index
akaone Jan 24, 2021
14af154
Fixes
akaone Feb 8, 2021
f6c47b0
Remove require field
akaone Feb 19, 2021
761335e
refactor client login to actions
akaone Feb 26, 2021
78ed14e
ApiAccountStats
akaone Mar 15, 2021
1298e08
Api account stats by day
akaone Mar 19, 2021
e7f9f6c
Order account stats by week
akaone Mar 20, 2021
abcd48c
Refactor apps-list
akaone Mar 20, 2021
b5c3fd4
Refactor livewire app show
akaone Mar 20, 2021
f2fa21a
Refactor staff payment show
akaone Mar 20, 2021
66cd99c
Refactor staff carriers index
akaone Mar 21, 2021
388896a
Refactor staff carrier create
akaone Mar 21, 2021
612135b
refactor staff clients index
akaone Mar 21, 2021
4b1eaca
refactor staff merchants index
akaone Mar 21, 2021
edb7f4f
Refactor staff operations index
akaone Mar 21, 2021
071e8e9
refactor staff messages index
akaone Mar 21, 2021
4a8cbe9
refactor staff users index
akaone Mar 21, 2021
bf4fc97
reafactor staff ner
akaone Mar 21, 2021
0534c1c
refactor login signup
akaone Mar 21, 2021
312a4cf
refactor apps index
akaone Mar 21, 2021
338b1c7
refactor apps-operations
akaone Mar 21, 2021
27b3273
refactor apps api index
akaone Mar 21, 2021
1345fd4
refactor apps users create
akaone Mar 21, 2021
ca9bd0b
refactor apps useres show
akaone Mar 21, 2021
d0f2efd
Add apps setting to set carriers
akaone Mar 24, 2021
d78645f
Select and update app carriers
akaone Mar 24, 2021
2a8096b
fix
akaone Mar 24, 2021
c0b6410
Edit app webhook
akaone Mar 31, 2021
5bfe2fa
allow members (app user) Delete app
akaone Apr 2, 2021
eb166ee
Display activated app's carriers [staff]
akaone Apr 2, 2021
ff45788
Api docs
akaone Apr 11, 2021
5f2cfc3
Fix api.payment-request.show missing parameter
akaone Apr 11, 2021
a368a06
lighter background
akaone Apr 16, 2021
4b8bbaa
Test object payment
akaone Apr 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions app/Actions/Account/ApiAccountStats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php


namespace App\Actions\Account;


use App\Models\Operation;
use App\Responses\ApiErrorCode;
use App\Responses\ApiResponse;
use App\Rules\ApiAccountStatsRule;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;

class ApiAccountStats
{
use AsAction;
const credit = "credit";
const debit = "debit";

public function rules(): array
{
return [
'year_month' => ["string", "required", new ApiAccountStatsRule]
];
}

public function handle(string $accountId, $month)
{
$date = Carbon::parse($month);

$startOfMonth = $date->copy()->startOfMonth();
$endOfMonth = $date->copy()->endOfMonth();

$operations = Operation::where('state', '=', Operation::$PAID)
->whereIn('type', [
Operation::FROM_MOBILE_MONEY_TO_CLIENT_ACCOUNT,
Operation::FROM_CLIENT_ACCOUNT_TO_MOBILE_MONEY,
Operation::FROM_CLIENT_ACCOUNT_TO_APP_ACCOUNT,
])
->where('created_at', '>=', $startOfMonth)
->where('created_at', '<=', $endOfMonth)
->where(function ($query) use ($accountId){
$query->where('account_id', '=', $accountId)
->orWhere('from', '=', $accountId);
})
->get();

$groupedByCreditAndDebit = $operations->groupBy(function ($item, $key) use ($accountId) {
return $item->account_id == $accountId ? ApiAccountStats::credit : ApiAccountStats::debit;
});


$creditTotal = $this->getOperationTotal($groupedByCreditAndDebit->get(ApiAccountStats::credit));
$debitTotal = $this->getOperationTotal($groupedByCreditAndDebit->get(ApiAccountStats::debit));

$creditOperations = $this->calculateOperations($groupedByCreditAndDebit->get(ApiAccountStats::credit));
$debitOperations = $this->calculateOperations($groupedByCreditAndDebit->get(ApiAccountStats::debit));

$response = collect();

$response->put('calendar_days', $this->getCalendarDays($date));

$response->put('month_credit', $creditTotal);
$response->put('credits', $creditOperations);

$response->put('month_debit', $debitTotal);
$response->put('debits', $debitOperations);

return $response;
}

public function asController(ActionRequest $request): Collection
{
$accountId = auth()->user()->primaryAccount->id;
return $this->handle($accountId, $request->input("year_month"));
}

public function jsonResponse(Collection $accountStats): JsonResponse
{
return ApiResponse::create(
true,
ApiErrorCode::NONE,
$accountStats->toArray()
);
}

private function calculateOperations($collection): ?Collection
{
$result = collect([]);
if($collection) {
$formattedByWeek = $collection->groupBy(function ($row) {
$date = Carbon::parse($row->updated_at);
$weekStart = $date->copy()->startOfWeek()->format("d");
$weekEnd = $date->copy()->endOfWeek()->format("d");
return "{$weekStart}-{$weekEnd}";
});


foreach ($formattedByWeek as $key => $value) {
$result->put($key, $value->sum("amount_requested"));
}
}

return $result;

}

private function getCalendarDays(Carbon $startDate): Collection
{
$month = $startDate->copy()->month;
$year = $startDate->copy()->year;
$date = Carbon::createFromDate($year,$month);
// $numberOfWeeks = floor($date->daysInMonth / Carbon::DAYS_PER_WEEK);

$calendar = collect();
for ($i=1; $i <= $date->daysInMonth ; $i++) {
$tempDate = Carbon::createFromDate($year,$month,$i);
$calendar->push($tempDate->copy()->startOfWeek()->format("d") . "-" . $tempDate->copy()->endOfweek()->format("d"));
$i+=7;
}

return $calendar;
}

private function getOperationTotal($operations): int
{
return $operations && $operations->count() > 0 ? $operations->sum("amount_requested") : 0;
}
}
52 changes: 52 additions & 0 deletions app/Actions/App/RetrieveAppAllowedCarriers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php


namespace App\Actions\App;


use App\Models\Account;
use App\Models\AppCarrier;
use App\Models\Carrier;
use App\Models\CarrierUssd;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Lorisleiva\Actions\Concerns\AsAction;

class RetrieveAppAllowedCarriers
{
use AsAction;

public function handle(string $appAccountId): Collection
{
return $this->allowedCarriers($appAccountId);
}

private function allowedCarriers($appAccountId): Collection
{
$account = Account::where('id', '=', $appAccountId)
->select(['type', 'client_id', 'app_id'])
->first()
;

$carriers = collect();
switch ($account->type) {
case Account::$ACCOUNT_TYPE_APP:
$carriers = AppCarrier::from('app_carriers', 'ac')
->join('carriers as ca', 'ca.id', '=', 'ac.carrier_id' )
->join('carrier_ussds as cu', 'cu.carrier_id', '=', 'ac.carrier_id')
->where([
'app_id' => $account->app_id,
'activated' => true,
'ca.state' => Carrier::$ACTIVATED,
'cu.state' => CarrierUssd::$ACTIVATED
])
->select(['cu.client_ussd_format', 'ca.name', 'ca.phone_regex', 'ca.ibm', 'ca.id as carrier_id', 'ca.country'])
->get()
;
break;
case Account::$ACCOUNT_TYPE_CLIENT:
break;
}
return $carriers;
}
}
114 changes: 114 additions & 0 deletions app/Actions/Auth/ApiClientSignUp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php


namespace App\Actions\Auth;


use App\Http\Requests\ApiClientSignUpRequest;
use App\Models\Client;
use App\Repositories\Api\ApiClientAuthRepository;
use App\Responses\ApiErrorCode;
use App\Responses\ApiResponse;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\QueryException;
use Illuminate\Http\JsonResponse;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberUtil;
use Lorisleiva\Actions\Concerns\AsAction;

/**
*
* @OA\Post(
* path="/client/signup",
* tags={"auth"},
* summary="Creation d'un compte client etape 1 []",
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* required={"country_code", "phone number"},
* @OA\Property(property="country_code", description="Client's country calling code", enum={"228", "229"}),
* @OA\Property(property="phone number", description="Client's phone number"),
* )
* )
* ),
* @OA\Response(response=200, description="SUCCESS"),
* @OA\Response(response=201, description="CLIENT_AUTH_PHONE_NUMBER_NOT_VALID"),
* @OA\Response(response=202, description="CLIENT_AUTH_PHONE_NUMBER_ALREADY_EXIST"),
*
* )
*/
class ApiClientSignUp
{
use AsAction;

public function rules()
{
return [
'country_code' => ['required', 'numeric', 'min:3'],
'phone_number' => ['required', 'numeric', 'min:6'],
];
}

public function jsonResponse()
{

$countryCode = request()->input('country_code');
$phoneNumber = request()->input('phone_number');

$phoneUtil = PhoneNumberUtil::getInstance();
$parsedPhoneNumber = $phoneUtil->parse("+{$countryCode}{$phoneNumber}");
$isValid = $phoneUtil->isValidNumber($parsedPhoneNumber);

if(false == $isValid) {
return ApiResponse::create(
false,
ApiErrorCode::CLIENT_AUTH_PHONE_NUMBER_NOT_VALID
);
}

/** @noinspection LaravelFunctionsInspection */
$smsCode = env("APP_ENV") == "production" ? ApiClientAuthRepository::quickRandom() : env('DEV_SMS_CODE');

$client = $this->saveClientPhoneNumber($countryCode, $phoneNumber, $smsCode);

if (null == $client) {
return ApiResponse::create(
false,
ApiErrorCode::CLIENT_AUTH_PHONE_NUMBER_ALREADY_EXIST
);
}

# todo: send the sms

return ApiResponse::create(true);
}

/**
* @param $countryCode
* @param $phoneNumber
* @param $smsCode
* @return Client|Model|null
*/
protected function saveClientPhoneNumber($countryCode, $phoneNumber, $smsCode)
{
try {
$client = Client::firstOrNew([
'country_code' => $countryCode,
'phone_number' => $phoneNumber
], ['state' => Client::$STATE_SMS]);

if(Client::$STATE_SMS != $client->state) {
return null;
}

$client->sms_code = $smsCode;
$client->save();

return $client;
} catch (QueryException $exception) {
return null;
}
}

}
Loading