A robust Clarity smart contract for scheduling and managing vendor payments on the Stacks blockchain.
This contract enables organizations to schedule future payments to vendors, manage payment authorization, and track payment history. It provides a secure, transparent system for handling recurring or scheduled vendor payments with multi-user access control.
- Schedule Payments: Create payment schedules with vendor address, amount, due date, and description
- Execute Payments: Process payments automatically when due date is reached
- Update Payments: Modify payment amounts or due dates before execution
- Cancel Payments: Deactivate scheduled payments that are no longer needed
- Batch Processing: Execute multiple payments (up to 20) in a single transaction
- Owner Privileges: Contract deployer has full administrative control
- Authorized Payers: Delegate payment execution rights to trusted addresses
- Emergency Pause: Stop all contract operations in case of emergency
- Anti-Double Payment: Prevents duplicate payment execution
- Validation Guards: Comprehensive checks on amounts, dates, and statuses
- Vendor Balances: Track total amounts paid and payment counts per vendor
- Payment History: Full audit trail with creation and execution timestamps
- Payment Status: Monitor active, paid, and cancelled payments
payments: Stores all payment schedules with detailsvendor-balances: Aggregates payment statistics per vendorauthorized-payers: Manages payer authorization status
u100: Owner-only operationu101: Payment not foundu102: Unauthorized accessu103: Invalid amount (must be > 0)u104: Invalid date (must be in future)u105: Payment already executedu106: Insufficient balanceu107: Payment not yet dueu108: Record already existsu109: Contract paused or payment inactive
(authorize-payer (payer principal))Grant payment execution rights to an address. Owner only.
(revoke-payer (payer principal))Remove payment execution rights from an address. Owner only.
(toggle-contract-pause)Pause or unpause all contract operations. Owner only.
(schedule-payment (vendor principal) (amount uint) (due-date uint) (description (string-ascii 256)))Create a new scheduled payment. Returns payment ID. Requires authorization.
Parameters:
vendor: Recipient's principal addressamount: Payment amount in microSTX (1 STX = 1,000,000 microSTX)due-date: Block height when payment becomes executabledescription: Payment description (max 256 characters)
(execute-payment (payment-id uint))Process a scheduled payment and transfer STX to vendor. Requires authorization.
Conditions:
- Payment must exist and be active
- Current block height ≥ due date
- Payment must not be already paid
- Caller must have sufficient STX balance
(cancel-payment (payment-id uint))Deactivate a scheduled payment. Requires authorization.
(update-payment-date (payment-id uint) (new-due-date uint))Modify the due date of an unpaid payment. Requires authorization.
(update-payment-amount (payment-id uint) (new-amount uint))Modify the amount of an unpaid payment. Requires authorization.
(batch-execute-payments (payment-ids (list 20 uint)))Execute multiple payments in one transaction (max 20). Requires authorization.
(get-payment (payment-id uint))Retrieve complete payment details.
(get-vendor-balance (vendor principal))Get total paid amount and payment count for a vendor.
(is-payment-due (payment-id uint))Check if a payment is ready for execution.
(is-payer-authorized (payer principal))Verify if an address has payment execution rights.
(get-contract-paused)Check if contract operations are paused.
(get-next-payment-id)Get the next available payment ID.
The deployer automatically becomes the contract owner.
(contract-call? .vendor-payment-scheduler authorize-payer 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM)(contract-call? .vendor-payment-scheduler schedule-payment
'ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC
u5000000 ;; 5 STX
u1000 ;; Block height 1000
"Monthly hosting services"
)(contract-call? .vendor-payment-scheduler execute-payment u0)- Authorization: Always verify authorized payers before granting access
- Pause Mechanism: Use toggle-contract-pause in emergencies
- STX Balance: Ensure sufficient balance before executing payments
- Due Date Validation: Payments can only be executed after due date
- Immutable Paid Status: Once paid, payments cannot be modified
- Set Realistic Due Dates: Consider blockchain confirmation times
- Batch When Possible: Use batch-execute-payments for gas efficiency
- Monitor Vendor Balances: Track spending per vendor
- Regular Audits: Review scheduled payments periodically
- Test on Testnet: Always test payment flows before mainnet deployment