BillingRouter
Inherits: Initializable, ContextUpgradeable, HubOwnableUUPSUpgradeable, ERC165Upgradeable, IBillingRouter
Author: Daniel Yamagata & Jerry Qi
A contract for sending and paying invoices
This contract uses ContextUpgradeable to allow for future versions to use a gas relayer if desired
State Variables
BillingRouterStorageLocation
bytes32 private constant BillingRouterStorageLocation =
0x37f3f3ea6bd3134a12f955ddfd4147e5790b22caaa1c2898646a2bd9d6b60b00;
Functions
_getBillingRouterStorage
function _getBillingRouterStorage() internal pure returns (BillingRouterStorage storage $);
onlyVendor
Reverts if the caller is not the vendor of 'invoiceId' or if the invoice does not exist
modifier onlyVendor(bytes32 invoiceId);
constructor
constructor(address _mezzHub) HubOwnableUUPSUpgradeable(_mezzHub);
sendInvoice
Sends an invoice to a billable party. Returns the invoice ID
Anyone can pay the invoice on behalf of the billable party
function sendInvoice(
address billableParty,
address denominationAsset,
uint256 amount,
uint256 dueDate,
bytes32 categoryId,
string memory description,
string memory documentName,
string memory documentUri
) external virtual pausable returns (bytes32);
Parameters
billableParty
address
The address of the billable party
denominationAsset
address
The address of the denomination asset used for the invoice
amount
uint256
The amount of the denomination asset to be paid
dueDate
uint256
The due date of the invoice. Must be in the future
categoryId
bytes32
The category ID of the invoice. Should be the keccak256 hash of the category name. For example, the category ID of "Transportation Services" is keccak256("Transportation Services")
description
string
The description of the invoice
documentName
string
The name of the document associated with the invoice
documentUri
string
The URI of the document associated with the invoice
Returns
<none>
bytes32
The ID of the invoice
payInvoice
Pays the invoice with 'invoiceId'
The amount paid to the vendor may be different from the amount specified in the invoice. This is due to some ERC20s having fees built into the transfer function of ERC20s.
function payInvoice(bytes32 invoiceId) external virtual freezable returns (uint256);
Parameters
invoiceId
bytes32
The ID of the invoice to be paid
Returns
<none>
uint256
The amount of the denomination asset paid to the vendor
cancelInvoice
Cancels the invoice with 'invoiceId'
Can only be called by the invoice's vendor
function cancelInvoice(bytes32 invoiceId) external virtual onlyVendor(invoiceId) pausable;
Parameters
invoiceId
bytes32
The ID of the invoice to be cancelled
updateInvoiceDocument
Updates the document related to the invoice with 'invoiceId' in the Document Registry
Can only be called by the invoice's vendor
function updateInvoiceDocument(bytes32 invoiceId, string memory updatedDocumentName, string memory updatedDocumentUri)
external
virtual
onlyVendor(invoiceId)
returns (uint256);
Parameters
invoiceId
bytes32
The ID of the invoice whose document is to be updated
updatedDocumentName
string
The updated name of the document
updatedDocumentUri
string
The updated URI of the document
Returns
<none>
uint256
The new version of the document
hashInvoice
Returns the ID of an invoice given the invoice's parameters
The description hash can be queried via event emission
function hashInvoice(
address vendor,
address billableParty,
address denominationAsset,
uint256 amount,
uint256 dueDate,
bytes32 categoryId,
bytes32 descriptionHash
) public pure returns (bytes32);
isInvoicePaid
Returns true if the invoice with 'invoiceId' has been paid, false otherwise
function isInvoicePaid(bytes32 invoiceId) external view returns (bool);
isInvoicePastDue
Returns true if the invoice with 'invoiceId' is past due, false otherwise
function isInvoicePastDue(bytes32 invoiceId) external view returns (bool);
getInvoiceById
Returns the invoice with 'invoiceId' as a DataTypes.Invoice struct
function getInvoiceById(bytes32 invoiceId) external view returns (DataTypes.Invoice memory);
_validateDenominationAsset
Reverts if 'denominationAsset' is invalid
function _validateDenominationAsset(address denominationAsset) internal view virtual;
_validateCallerIsVendor
function _validateCallerIsVendor(bytes32 invoiceId) internal view virtual;
_validateInvoiceExists
function _validateInvoiceExists(bytes32 invoiceId) internal view virtual;
supportsInterface
ERC165 support
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC165Upgradeable, IERC165)
returns (bool);
Structs
BillingRouterStorage
struct BillingRouterStorage {
mapping(bytes32 => DataTypes.Invoice) _invoiceById;
}