Skip to content

Commit

Permalink
Updated voucher generation process to handle colloquial currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ok200paul committed Sep 30, 2024
1 parent ef20346 commit 6d8c434
Show file tree
Hide file tree
Showing 73 changed files with 468 additions and 452 deletions.
39 changes: 18 additions & 21 deletions app/Http/Controllers/Api/V1/Admin/ApiAdminVoucherSetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function index(): JsonResponse
public function store(): JsonResponse
{
$validationArray = [
'is_test' => [
'is_test' => [
'required',
'boolean',
],
Expand All @@ -205,39 +205,39 @@ public function store(): JsonResponse
'integer',
Rule::exists('teams', 'id'),
],
'merchant_team_ids' => [
'merchant_team_ids' => [
'required',
'array',
],
'merchant_team_ids.*' => [
'merchant_team_ids.*' => [
'integer',
Rule::exists('teams', 'id'),
],
'funded_by_team_id' => [
'funded_by_team_id' => [
'sometimes',
'nullable',
'integer',
Rule::exists('teams', 'id'),
],
'voucher_template_id' => [
'voucher_template_id' => [
'required',
'integer',
Rule::exists('voucher_templates', 'id'),
],
'total_set_value' => [
'total_set_value' => [
'required',
'integer',
],
'denominations' => [
'denominations' => [
'required',
'array',
],
'expires_at' => [
'expires_at' => [
'sometimes',
'string',
'nullable',
],
'voucher_set_type' => [
'voucher_set_type' => [
'required',
'string',
],
Expand All @@ -249,7 +249,7 @@ public function store(): JsonResponse

$this->responseCode = 400;
$this->message = $validator->errors()
->first();
->first();

return $this->respond();

Expand All @@ -260,8 +260,7 @@ public function store(): JsonResponse
/**
* Ensure the API user has a country against their current team.
*/
if(!isset(Auth::user()->currentTeam->country_id))
{
if (!isset(Auth::user()->currentTeam->country_id)) {
$this->message = ApiResponse::RESPONSE_INVALID_TEAM->value;
$this->responseCode = 400;

Expand All @@ -278,8 +277,8 @@ public function store(): JsonResponse
* Get the service team's merchants list as an array of IDs
*/
$teamMerchantTeams = TeamMerchantTeam::where('team_id', $serviceTeamId)
->pluck('merchant_team_id')
->toArray();
->pluck('merchant_team_id')
->toArray();

/**
* Validate that the merchant ID are all merchants for the service team.
Expand Down Expand Up @@ -331,9 +330,9 @@ public function store(): JsonResponse
}
}

$model->created_by_user_id = Auth::id();
$model->created_by_team_id = Auth::user()->current_team_id;
$model->currency_country_id = Auth::user()->currentTeam?->country_id;
$model->created_by_user_id = Auth::id();
$model->created_by_team_id = Auth::user()->current_team_id;
$model->currency_country_id = Auth::user()->currentTeam->country_id;
$model->save();

foreach ($merchantTeamIds as $merchantTeamId) {
Expand All @@ -348,8 +347,7 @@ public function store(): JsonResponse

DB::commit();

}
catch (Exception $e) {
} catch (Exception $e) {

DB::rollBack();

Expand Down Expand Up @@ -465,8 +463,7 @@ public function destroy(string $id)
$model->delete();
$this->message = ApiResponse::RESPONSE_DELETED->value;

}
catch (Exception $e) {
} catch (Exception $e) {

$this->responseCode = 500;
$this->message = ApiResponse::RESPONSE_ERROR->value . ':' . $e->getMessage();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d8c434

Please sign in to comment.