Peer Tutoring Payment Contract
What it does:
Facilitates secure, on-chain payments between students and peer tutors for tutoring sessions.
Why it matters:
Ensures tutors get paid promptly, provides transparent payment tracking, and reduces disputes over fees or attendance.
How it works:
-
Student books a tutoring session and deposits payment into the smart contract
-
Tutor confirms session completion on-chain
-
Smart contract releases payment to tutor automatically
-
If session is canceled or not completed, funds can be refunded to the student according to predefined rules
-
All bookings, confirmations, and payments are recorded immutably
-
Supports multiple tutors, sessions, and variable pricing
-
Dispute resolution can be handled via DAO or admin override
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title PeerTutoringPayment
* @author Nam
* @notice Secure P2P tutoring payments with automated release
*/
contract PeerTutoringPayment {
uint256 public sessionCount;
struct Session {
address student;
address payable tutor;
uint256 amount;
bool completed;
bool paid;
bool active;
}
mapping(uint256 => Session) public sessions;
// -------------------- EVENTS --------------------
event SessionBooked(uint256 indexed sessionId, address indexed student, address indexed tutor, uint256 amount);
event SessionCompleted(uint256 indexed sessionId, address indexed tutor);
event PaymentReleased(uint256 indexed sessionId, address indexed tutor, uint256 amount);
event SessionCancelled(uint256 indexed sessionId, address indexed student);
// -------------------- SESSION MANAGEMENT --------------------
function bookSession(address payable _tutor) external payable {
require(_tutor != address(0), "Invalid tutor");
require(msg.value > 0, "Payment required");
sessionCount += 1;
sessions[sessionCount] = Session({
student: msg.sender,
tutor: _tutor,
amount: msg.value,
completed: false,
paid: false,
active: true
});
emit SessionBooked(sessionCount, msg.sender, _tutor, msg.value);
}
function completeSession(uint256 _sessionId) external {
Session storage s = sessions[_sessionId];
require(msg.sender == s.tutor, "Not tutor");
require(s.active, "Session inactive");
require(!s.completed, "Already completed");
s.completed = true;
emit SessionCompleted(_sessionId, msg.sender);
}
function releasePayment(uint256 _sessionId) external {
Session storage s = sessions[_sessionId];
require(s.completed, "Session not completed");
require(!s.paid, "Already paid");
s.paid = true;
s.active = false;
s.tutor.transfer(s.amount);
emit PaymentReleased(_sessionId, s.tutor, s.amount);
}
function cancelSession(uint256 _sessionId) external {
Session storage s = sessions[_sessionId];
require(msg.sender == s.student, "Not student");
require(!s.paid, "Already paid");
require(s.active, "Session inactive");
s.active = false;
payable(s.student).transfer(s.amount);
emit SessionCancelled(_sessionId, msg.sender);
}
// -------------------- FUNDING RECEIVED --------------------
receive() external payable {}
}