X402.Extensions.PaymentIdentifier.Cache behaviour (X402 v0.3.3)

Copy Markdown View Source

Behaviour and adapter helpers for payment identifier idempotency caches.

Cache adapters are configured as {module, cache} tuples where module implements this behaviour and cache is adapter-specific runtime state (for example, a pid or registered process name).

Summary

Types

Adapter tuple accepted by X402.Plug.PaymentGate.

Result returned by get/2.

Payment identifier cache key.

Value stored for a given payment identifier.

Result returned by write/delete operations.

Functions

Deletes a cached value for a payment identifier.

Reads a cached value for a payment identifier.

Stores a cached value for a payment identifier.

Validates a cache adapter tuple for NimbleOptions custom validation.

Validates an optional cache adapter for NimbleOptions.

Types

adapter()

@type adapter() :: {module(), term()}

Adapter tuple accepted by X402.Plug.PaymentGate.

get_result()

@type get_result() :: {:hit, value()} | :miss | {:error, term()}

Result returned by get/2.

key()

Payment identifier cache key.

value()

@type value() :: :verified | {:rejected, term()}

Value stored for a given payment identifier.

write_result()

@type write_result() :: :ok | {:error, term()}

Result returned by write/delete operations.

Callbacks

delete(cache, key)

@callback delete(cache :: term(), key()) :: write_result()

get(cache, key)

@callback get(cache :: term(), key()) :: get_result()

put(cache, key, value)

@callback put(cache :: term(), key(), value()) :: write_result()

Functions

delete(arg1, payment_id)

(since 0.1.0)
@spec delete(adapter(), key()) :: write_result()

Deletes a cached value for a payment identifier.

get(arg1, payment_id)

(since 0.1.0)
@spec get(adapter(), key()) :: get_result()

Reads a cached value for a payment identifier.

put(arg1, payment_id, value)

(since 0.1.0)
@spec put(adapter(), key(), value()) :: write_result()

Stores a cached value for a payment identifier.

validate_adapter(arg1)

(since 0.1.0)
@spec validate_adapter(term()) :: :ok | {:error, String.t()}

Validates a cache adapter tuple for NimbleOptions custom validation.

validate_optional_adapter(adapter)

(since 0.1.0)
@spec validate_optional_adapter(term()) :: :ok | {:error, String.t()}

Validates an optional cache adapter for NimbleOptions.

nil disables idempotency caching.