Skip to content

Commit

Permalink
Merge pull request #69 from openfoodfoundation/feature/multiple-merch…
Browse files Browse the repository at this point in the history
…ants

Feature: Multiple merchant shops on voucher sets
  • Loading branch information
ok200paul authored Nov 7, 2024
2 parents 4cc9f73 + 4ed5318 commit 389b895
Show file tree
Hide file tree
Showing 14 changed files with 1,019 additions and 808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function store(): JsonResponse
'email' => [
'required',
'email',
'email:rfc,dns'
'email:rfc,dns',
],
'current_team_id' => [
'sometimes',
Expand Down
31 changes: 31 additions & 0 deletions app/Http/Controllers/Api/V1/ApiVoucherRedemptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,36 @@ public function index(): JsonResponse
status : 200,
description: '',
)]
#[Response(
content : '{"meta":{"responseCode":400,"limit":50,"offset":0,"message":"Invalid merchant team."},"data":{}',
status : 400,
description: 'Shown when the team that the redeeming user is not valid for this voucher under redemption. Merchant team might not have approved their involvement yet.',
)]
#[Response(
content : '{"meta":{"responseCode":400,"limit":50,"offset":0,"message":"This voucher has already been fully redeemed, no redemption made this time."},"data":{}',
status : 400,
description: 'Voucher fully redeemed. No redemption takes place',
)]
#[Response(
content : '{"meta":{"responseCode":400,"limit":50,"offset":0,"message":"Requested amount is greater than voucher value remaining, no redemption made this time."},"data":{}',
status : 400,
description: 'Voucher redemption amount too high',
)]
#[Response(
content : '{"meta":{"responseCode":404,"limit":50,"offset":0,"message":"Not found."},"data":{}',
status : 404,
description: '',
)]
#[Response(
content : '{"meta":{"responseCode":429,"limit":50,"offset":0,"message":"Too many redemption attempts, please wait."},"data":{}',
status : 429,
description: 'Too many redemption requests. Only 1 redemption may be made per voucher per minute.',
)]
#[Response(
content : '{"meta":{"responseCode":500,"limit":50,"offset":0,"message":"Error"},"data":{}',
status : 500,
description: 'Server Error',
)]
public function store(): JsonResponse
{
$validationArray = [
Expand Down Expand Up @@ -109,6 +139,7 @@ public function store(): JsonResponse
* Ensure the users current team is a merchant for the voucher set.
*/
$voucherSetMerchantTeamIds = VoucherSetMerchantTeam::where('voucher_set_id', $voucherSetId)
->whereNotNull('voucher_set_merchant_team_approval_request_id')
->pluck('merchant_team_id')
->unique()
->toArray();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function share(Request $request): array

return [
...parent::share($request),
'auth' => [
'auth' => [
'user' => $request->user(),
'currentTeam' => $team,
'availableTeams' => TeamUser::with('team')->where('user_id', Auth::id())->get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Events\VoucherSetMerchantTeamApprovalRequest\VoucherSetMerchantTeamApprovalRequestWasApproved;
use App\Models\User;
use App\Models\VoucherSetMerchantTeam;
use App\Notifications\Slack\VoucherSetMerchantTeamApprovalRequest\VoucherSetMerchantTeamApprovalRequestApprovedNotification;
use App\Services\AuditItemService;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -24,8 +25,27 @@ public function __construct() {}
*/
public function handle(VoucherSetMerchantTeamApprovalRequestWasApproved $event): void
{
$user = User::first();

/**
* Mark the participating merchant team with the ID of the approval
*/
$voucherSetMerchantTeam = VoucherSetMerchantTeam::where(
column : 'voucher_set_id',
operator: $event->voucherSetMerchantTeamApprovalRequest->voucher_set_id
)->where(
column : 'merchant_team_id',
operator: $event->voucherSetMerchantTeamApprovalRequest->merchant_team_id
)->first();

if ($voucherSetMerchantTeam) {
$voucherSetMerchantTeam->voucher_set_merchant_team_approval_request_id = $event->voucherSetMerchantTeamApprovalRequest->id;
$voucherSetMerchantTeam->save();
}

/**
* Notify the user
*/
$user = User::first();
$user->notify(new VoucherSetMerchantTeamApprovalRequestApprovedNotification($event->voucherSetMerchantTeamApprovalRequest));

AuditItemService::createAuditItemForEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Notifications\Mail\VoucherSetMerchantTeamApprovalRequest;

use App\Models\Team;
use App\Models\User;
use App\Models\VoucherSet;
use App\Models\VoucherSetMerchantTeamApprovalRequest;
Expand Down Expand Up @@ -66,11 +67,14 @@ public function toMail(object $notifiable): MailMessage
]
)->find($this->voucherSetMerchantTeamApprovalRequest->voucher_set_id);

$merchantTeam = Team::find($this->voucherSetMerchantTeamApprovalRequest->merchant_team_id);

return (new MailMessage())
->subject('A Vine voucher set is about to be been generated that may be redeemed at your shop')
->markdown('mail.voucher-set-approval-request', [
'voucherSetId' => $this->voucherSetMerchantTeamApprovalRequest->voucher_set_id,
'voucherSet' => $voucherSet,
'merchantTeam' => $merchantTeam,
'createdBy' => $voucherSet->createdByTeam->name,
'approve' => $urlApprove,
'reject' => $urlReject,
Expand Down
Loading

0 comments on commit 389b895

Please sign in to comment.