cryptopaymentintent

package
v1.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func RequiredConfirmationsForChain

func RequiredConfirmationsForChain(chain Chain) int

RequiredConfirmationsForChain returns the default confirmation count.

Types

type Chain

type Chain string

Chain represents a supported blockchain.

const (
	Ethereum Chain = "ethereum"
	Solana   Chain = "solana"
	Base     Chain = "base"
	Polygon  Chain = "polygon"
	Arbitrum Chain = "arbitrum"
)

type CryptoPaymentIntent

type CryptoPaymentIntent struct {
	mixin.Model[CryptoPaymentIntent]

	// Amount in smallest unit of settlement currency (cents for USD)
	Amount int64 `json:"amount"`

	// Settlement currency (fiat, e.g., "usd")
	Currency string `json:"currency" orm:"default:usd"`

	// Blockchain where deposit is expected
	Chain Chain `json:"chain"`

	// Token on the chain (e.g., "usdc", "usdt", "eth")
	Token string `json:"token"`

	// Per-payment deposit address (generated by custody service)
	DepositAddress string `json:"depositAddress"`

	// Customer reference
	CustomerRef string `json:"customerRef,omitempty"`

	// Current status
	Status Status `json:"status" orm:"default:pending"`

	// Number of confirmations received
	Confirmations int `json:"confirmations"`

	// Number of confirmations required
	RequiredConfirmations int `json:"requiredConfirmations"`

	// On-chain transaction hash (once detected)
	TxHash string `json:"txHash,omitempty"`

	// Block number where deposit was included
	BlockNumber int64 `json:"blockNumber,omitempty"`

	// Payment expiry (typically 30-60 minutes)
	ExpiresAt time.Time `json:"expiresAt"`

	// Fiat-equivalent amount after conversion
	SettlementAmount int64 `json:"settlementAmount"`

	// Settlement currency
	SettlementCurrency string `json:"settlementCurrency" orm:"default:usd"`

	// Exchange rate at time of settlement
	ExchangeRate string `json:"exchangeRate,omitempty"`

	// Crypto amount in token's smallest unit (wei, lamports, etc.)
	CryptoAmount string `json:"cryptoAmount,omitempty"`

	// Refund transaction hash (if refunded)
	RefundTxHash string `json:"refundTxHash,omitempty"`

	// OFAC screening result
	ScreeningStatus string `json:"screeningStatus,omitempty"` // clear, flagged, blocked

	Metadata Map `json:"metadata,omitempty" orm:"default:{}"`
}

CryptoPaymentIntent represents a custodial crypto/stablecoin payment flow.

func (*CryptoPaymentIntent) AddConfirmation

func (cpi *CryptoPaymentIntent) AddConfirmation()

AddConfirmation records a new block confirmation.

func (*CryptoPaymentIntent) Defaults

func (cpi *CryptoPaymentIntent) Defaults()

Defaults sets runtime-computed defaults that cannot be expressed as struct tags.

func (*CryptoPaymentIntent) IsExpired

func (cpi *CryptoPaymentIntent) IsExpired() bool

IsExpired returns true if the payment window has closed.

func (*CryptoPaymentIntent) IsFullyConfirmed

func (cpi *CryptoPaymentIntent) IsFullyConfirmed() bool

IsFullyConfirmed returns true if required confirmations are met.

func (*CryptoPaymentIntent) MarkConfirming

func (cpi *CryptoPaymentIntent) MarkConfirming(txHash string, blockNumber int64) error

MarkConfirming transitions to confirming state when deposit is detected.

func (*CryptoPaymentIntent) MarkExpired

func (cpi *CryptoPaymentIntent) MarkExpired() error

MarkExpired transitions to expired if no deposit received.

func (*CryptoPaymentIntent) MarkFailed

func (cpi *CryptoPaymentIntent) MarkFailed(reason string) error

MarkFailed transitions to failed (e.g., reorg caused loss).

func (*CryptoPaymentIntent) MarkSucceeded

func (cpi *CryptoPaymentIntent) MarkSucceeded(settlementAmount int64, exchangeRate string) error

MarkSucceeded transitions to succeeded after full confirmation.

type Status

type Status string

Status represents the lifecycle state of a crypto payment.

const (
	Pending    Status = "pending"    // Awaiting deposit
	Confirming Status = "confirming" // Deposit detected, awaiting confirmations
	Succeeded  Status = "succeeded"  // Fully confirmed + settled
	Expired    Status = "expired"    // No deposit received before timeout
	Failed     Status = "failed"     // Deposit failed (reorg, etc.)
	Refunded   Status = "refunded"   // Refund issued on-chain
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL