I am getting an Invalid Opcode error while calling the refundAmount function which will refund the amount to the customer and cancel his/her ticket bookings. registrations is a structure mapping and the structure includes 3 variables that are in the below manner.
struct Registration {
uint8 noOfTickets;
uint amount;
string email;
}
address payable public owner;
uint public ticketsSold;
uint8 public totalTickets;
uint public price;
mapping (address => Registration) public registrations;
The below is the refundAmount function. I could have used msg.sender for this but my javascript takes care of it by using the coinbase address.
function refundAmount(address payable _customer)
external
payable {
if(registrations[_customer].amount > 0){
if(address(this).balance >= registrations[_customer].amount) {
ticketsSold = ticketsSold - registrations[_customer].noOfTickets;
registrations[_customer].noOfTickets = 0;
registrations[_customer].email = " ";
uint refundCustAmount = registrations[_customer].amount;
registrations[_customer].amount = 0;
_customer.transfer(refundCustAmount);
emit Refund(_customer, refundCustAmount);
}
}
Please help me. Thank you in advance and Cheers to Ethereum!!
Edit: - This works completely fine on Rinkeby testnet but reverts while using Ganache.