mintTicketPayable
// Some code
```remix-solidity
/**
MintTicketPayable: Mint tickets for the specified recipients, events, access levels, and amounts, collecting payment in Ether.
@param _to: Array of recipient addresses for whom tickets are to be minted.
@param _eventIds: Array of event IDs for which tickets are to be minted.
@param _accessLevels: Array of access levels associated with the tickets being minted.
@param _amounts: Array of amounts of tickets to be minted for each recipient.
Format: to, eventIds, accessLevels, amounts
*/
function mintTicketPayable(
address[] calldata _to,
string[] calldata _eventIds,
string[] calldata _accessLevels,
uint256[] calldata _amounts
) public payable nonReentrant {
// Check if the lengths of input arrays match
if (!checkLengths(_to, _eventIds, _accessLevels, _amounts))
revert DecastGating__UnmatchedArrayLength();
// Initialize variable to store total collected amount
uint256 totalCollectedAmount = 0;
// Iterate through each recipient
for (uint256 i = 0; i < _to.length; ++i) {
// Get the token ID for the specified event and access level
uint256 _tokenId = getTokenIdOfAccessLevel(
_eventIds[i],
_accessLevels[i]
);
// Check if the ticket price is not 0 and the amount is valid
if (getTicketPriceFromTokenId(_tokenId) == 0)
revert DecastGating__UnMatchedInputAmount();
if (_amounts[i] <= 0) revert DecastGating__InvalidInputAmount();
// Check if the token ID exists for the specified event
if (!checkTokenIdExistsForEventId(_eventIds[i], _tokenId))
revert DecastGating__TokenIdDoesNotExists();
// Calculate and accumulate the total amount to be collected
totalCollectedAmount +=
getTicketPriceFromTokenId(_tokenId) *
_amounts[i];
// Update collected amount for the event ID
s_collectedAmountForEventId[_eventIds[i]] +=
_amounts[i] *
getTicketPriceFromTokenId(_tokenId);
// Mint the ticket
_mintTicket(_eventIds[i], _to[i], _tokenId, _amounts[i]);
}
// Check if the total collected amount matches the sent Ether value
if (totalCollectedAmount != msg.value)
revert DecastGating__UnMatchedAccumulatedAmount();
}
```Explanation:
Last updated