Skip to content

Commit

Permalink
🐛 Revise bookReservationDiscount
Browse files Browse the repository at this point in the history
  • Loading branch information
sheagrief committed Aug 24, 2024
1 parent f23b2ff commit 2f90188
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions contracts/LoyaltyLogicContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,40 @@ contract LoyaltyLogicContract is Ownable {
return loyaltyToken.balanceOf(_user);
}

function externalUpdateReservation(uint256 reservationId) external {
function bookReservationDiscount(
uint256 reservationId,
uint256 consumeLoyaltyPoints
) external {
IBookingContract.Reservation memory reservation = bookingContract
.reservations(reservationId);

require(
msg.sender ==
bookingContract.stores(reservation.storeId).storeAdmin,
"Only store admin can call this function"
msg.sender == reservation.customer,
"Only the customer who booked the reservation can call this function"
);

bookingContract.bookReservation(reservationId);
}

function externalUpdateReservation(
uint256 _reservationId,
uint256 _storeId,
address _customer,
uint256 _datetime,
uint256 _requiredDeposit,
uint256 _currentDeposit,
uint256 _serviceFee,
bool _paid
) external {
IBookingContract.Reservation memory reservation = bookingContract
.reservations(_reservationId);
require(
consumeLoyaltyPoints <= loyaltyToken.balanceOf(msg.sender),
"Insufficient loyalty points"
);

require(
msg.sender == reservation.customer,
"Only the customer who booked the reservation can call this function"
consumeLoyaltyPoints <= reservation.serviceFee,
"Cannot consume more points than the service fee"
);

bookingContract.updateReservation(
_reservationId,
_storeId,
_customer,
_datetime,
_requiredDeposit,
_currentDeposit,
_serviceFee,
_paid
reservationId,
reservation.storeId,
reservation.customer,
reservation.datetime,
reservation.requiredDeposit,
reservation.currentDeposit,
reservation.serviceFee - consumeLoyaltyPoints,
reservation.paid
);

this.usePoints(msg.sender, consumeLoyaltyPoints);
}

// Function to finalize payment and award loyalty points (1/20 of the service fee)
Expand Down

0 comments on commit 2f90188

Please sign in to comment.