API Reference

This section provides auto-generated references for public modules, classes, and helper functions in django-solana-payments.

Core Services

VerifyTransactionService

SolanaPaymentsService

OneTimeWalletService

class django_solana_payments.services.one_time_wallet_service.OneTimeWalletService

Bases: object

generate_one_time_wallet_and_encrypt_if_needed() tuple[Keypair, str]

Generates one-time wallet on-chain and encrypts if ONE_TIME_WALLETS_ENCRYPTION_ENABLED=True

create_one_time_wallet(should_create_atas: bool = True) tuple[Keypair, str, OneTimePaymentWallet]

Creates a record for one time wallet and associated token addresses if needed

close_one_time_wallet_atas(one_time_wallet: OneTimePaymentWallet, rent_receiver_address: Pubkey, max_atas_per_tx: int = 8) bool

Closes all empty associated token accounts (ATAs) for a one-time wallet and recovers rent to recipient_address.

close_expired_one_time_wallets(sleep_interval_seconds: float | int | None = None)

Close all one-time Solana wallets that are: - in PAYMENT_EXPIRED state (linked payment expired).

Main wallet service functions

Additional Service Modules

django_solana_payments.services.one_time_wallet_service.get_one_time_wallet_service() OneTimeWalletService

Get or create a singleton instance of OneTimeWalletService. This allows for easier testing and mocking.

Usage examples:

# In production code
service = get_one_time_wallet_service()
wallet = service.create_one_time_wallet()

# In tests, reset before each test
reset_one_time_wallet_service()
service = get_one_time_wallet_service()

# Or mock the factory function
with patch("module.get_one_time_wallet_service") as mock:
    mock.return_value = YourMockService()
django_solana_payments.services.one_time_wallet_service.reset_one_time_wallet_service()

Reset the singleton instance. Useful for testing.

Models

AbstractPaymentToken

class django_solana_payments.models.AbstractPaymentToken(*args, **kwargs)

Bases: Model

clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

save(*args, **kwargs)

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

AbstractSolanaPayment

class django_solana_payments.models.AbstractSolanaPayment(*args, **kwargs)

Bases: Model

Concrete models

class django_solana_payments.models.PaymentCryptoToken(id, is_active, token_type, mint_address, payment_crypto_price, created, updated, name, symbol, meta_data)
exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
class django_solana_payments.models.SolanaPayPaymentCryptoPrice(id, amount_in_crypto, token, meta_data, created, updated)
exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
class django_solana_payments.models.OneTimePaymentWallet(id, keypair_json, state, receiver_address, created, updated)
exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
class django_solana_payments.models.SolanaPayment(id, payment_address, one_time_payment_wallet, paid_token, status, signature, expiration_date, meta_data, created, updated, user, email, label, message)
exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated

API Layer

Views

Serializers

Helpers

Dynamically resolves the related_name for a field on the SolanaPayment model.

Signals

Core Types and Exceptions

class django_solana_payments.choices.SolanaPaymentStatusTypes(*values)
class django_solana_payments.choices.OneTimeWalletStateTypes(*values)
class django_solana_payments.choices.TokenTypes(*values)
exception django_solana_payments.solana.exceptions.BaseSolanaClientException

Base exception for the solana client

Solana Clients

django_solana_payments.solana.utils.parse_keypair(keypair_data: Any) Keypair

Parse a keypair provided in multiple supported formats and return a solders.keypair.Keypair.

Supported input formats: - JSON array string: “[1,2,3,…,64]” (string starting with ‘[‘) - Base58 string: e.g. “5J3mBb…” - Python list or bytes: [1,2,3,…] or b”…”

Raises ValueError on unsupported/invalid input.

django_solana_payments.solana.utils.derive_pubkey_string_from_keypair(keypair_data: Any) str

Derive a base58 pubkey string from various forms of keypair input.

This function is resilient: it first tries to obtain a real Keypair via parse_keypair() and returns its pubkey. If parsing to a Keypair fails but the input looks like a JSON array of ints, it deterministically derives a 32-byte value from SHA-256 of the bytes and returns its base58 representation as a fallback Pubkey. This is useful for tests or placeholder values where a real keypair isn’t available.

Admin

Admin classes are registered in django_solana_payments.admin and require django.contrib.admin to be present in INSTALLED_APPS.