Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ability to select tickets unrelated to your order #20

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ For any questions or clarifications, feel free to reach out to us at [security@h

## Hi.Events Public Key

if you need to send us encrypted information, you can use our public key below:
If you need to send us encrypted information, you can use our public key below:

```plaintext

Expand Down Expand Up @@ -101,4 +101,4 @@ URSFSI5iNr0JSvCYNmzsDB6zSSlR/UvgRFM1SRUoG3sygmV32Onh0EzU

---

Hi.Events Team
Hi.Events Team
19 changes: 19 additions & 0 deletions backend/app/Services/Handlers/Order/CompleteOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private function createAttendees(Collection $attendees, OrderDomainObject $order
values: $attendees->pluck('ticket_price_id')->toArray(),
);

$this->validateTicketPriceIdsMatchOrder($order, $ticketsPrices);

foreach ($attendees as $attendee) {
$ticketId = $ticketsPrices->first(
fn(TicketPriceDomainObject $ticketPrice) => $ticketPrice->getId() === $attendee->ticket_price_id)
Expand Down Expand Up @@ -238,4 +240,21 @@ private function updateOrder(OrderDomainObject $order, CompleteOrderOrderDTO $or
]
);
}

/**
* Check if the passed ticket price IDs match what exist in the order_items table
*
* @throws ResourceConflictException
*/
private function validateTicketPriceIdsMatchOrder(OrderDomainObject $order, Collection $ticketsPrices): void
{
$orderTicketPriceIds = $order->getOrderItems()
?->map(fn(OrderItemDomainObject $orderItem) => $orderItem->getTicketPriceId())->toArray();

$ticketsPricesIds = $ticketsPrices->map(fn(TicketPriceDomainObject $ticketPrice) => $ticketPrice->getId());

if ($ticketsPricesIds->diff($orderTicketPriceIds)->isNotEmpty()) {
throw new ResourceConflictException(__('There is an unexpected ticket price ID in the order'));
}
}
}
Loading