I am developing a movie renting smart contract where the owner can add new movies, clients can search movies and pay for the movies they select. Adding and searching is working to my liking.
The problem: I want to develop the pay function as such- where it takes one argument( the title of the movie) and clients has to pay the exact amount set by the owner, he can not pay less then the price.
For example: owner add a movie: title-titanic,price-10 eth. When client use the pay function he put the title titanic and pay 10 eth. If he tries to pay less or more the transaction will not be successful.
Here is the code:
pragma solidity 0.8.7;
// SPDX-License-Identifier: MIT
contract Movie{
address public owner;
struct Move{
uint year;
uint price;
}
mapping (string => Move ) public movieInfo;
mapping(uint => Move) amount;
constructor() payable{
owner= msg.sender;
}
function addMovie(string memory _title, uint _year, uint _price) public {
require( msg.sender==owner);
movieInfo[_title]= Move(_year, _price);
}
function pay(string memory _title) public payable{
}
function totalFunds() public view returns(uint){
return address(this).balance;
}
}