@@ -20,6 +20,9 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
2020 /// @notice The amount to pay for a subscription in wei.
2121 uint256 public amountToPayInWei;
2222
23+ /// @notice The address where the payment funds will be sent.
24+ address public paymentFundsRecipient;
25+
2326 /**
2427 * @notice Emitted when a user deposits funds to purchase service time.
2528 * @param user Address that sent the payment.
@@ -33,10 +36,19 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
3336 /// @param newExpirationTime the new expiration time in seconds
3437 event PaymentExpirationTimeUpdated (uint256 indexed newExpirationTime );
3538
36- /// @notice Event emitted when the payment expiration time is updated
39+ /// @notice Event emitted when the amount to pay for subscription is updated
3740 /// @param newAmountToPay the new amount to pay for a subscription in wei.
3841 event AmountToPayUpdated (uint256 indexed newAmountToPay );
3942
43+ /// @notice Event emitted when the funds recipient is updated
44+ /// @param newFundsRecipient the new address for receiving the funds on withdrawal.
45+ event FundsRecipientUpdated (address indexed newFundsRecipient );
46+
47+ /// @notice Event emitted when the balance is withdrawn to the recipient address
48+ /// @param recipient the address where the funds will be sent
49+ /// @param amount the amont send to the recipient address
50+ event FundsWithdrawn (address indexed recipient , uint256 amount );
51+
4052 error InvalidDepositAmount (uint256 amountReceived , uint256 amountRequired );
4153
4254 /**
@@ -50,13 +62,14 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
5062 * @notice Initializes the contract and transfers ownership to the provided address.
5163 * @param _owner Address that becomes the contract owner.
5264 */
53- function initialize (address _owner ) public initializer {
65+ function initialize (address _owner , address _paymentFundsRecipient ) public initializer {
5466 __Ownable_init ();
5567 __UUPSUpgradeable_init ();
5668 _transferOwnership (_owner);
5769
5870 paymentExpirationTimeSeconds = PAYMENT_VALID_UNTIL_SECONDS;
5971 amountToPayInWei = 1000000000000000000 ; // 1 ETH
72+ paymentFundsRecipient = _paymentFundsRecipient;
6073 }
6174
6275 /**
@@ -70,7 +83,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
7083 {}
7184
7285 /**
73- * @notice Ensures only the owner can authorize upgrades.
86+ * @notice Sets the new expiration time. Only callable by the owner
7487 * @param newExpirationTimeInSeconds The new expiration time for the users payments in seconds.
7588 */
7689 function setPaymentExpirationTimeSeconds (uint256 newExpirationTimeInSeconds ) public onlyOwner () {
@@ -80,7 +93,17 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
8093 }
8194
8295 /**
83- * @notice Ensures only the owner can authorize upgrades.
96+ * @notice Sets the new amount to pay. Only callable by the owner
97+ * @param newRecipient The new address for receiving the funds on withdrawal.
98+ */
99+ function setFundsRecipientAddress (address newRecipient ) public onlyOwner () {
100+ paymentFundsRecipient = newRecipient;
101+
102+ emit FundsRecipientUpdated (newRecipient);
103+ }
104+
105+ /**
106+ * @notice Sets the new amount to pay. Only callable by the owner
84107 * @param newAmountToPay The new amount to pay for subscription in wei.
85108 */
86109 function setAmountToPay (uint256 newAmountToPay ) public onlyOwner () {
@@ -101,4 +124,13 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
101124
102125 emit UserPayment (msg .sender , amount, block .timestamp , block .timestamp + paymentExpirationTimeSeconds);
103126 }
127+
128+ /**
129+ * @notice Withdraws the contract balance to the recipient address.
130+ */
131+ function withdraw () external onlyOwner {
132+ uint256 balance = address (this ).balance;
133+ payable (paymentFundsRecipient).transfer (balance);
134+ emit FundsWithdrawn (paymentFundsRecipient, balance);
135+ }
104136}
0 commit comments