From cef6d86d0f841cd8b4ccbcc38c1f2edaffa9fddb Mon Sep 17 00:00:00 2001 From: Djery-Tom Date: Wed, 27 Oct 2021 13:48:07 +0100 Subject: [PATCH] Add endpoints to validate and reject subscription --- .env.example | 2 + app/Events/InsuranceEvent.php | 31 +++++ app/Events/InsuranceSubscribed.php | 21 ---- app/Exceptions/Handler.php | 4 + app/Http/Controllers/InsuranceController.php | 106 +++++++++++++++--- app/InsuranceSubscriptionState.php | 1 + app/Listeners/NotifyUser.php | 27 +++-- .../NhInsurancesSubscriptionsHistory.php | 6 +- app/Providers/EventServiceProvider.php | 4 +- app/Traits/Helper.php | 20 ++++ bootstrap/app.php | 4 +- composer.json | 5 +- config/sentry.php | 57 ++++++++++ ...s_in_nh_insurances_subscriptions_table.php | 36 ++++++ ...insurances_subscriptions_history_table.php | 35 ++++++ resources/lang/en/errors.php | 2 +- resources/lang/en/messages.php | 27 ++++- resources/lang/fr/errors.php | 2 +- resources/lang/fr/messages.php | 27 ++++- routes/web.php | 12 +- 20 files changed, 368 insertions(+), 61 deletions(-) create mode 100644 app/Events/InsuranceEvent.php delete mode 100644 app/Events/InsuranceSubscribed.php create mode 100644 config/sentry.php create mode 100644 database/migrations/2021_10_26_213917_add_due_dates_in_nh_insurances_subscriptions_table.php create mode 100644 database/migrations/2021_10_26_231840_update_actor_in_nh_insurances_subscriptions_history_table.php diff --git a/.env.example b/.env.example index 7d96d1a..1e84e37 100644 --- a/.env.example +++ b/.env.example @@ -26,3 +26,5 @@ NOTIFICATION_SERVICE_KEY=RfXvPQzQRgwpzQYPnLfWpZzgx4QseHlg SWAGGER_GENERATE_ALWAYS=true SWAGGER_DOCS_TOKEN=ZfMqCAdHHrSH8ADdXreIejgjJtOwsH4K +SENTRY_LARAVEL_DSN=https://cb0057643b0c4ce5805e49b5b54bd5c3@o1053292.ingest.sentry.io/6037678 +SENTRY_TRACES_SAMPLE_RATE=1 diff --git a/app/Events/InsuranceEvent.php b/app/Events/InsuranceEvent.php new file mode 100644 index 0000000..f8740f2 --- /dev/null +++ b/app/Events/InsuranceEvent.php @@ -0,0 +1,31 @@ +subscription = $subscription; + $this->mailTitle = $mailTitle; + $this->mailMessage = $mailMessage; + $this->notification = $notification; + } +} diff --git a/app/Events/InsuranceSubscribed.php b/app/Events/InsuranceSubscribed.php deleted file mode 100644 index 8f075d0..0000000 --- a/app/Events/InsuranceSubscribed.php +++ /dev/null @@ -1,21 +0,0 @@ -subscription = $subscription; - } -} diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 6c6f4f2..b1120a0 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -44,6 +44,10 @@ class Handler extends ExceptionHandler */ public function report(Throwable $exception) { + if (app()->bound('sentry') && $this->shouldReport($exception)) { + app('sentry')->captureException($exception); + } + parent::report($exception); } diff --git a/app/Http/Controllers/InsuranceController.php b/app/Http/Controllers/InsuranceController.php index 10efc3a..97731f1 100644 --- a/app/Http/Controllers/InsuranceController.php +++ b/app/Http/Controllers/InsuranceController.php @@ -2,7 +2,8 @@ namespace App\Http\Controllers; -use App\Events\InsuranceSubscribed; +use App\Events\InsuranceEvent; +use App\Events\InsuranceSubscriptionAccepted; use App\InsuranceSubscriptionState; use App\Models\CountriesCurrency; use App\Models\Identification; @@ -36,15 +37,15 @@ class InsuranceController extends Controller /** * @OA\Get( - * path="/insurances/countries/{countryId}", - * summary="Afficher la liste des assurances d'un pays", + * path="/insurances", + * summary="Afficher la liste des assurances ( par pays )", * tags={"Assurances"}, * security={{"api_key":{}}}, * @OA\Parameter( - * parameter="countryId", - * name="countryId", + * parameter="country_id", + * name="country_id", * description="ID du pays", - * in="path", + * in="query", * required=true, * @OA\Schema( * type="integer", @@ -66,13 +67,17 @@ class InsuranceController extends Controller * ) * ) */ - public function getInsurancesByCountryId($countryId) + public function getInsurances(Request $request) { - $country = CountriesCurrency::findOrFail($countryId); + $this->validate($request, [ + 'country_id' => 'nullable|integer|exists:countries,id' + ]); + + $country = CountriesCurrency::findOrFail($request->input('country_id')); $insurances = DB::select("SELECT n.id , n.name , nhc.age_limit_of_insured_and_spouse, nhc.age_limit_of_child_beneficiary, nhc.max_number_of_beneficiaries, nhc.id as nhc_id FROM networks n JOIN configWallet cw ON cw.id_network = n.id JOIN nh_networks_configs nhc - ON nhc.network_id = n.id WHERE n.country_id = :countryId AND cw.type = 'ilink_sante' AND n.status = 1", ['countryId' => $countryId]); + ON nhc.network_id = n.id WHERE n.country_id = :countryId AND cw.type = 'ilink_sante' AND n.status = 1", ['countryId' => $request->input('country_id')]); foreach ($insurances as $insurance) { $months_prices = DB::select("SELECT id, number_of_months , min_amount FROM nh_months_prices_grid WHERE nh_network_config_id = :nhc_id", @@ -90,7 +95,7 @@ class InsuranceController extends Controller /** * @OA\Post( - * path="/insurances/bonus-amount", + * path="/insurances/subscriptions/bonus-amount", * summary="Calculer le montant de la prime", * tags={"Assurances"}, * security={{"api_key":{}}}, @@ -134,7 +139,7 @@ class InsuranceController extends Controller $this->validate($request, [ 'network_id' => 'required|integer|exists:networks,id', 'month_price_id' => 'required|integer|exists:nh_months_prices_grid,id', - 'beneficiaries' => 'required|array', + 'beneficiaries' => 'nullable|array', 'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today', 'beneficiaries.*.affiliation' => 'required|in:CHILD,SPOUSE' ]); @@ -182,7 +187,7 @@ class InsuranceController extends Controller /** * @OA\Post( - * path="/insurances/subscribe", + * path="/insurances/subscriptions", * summary="Souscrire à une assurance", * tags={"Assurances"}, * security={{"api_key":{}}}, @@ -315,7 +320,7 @@ class InsuranceController extends Controller 'user_id' => 'required|integer|exists:users,id', 'password' => 'required|string', 'month_price_id' => 'required|integer|exists:nh_months_prices_grid,id', - 'beneficiaries' => 'required|array', + 'beneficiaries' => 'nullable|array', 'beneficiaries.*.lastname' => 'required|string', 'beneficiaries.*.gender' => 'required|in:M,F', 'beneficiaries.*.birthdate' => 'required|date_format:Y-m-d|before:today', @@ -341,8 +346,8 @@ class InsuranceController extends Controller return $this->errorResponse(trans('errors.nano_health_not_activated')); // Verification de l'age du beneficiaire - $insuredAge = date_diff(date_create($identification->birthdate), date_create('now'))->y; - if ($insuredAge < $networkConfig->age_limit_of_insured_and_spouse) { + $insuredAge = date_diff(date_create($identification->birth_date), date_create('now'))->y; + if ($insuredAge > $networkConfig->age_limit_of_insured_and_spouse) { return $this->errorResponse(trans('errors.minimal_age_required')); } @@ -384,7 +389,8 @@ class InsuranceController extends Controller ]); - Event::dispatch(new InsuranceSubscribed($subscription)); + Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription'), trans('messages.insurance_subscription_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id, + 'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries]))); DB::commit(); return $this->successResponse(trans('messages.successful_transaction')); @@ -398,7 +404,7 @@ class InsuranceController extends Controller /** * @OA\Post( - * path="/insurances/upload-images", + * path="/insurances/subscriptions/upload-images", * summary="Uploader les images de l'assurance", * tags={"Assurances"}, * security={{"api_key":{}}}, @@ -445,6 +451,72 @@ class InsuranceController extends Controller return $this->successResponse($files); } + public function validateSubscription($id, Request $request) + { + $this->validate($request, [ + 'agent_id' => 'required|integer|exists:agents,id' + ]); + + try { + DB::beginTransaction(); + $subscription = NhInsurancesSubscription::findOrFail($id); + $subscription->state = InsuranceSubscriptionState::ACCEPTED; + $subscription->save(); + + NhInsurancesSubscriptionsHistory::create([ + 'action' => 'EDIT', + 'insurance_subscription_id' => $subscription->insurance_subscription_id, + 'insurance_subscription_state' => $subscription->state, + 'agent_id' => $request->input('agent_id'), + 'insurance_subscription' => json_encode($subscription) + ]); + + Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_accepted'), trans('messages.insurance_subscription_accepted_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id, + 'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'user_code' => $subscription->user->user_code, + 'number_of_beneficiaries' => $subscription->number_of_beneficiaries]), trans('messages.insurance_subscription_accepted_notification', ['subscription_id' => $subscription->insurance_subscription_id]))); + DB::commit(); + return $this->successResponse(trans('messages.successful_transaction')); + } catch (Throwable $e) { + Log::error($e->getMessage() . '\n' . $e->getTraceAsString()); + DB::rollBack(); + return $this->errorResponse(trans('errors.unexpected_error'), 500); + } + } + + public function rejectSubscription($id, Request $request) + { + $this->validate($request, [ + 'agent_id' => 'required|integer|exists:agents,id', + 'reason' => 'required' + ]); + + try { + DB::beginTransaction(); + $subscription = NhInsurancesSubscription::findOrFail($id); + $subscription->reason = $request->input('reason'); + $subscription->state = InsuranceSubscriptionState::REJECTED; + $subscription->save(); + + NhInsurancesSubscriptionsHistory::create([ + 'action' => 'EDIT', + 'insurance_subscription_id' => $subscription->insurance_subscription_id, + 'insurance_subscription_state' => $subscription->state, + 'agent_id' => $request->input('agent_id'), + 'insurance_subscription' => json_encode($subscription) + ]); + + Event::dispatch(new InsuranceEvent($subscription, trans('messages.insurance_subscription_rejected'), trans('messages.insurance_subscription_rejected_mail', ['name' => $subscription->user->lastname, 'subscription_id' => $subscription->insurance_subscription_id, + 'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'reason' => $request->input('reason'), + 'number_of_beneficiaries' => $subscription->number_of_beneficiaries]), trans('messages.insurance_subscription_rejected_notification', ['subscription_id' => $subscription->insurance_subscription_id]))); + DB::commit(); + return $this->successResponse(trans('messages.successful_transaction')); + } catch (Throwable $e) { + Log::error($e->getMessage() . '\n' . $e->getTraceAsString()); + DB::rollBack(); + return $this->errorResponse(trans('errors.unexpected_error'), 500); + } + } + private function generateSubscriptionID(): string { do { diff --git a/app/InsuranceSubscriptionState.php b/app/InsuranceSubscriptionState.php index dcc4664..c24941d 100644 --- a/app/InsuranceSubscriptionState.php +++ b/app/InsuranceSubscriptionState.php @@ -7,6 +7,7 @@ abstract class InsuranceSubscriptionState const UNDER_VALIDATION = 'UNDER_VALIDATION'; const ACCEPTED = 'ACCEPTED'; const REJECTED = 'REJECTED'; + const CURRENT = 'CURRENT'; const UNDER_STOPPING = 'UNDER_STOPPING'; const STOPPED = 'STOPPED'; } diff --git a/app/Listeners/NotifyUser.php b/app/Listeners/NotifyUser.php index 926c4c3..865f5e7 100644 --- a/app/Listeners/NotifyUser.php +++ b/app/Listeners/NotifyUser.php @@ -3,7 +3,7 @@ namespace App\Listeners; use App\Events\ExampleEvent; -use App\Events\InsuranceSubscribed; +use App\Events\InsuranceEvent; use App\Traits\Helper; use GuzzleHttp\Client; use Illuminate\Contracts\Queue\ShouldQueue; @@ -28,10 +28,10 @@ class NotifyUser /** * Handle the event. * - * @param InsuranceSubscribed $event + * @param InsuranceEvent $event * @return void */ - public function handle(InsuranceSubscribed $event) + public function handle(InsuranceEvent $event) { // $subscription = $event->subscription; @@ -44,12 +44,25 @@ class NotifyUser 'Authorization' => config('services.notification_service.key'), ]; $body = new \stdClass(); - $body->title = trans('messages.insurance_subscription'); - $body->message = trans('messages.insurance_subscription_mail', ['name' => $user->lastname, 'subscription_id' => $subscription->insurance_subscription_id, - 'bonus_amount' => $this->toMoneyWithNetwork($subscription->total_bonus_amount, $subscription->network_id), 'number_of_beneficiaries' => $subscription->number_of_beneficiaries]); + $body->title = $event->mailTitle; + $body->message = $event->mailMessage; $body->email = $user->email; - $response = $client->request('POST', '/send-mail', ['json' => $body, 'headers' => $headers]); + $client->request('POST', '/send-mail', ['json' => $body, 'headers' => $headers]); + + if (isset($event->notification)) { + $body = new \stdClass(); + $body->user_code = $user->user_code; + $body->message = $event->notification; + $body->data = []; + try { + $body->date = $this->getCurrentTimeByCountryCode($user->network->country->code_country); + } catch (Throwable $t) { + Log::error($t->getMessage()); + $body->date = date('Y-m-d H:i:s'); + } + $client->request('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers]); + } } catch (Throwable $t) { Log::error('-------- User notification not sent-----------'); Log::error($t->getMessage() . '\n' . $t->getTraceAsString()); diff --git a/app/Models/NhInsurancesSubscriptionsHistory.php b/app/Models/NhInsurancesSubscriptionsHistory.php index f37111f..5a92da5 100644 --- a/app/Models/NhInsurancesSubscriptionsHistory.php +++ b/app/Models/NhInsurancesSubscriptionsHistory.php @@ -15,7 +15,7 @@ use Illuminate\Database\Eloquent\Model; * @property int $id * @property string $action * @property string $insurance_subscription_id - * @property int|null $nh_validating_doctor_id + * @property int|null $agent_id * @property string $insurance_subscription_state * @property string $insurance_subscription * @property Carbon $created_at @@ -28,13 +28,13 @@ class NhInsurancesSubscriptionsHistory extends Model protected $table = 'nh_insurances_subscriptions_history'; protected $casts = [ - 'nh_validating_doctor_id' => 'int' + 'agent_id' => 'int' ]; protected $fillable = [ 'action', 'insurance_subscription_id', - 'nh_validating_doctor_id', + 'agent_id', 'insurance_subscription_state', 'insurance_subscription' ]; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b9fa6ce..474e0c0 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,7 +2,7 @@ namespace App\Providers; -use App\Events\InsuranceSubscribed; +use App\Events\InsuranceEvent; use App\Listeners\NotifyUser; use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider; @@ -17,7 +17,7 @@ class EventServiceProvider extends ServiceProvider \App\Events\ExampleEvent::class => [ \App\Listeners\ExampleListener::class, ], - InsuranceSubscribed::class => [ + InsuranceEvent::class => [ NotifyUser::class ] ]; diff --git a/app/Traits/Helper.php b/app/Traits/Helper.php index 468f623..61bcabf 100644 --- a/app/Traits/Helper.php +++ b/app/Traits/Helper.php @@ -4,6 +4,7 @@ namespace App\Traits; +use App\Models\CountriesCurrency; use App\Models\Country; use Brick\Money\Context\AutoContext; use Brick\Money\Money; @@ -101,4 +102,23 @@ trait Helper // Return compressed image return $destination; } + + // Obtenir l'heure en fonction du pays de l'utilisateur + public function getCurrentTime($id_country) + { + $country = CountriesCurrency::find($id_country); + $country_code = isset($country) ? $country->code_country : 'GA'; + $timezone = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $country_code); + $date = (sizeof($timezone) > 0) ? new \DateTime('now', new \DateTimeZone($timezone[0])) : new \DateTime(); + return $date->format('Y-m-d H:i:s'); + } + + // Obtenir l'heure en fonction du code du pays de l'utilisateur + public function getCurrentTimeByCountryCode($country_code = 'GA') + { + $timezone = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $country_code); + $date = (sizeof($timezone) > 0) ? new \DateTime('now', new \DateTimeZone($timezone[0])) : new \DateTime(); + return $date->format('Y-m-d H:i:s'); + } + } diff --git a/bootstrap/app.php b/bootstrap/app.php index d44e64f..862ff6f 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -62,6 +62,7 @@ $app->singleton( $app->configure('app'); $app->configure('swagger-lume'); $app->configure('services'); +$app->configure('sentry'); /* |-------------------------------------------------------------------------- @@ -100,7 +101,8 @@ $app->configure('services'); $app->register(App\Providers\EventServiceProvider::class); $app->register(\SwaggerLume\ServiceProvider::class); $app->register(\MigrationsGenerator\MigrationsGeneratorServiceProvider::class); - +$app->register('Sentry\Laravel\ServiceProvider'); +$app->register('Sentry\Laravel\Tracing\ServiceProvider'); /* |-------------------------------------------------------------------------- diff --git a/composer.json b/composer.json index 9d2a810..b2f78ad 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,14 @@ "type": "project", "require": { "php": "^7.3|^8.0", + "ext-gd": "*", + "ext-json": "*", "brick/money": "^0.5.2", "darkaonline/swagger-lume": "^8.0", "guzzlehttp/guzzle": "^7.3", "kitloong/laravel-migrations-generator": "^5.0", "laravel/lumen-framework": "^8.0", - "ext-json": "*", - "ext-gd": "*" + "sentry/sentry-laravel": "^2.9" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/config/sentry.php b/config/sentry.php new file mode 100644 index 0000000..0f2c2e1 --- /dev/null +++ b/config/sentry.php @@ -0,0 +1,57 @@ + env('SENTRY_LARAVEL_DSN', env('SENTRY_DSN')), + + // capture release as git sha + // 'release' => trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')), + + // When left empty or `null` the Laravel environment will be used + 'environment' => env('SENTRY_ENVIRONMENT'), + + 'breadcrumbs' => [ + // Capture Laravel logs in breadcrumbs + 'logs' => true, + + // Capture SQL queries in breadcrumbs + 'sql_queries' => true, + + // Capture bindings on SQL queries logged in breadcrumbs + 'sql_bindings' => true, + + // Capture queue job information in breadcrumbs + 'queue_info' => true, + + // Capture command information in breadcrumbs + 'command_info' => true, + ], + + 'tracing' => [ + // Trace queue jobs as their own transactions + 'queue_job_transactions' => env('SENTRY_TRACE_QUEUE_ENABLED', false), + + // Capture queue jobs as spans when executed on the sync driver + 'queue_jobs' => true, + + // Capture SQL queries as spans + 'sql_queries' => true, + + // Try to find out where the SQL query originated from and add it to the query spans + 'sql_origin' => true, + + // Capture views as spans + 'views' => true, + + // Indicates if the tracing integrations supplied by Sentry should be loaded + 'default_integrations' => true, + ], + + // @see: https://docs.sentry.io/platforms/php/configuration/options/#send-default-pii + 'send_default_pii' => false, + + 'traces_sample_rate' => (float)(env('SENTRY_TRACES_SAMPLE_RATE', 0.0)), + + 'controllers_base_namespace' => env('SENTRY_CONTROLLERS_BASE_NAMESPACE', 'App\\Http\\Controllers'), + +]; diff --git a/database/migrations/2021_10_26_213917_add_due_dates_in_nh_insurances_subscriptions_table.php b/database/migrations/2021_10_26_213917_add_due_dates_in_nh_insurances_subscriptions_table.php new file mode 100644 index 0000000..0c2d685 --- /dev/null +++ b/database/migrations/2021_10_26_213917_add_due_dates_in_nh_insurances_subscriptions_table.php @@ -0,0 +1,36 @@ +dateTime('start_at')->nullable()->after('state')->comment("Date de debut de l'assurance"); + $table->dateTime('end_at')->nullable()->after('start_at')->comment("Date d'echeance"); + $table->text('reason')->nullable()->after('end_at')->comment("Raison de traitement de la subscription"); + DB::statement("ALTER TABLE nh_insurances_subscriptions MODIFY state + ENUM('UNDER_VALIDATION', 'ACCEPTED', 'REJECTED', 'UNDER_STOPPING', 'STOPPED', 'CURRENT') DEFAULT 'UNDER_VALIDATION' NOT NULL;"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_insurances_subscriptions', function (Blueprint $table) { + $table->dropColumn(['start_at', 'end_at', 'reason']); + }); + } +} diff --git a/database/migrations/2021_10_26_231840_update_actor_in_nh_insurances_subscriptions_history_table.php b/database/migrations/2021_10_26_231840_update_actor_in_nh_insurances_subscriptions_history_table.php new file mode 100644 index 0000000..e290d1a --- /dev/null +++ b/database/migrations/2021_10_26_231840_update_actor_in_nh_insurances_subscriptions_history_table.php @@ -0,0 +1,35 @@ +dropColumn('nh_validating_doctor_id'); + $table->integer('agent_id')->nullable()->after('insurance_subscription_id') + ->comment("ID de l'agent acteur de l'operation"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('nh_insurances_subscriptions_history', function (Blueprint $table) { + $table->integer('nh_validating_doctor_id')->nullable(); + $table->dropColumn('agent_id'); + }); + } +} diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php index 7a1e086..267db08 100755 --- a/resources/lang/en/errors.php +++ b/resources/lang/en/errors.php @@ -25,5 +25,5 @@ return [ 'nano_health_not_activated' => "Nano health is not activated for this network", 'number_of_beneficiaries_exceeded' => 'The number of beneficiaries is greater than the authorized limit', 'incorrect_selected_amount' => 'The amount selected is incorrect', - 'minimal_age_required' => "You do not have the minimum age required to subscribe to this insurance" + 'minimal_age_required' => "Your age is above the age limit required to subscribe to this insurance" ]; diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index e8ef5f7..1fb241f 100755 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -24,5 +24,30 @@ Your subscription request is being validated. - ID: :subscription_id - Bonus amount: :bonus_amount - Number of beneficiaries: :number_of_beneficiaries - " + ", + 'insurance_subscription_accepted' => "Insurance subscription accepted", + 'insurance_subscription_accepted_mail' => "Mr/Mrs :name , + +Your application has been accepted. + Application information : + - ID: :subscription_id + - Policyholder number: :user_code + - Amount to be paid: :bonus_amount + - Number of beneficiaries : :number_of_beneficiaries + + Make sure your wallet has enough credit to activate your insurance by payment. + ", + 'insurance_subscription_accepted_notification' => "Your :subscription_id application has been accepted. + Please ensure that your wallet has sufficient credit to activate your insurance", + 'insurance_subscription_rejected' => "Insurance subscription rejected", + 'insurance_subscription_rejected_mail' => "Mr/Mrs :name , + +Your application has been rejected. + Application information : + - ID: :subscription_id + - Premium amount: :bonus_amount + - Number of beneficiaries : :number_of_beneficiaries + + Reason for rejection: :reason ", + 'insurance_subscription_rejected_notification' => "Your :subscription_id application has been rejected" ]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php index b25cb3a..2aed9f9 100755 --- a/resources/lang/fr/errors.php +++ b/resources/lang/fr/errors.php @@ -25,5 +25,5 @@ return [ 'nano_health_not_activated' => "Le nano santé n'est pas activé pour ce réseau", 'number_of_beneficiaries_exceeded' => "Le nombre d'ayant droit est superieur à la limite autorisée", 'incorrect_selected_amount' => 'Le montant choisi est incorrect', - 'minimal_age_required' => "Vous n'avez pas l'âge minimum requis pour souscrire à cette assurance" + 'minimal_age_required' => "Votre âge est supérieur à l'âge limite requis pour souscrire à cette assurance" ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index f9dd6ed..6ec55d6 100755 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -24,5 +24,30 @@ Votre demande de souscription est en cours de validation. - ID : :subscription_id - Montant de la prime : :bonus_amount - Nombre d'ayants droit : :number_of_beneficiaries - " + ", + 'insurance_subscription_accepted' => "Souscription à l'assurance acceptée", + 'insurance_subscription_accepted_mail' => "M/Mme :name , + +Votre demande de souscription a été acceptée. + Informations de la demande : + - ID : :subscription_id + - Numéro d'assuré : :user_code + - Montant à payer : :bonus_amount + - Nombre d'ayants droit : :number_of_beneficiaries + + Assurer-vous que votre wallet a le crédit suffisant pour activer votre assurance par le payement. + ", + 'insurance_subscription_accepted_notification' => "Votre demande de souscription :subscription_id a été acceptée. + Assurer-vous que votre wallet a le crédit suffisant pour activer votre assurance", + 'insurance_subscription_rejected' => "Souscription à l'assurance rejetée", + 'insurance_subscription_rejected_mail' => "M/Mme :name , + +Votre demande de souscription a été rejetée. + Informations de la demande : + - ID : :subscription_id + - Montant de la prime : :bonus_amount + - Nombre d'ayants droit : :number_of_beneficiaries + + Motif du rejet : :reason ", + 'insurance_subscription_rejected_notification' => "Votre demande de souscription :subscription_id a été rejetée.", ]; diff --git a/routes/web.php b/routes/web.php index 69f15dc..598a7d8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -15,9 +15,13 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($router) { // Insurances routes $router->group(['prefix' => '/insurances'], function () use ($router) { - $router->get('countries/{countryId}', 'InsuranceController@getInsurancesByCountryId'); - $router->post('bonus-amount', 'InsuranceController@calculateBonusAmount'); - $router->post('subscribe', 'InsuranceController@subscribe'); - $router->post('upload-images', 'InsuranceController@uploadImages'); + $router->get('', 'InsuranceController@getInsurances'); + $router->group(['prefix' => '/subscriptions'], function () use ($router) { + $router->post('bonus-amount', 'InsuranceController@calculateBonusAmount'); + $router->post('upload-images', 'InsuranceController@uploadImages'); + $router->post('', 'InsuranceController@subscribe'); + $router->put('{id}/validate', 'InsuranceController@validateSubscription'); + $router->put('{id}/reject', 'InsuranceController@rejectSubscription'); + }); }); });