Payment Kit Standard
The Sui Payment Kit is a framework for secure, flexible payment processing on Sui. It provides persistent and ephemeral payment options, event-driven architecture, and built-in duplicate prevention.
The Payment Kit standardizes payment processing on Sui, enabling developers to build robust payment flows without reimplementing common payment verification and receipt management logic. Applications using the Payment Kit benefit from battle-tested security patterns and consistent payment handling across the ecosystem.
Key features
The Payment Kit provides the following core capabilities:
- Secure payment processing: Validates payment amounts and transfers coins safely.
- Payment registries: Optional persistent storage for payment receipts with duplicate detection.
- Flexible receipt management: Generates receipts for payment tracking and verification.
- Event-driven architecture: Emits events for offchain tracking and integration.
- Multi-coin support: Works with any Sui coin type.
- Transaction URIs: Standardized URI format to create encoded links for user-friendly payment flows.
Architecture components
The Payment Kit consists of the following main components:
Payment processing core
Handles coin transfers, payment validation, and receipt generation. The core validates that:
- Payment amounts match expected values
- Coins have sufficient balance
- Transfers complete successfully
- Receipts contain accurate payment information
Registry system
Optional persistent storage that tracks payment history and prevents duplicate payments. Registries provide:
- Payment record storage keyed by a composite
PaymentKeyof nonce, amount, coin type, and receiver - Configurable expiration policies for payment records
- Withdrawal capabilities for accumulated funds
- Administrative controls through capabilities
Core concepts
What payment modes does Payment Kit support?
The Payment Kit supports two payment processing modes:
1. Registry payments: Process payments through a PaymentRegistry with duplicate prevention and persistent receipts. Use this mode when:
- You need to prevent duplicate payments
- Payment history must be tracked
- Compliance or auditing requires payment records
- Funds should accumulate in a managed registry
2. Ephemeral payments: Process one-time payments without persistent storage.
- Duplicate prevention is not enforced
How does Payment Kit prevent duplicate payments?
Duplicate prevention is enforced when processing payments through a PaymentRegistry. The system uses a composite PaymentKey derived from:
- Nonce: Unique identifier for each payment
(UUIDv4). - Amount: Payment value in coin units.
- Coin type: The specific coin type, carried as the phantom type parameter
TofPaymentKey<T>rather than as a field. - Receiver address: Destination address for the payment.
This composite key ensures that the same payment cannot be processed twice, even if individual components (like amount or receiver) are reused across different payments.
How do I retry a payment safely?
Derive a stable nonce for each logical payment (for example, one per purchase) and reuse that same nonce on every retry. The registry aborts with EDuplicatePayment when it sees a repeated composite key (nonce, amount, coin type, receiver), so a retry that reuses the nonce cannot be credited twice. Generating a fresh nonce on retry creates a new composite key, which turns the retry into a second payment. Use a UUIDv4 nonce, which fits within the 36-character limit.
Payment receipts
Every processed payment generates a PaymentReceipt object containing:
- Payment nonce for reference
- Amount paid
- Coin type used
- Receiver address
- Timestamp of payment
- Registry information (for registry payments; not applicable to ephemeral payments)
Receipts serve as proof of payment and can be used for offchain verification, accounting, or integration with other systems.
Payment records
When payments are processed through a PaymentRegistry, the system creates and stores PaymentRecord objects internally to track payment history and enable duplicate prevention.
Payment records differ from payment receipts in key ways:
PaymentRecords vs PaymentReceipts:
PaymentRecords: Internal registry storage structures that persist payment metadata for duplicate detection. These are stored within the registry's internal tables and are not directly accessible as objects.PaymentReceipts: User-facing objects returned after payment processing that serve as proof of payment. These can be stored, transferred, or used for offchain verification.
PaymentRecord lifecycle:
- Creation: When
process_registry_paymentis called, aPaymentRecordis created and stored in the registry using the compositePaymentKey. - Storage: Records persist in the registry's internal table, indexed by their unique payment key.
- Expiration: Records become eligible for deletion after the registry's configured
epoch_expiration_durationhas passed. - Deletion: Expired records can be removed using
delete_payment_recordto reclaim storage and reduce gas costs.
PaymentRecord expiration:
A PaymentRecord includes an expiration epoch calculated at the time of payment creation. This expiration mechanism:
- Prevents indefinite storage growth in registries
- Allows for eventual cleanup of historical payment data
- Balances duplicate prevention needs with storage efficiency
- Can be configured per-registry through
set_config_epoch_expiration_duration
A PaymentRecord cannot be deleted before its expiration epoch, ensuring a minimum retention period for duplicate detection. After expiration, administrators or users can delete records to free storage, though deletion is optional.