Documentation
¶
Index ¶
- Constants
- func IsSOL(currency string) bool
- func MintAddress(currency string, fallback string) string
- func ReferenceAccountNotificationListener(service PaymentService, enq eventsEnqueuer) events.Listener
- func TransactionCreatedListener(service PaymentService, enq eventsEnqueuer) events.Listener
- func UpdateTransactionStatusListener(service PaymentService) events.Listener
- type Config
- type Enqueuer
- type EnqueuerOption
- type Logger
- type Payment
- type PaymentBuilder
- type PaymentService
- type PaymentStatus
- type ReferencePayload
- type Scheduler
- type Service
- func (s *Service) BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error)
- func (s *Service) CancelPayment(ctx context.Context, id uuid.UUID) error
- func (s *Service) CancelPaymentByExternalID(ctx context.Context, externalID string) error
- func (s *Service) CreatePayment(ctx context.Context, payment *Payment) (*Payment, error)
- func (s *Service) GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error)
- func (s *Service) GetPayment(ctx context.Context, id uuid.UUID) (*Payment, error)
- func (s *Service) GetPaymentByExternalID(ctx context.Context, externalID string) (*Payment, error)
- func (s *Service) GetPendingTransactions(ctx context.Context) ([]*Transaction, error)
- func (s *Service) GetTransactionByReference(ctx context.Context, reference string) (*Transaction, error)
- func (s *Service) MarkPaymentsAsExpired(ctx context.Context) error
- func (s *Service) MarkTransactionsAsExpired(ctx context.Context) error
- func (s *Service) UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error
- func (s *Service) UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, ...) error
- type ServiceEvents
- func (s *ServiceEvents) BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error)
- func (s *ServiceEvents) CancelPayment(ctx context.Context, id uuid.UUID) error
- func (s *ServiceEvents) CancelPaymentByExternalID(ctx context.Context, externalID string) error
- func (s *ServiceEvents) CreatePayment(ctx context.Context, payment *Payment) (*Payment, error)
- func (s *ServiceEvents) GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error)
- func (s *ServiceEvents) UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error
- func (s *ServiceEvents) UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, ...) error
- type ServiceLogger
- func (s *ServiceLogger) BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error)
- func (s *ServiceLogger) CancelPayment(ctx context.Context, id uuid.UUID) error
- func (s *ServiceLogger) CancelPaymentByExternalID(ctx context.Context, externalID string) error
- func (s *ServiceLogger) CreatePayment(ctx context.Context, payment *Payment) (*Payment, error)
- func (s *ServiceLogger) GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error)
- func (s *ServiceLogger) GetPayment(ctx context.Context, id uuid.UUID) (*Payment, error)
- func (s *ServiceLogger) GetPaymentByExternalID(ctx context.Context, externalID string) (*Payment, error)
- func (s *ServiceLogger) GetPendingTransactions(ctx context.Context) ([]*Transaction, error)
- func (s *ServiceLogger) GetTransactionByReference(ctx context.Context, reference string) (*Transaction, error)
- func (s *ServiceLogger) MarkPaymentsAsExpired(ctx context.Context) error
- func (s *ServiceLogger) MarkTransactionsAsExpired(ctx context.Context) error
- func (s *ServiceLogger) UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error
- func (s *ServiceLogger) UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, ...) error
- type Transaction
- type TransactionStatus
- type Worker
- func (w *Worker) CheckPaymentByReference(ctx context.Context, t *asynq.Task) error
- func (w *Worker) CheckPendingTransactions(ctx context.Context, t *asynq.Task) error
- func (w *Worker) MarkPaymentsAsExpired(ctx context.Context, t *asynq.Task) error
- func (w *Worker) MarkTransactionsAsExpired(ctx context.Context, t *asynq.Task) error
- func (w *Worker) Register(mux *asynq.ServeMux)
Constants ¶
const ( SOL = "So11111111111111111111111111111111111111112" USDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" USDT = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" )
const ( TastMarkPaymentsAsExpired = "mark_payments_as_expired" TaskCheckPaymentByReference = "check_payment_by_reference" TaskMarkTransactionsAsExpired = "mark_transactions_as_expired" TaskCheckPendingTransactions = "check_pending_transactions" )
Task names.
Variables ¶
This section is empty.
Functions ¶
func MintAddress ¶
MintAddress returns the mint address by symbol. If the symbol is not found, it returns the fallback address. Supports only default mints.
func ReferenceAccountNotificationListener ¶
func ReferenceAccountNotificationListener(service PaymentService, enq eventsEnqueuer) events.Listener
ReferenceAccountNotificationListener is a listener for the transaction.reference.notification event.
func TransactionCreatedListener ¶
func TransactionCreatedListener(service PaymentService, enq eventsEnqueuer) events.Listener
TransactionCreatedListener is a listener for the transaction.created event.
func UpdateTransactionStatusListener ¶
func UpdateTransactionStatusListener(service PaymentService) events.Listener
UpdateTransactionStatusListener is a listener for the transaction.updated event.
Types ¶
type Config ¶
type Config struct { ApplyBonus bool BonusMintAddress string BonusAuthAccount string MaxApplyBonusAmount uint64 MaxApplyBonusPercent uint16 // 10000 = 100%, 100 = 1%, 1 = 0.01% AccrueBonus bool AccrueBonusRate uint64 DestinationMint string DestinationWallet string PaymentTTL time.Duration SolPayBaseURL string }
type Enqueuer ¶
type Enqueuer struct {
// contains filtered or unexported fields
}
Enqueuer is a helper struct for enqueuing email tasks.
func NewEnqueuer ¶
func NewEnqueuer(client *asynq.Client, opt ...EnqueuerOption) *Enqueuer
NewEnqueuer creates a new email enqueuer. This function accepts EnqueuerOption to configure the enqueuer. Default values are used if no option is provided. Default values are:
- queue name: "default"
- task deadline: 1 minute
- max retry: 3
type EnqueuerOption ¶
type EnqueuerOption func(*Enqueuer)
EnqueuerOption is a function that configures an enqueuer.
func WithQueueName ¶
func WithQueueName(name string) EnqueuerOption
WithQueueName configures the queue name.
func WithTaskDeadline ¶
func WithTaskDeadline(d time.Duration) EnqueuerOption
WithTaskDeadline configures the task deadline.
type Payment ¶
type Payment struct { ID uuid.UUID `json:"id,omitempty"` ExternalID string `json:"external_id,omitempty"` DestinationWallet string `json:"destination_wallet,omitempty"` DestinationMint string `json:"destination_mint,omitempty"` Amount uint64 `json:"amount,omitempty"` Status PaymentStatus `json:"status,omitempty"` Message string `json:"message,omitempty"` ExpiresAt *time.Time `json:"expires_at,omitempty"` }
Payment represents an initial payment request.
type PaymentBuilder ¶
type PaymentBuilder struct {
// contains filtered or unexported fields
}
PaymentBuilder is a builder for creating a payment transaction.
func NewPaymentTransactionBuilder ¶
func NewPaymentTransactionBuilder(sc solanaClient, jc jupiterClient, config Config) *PaymentBuilder
NewPaymentTransactionBuilder creates a new PaymentTransactionBuilder.
func (*PaymentBuilder) Build ¶
func (b *PaymentBuilder) Build(ctx context.Context) (string, *Transaction, error)
Build builds the payment transaction.
func (*PaymentBuilder) GetReferenceAddress ¶
func (b *PaymentBuilder) GetReferenceAddress() string
GetReferenceAddress returns the reference address.
func (*PaymentBuilder) SetTransaction ¶
func (b *PaymentBuilder) SetTransaction(tx *Transaction, p *Payment) *PaymentBuilder
SetTransaction sets the transaction.
type PaymentService ¶
type PaymentService interface { // CreatePayment creates a new payment. CreatePayment(ctx context.Context, payment *Payment) (*Payment, error) // GetPayment returns the payment with the given ID. GetPayment(ctx context.Context, id uuid.UUID) (*Payment, error) // GetPaymentByExternalID returns the payment with the given external ID. GetPaymentByExternalID(ctx context.Context, externalID string) (*Payment, error) // GeneratePaymentLink generates a new payment link for the given payment. GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error) // UpdatePaymentStatus updates the status of the payment with the given ID. UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error // CancelPayment cancels the payment with the given ID. CancelPayment(ctx context.Context, id uuid.UUID) error // CancelPaymentByExternalID cancels the payment with the given external ID. CancelPaymentByExternalID(ctx context.Context, externalID string) error // MarkPaymentsAsExpired marks all payments that are expired as expired. MarkPaymentsAsExpired(ctx context.Context) error // BuildTransaction builds a new transaction for the given payment. BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error) // GetTransactionByReference returns the transaction with the given reference. GetTransactionByReference(ctx context.Context, reference string) (*Transaction, error) // UpdateTransaction updates the status and signature of the transaction with the given reference. UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, signature string) error // GetPendingTransactions returns all pending transactions. GetPendingTransactions(ctx context.Context) ([]*Transaction, error) // MarkTransactionsAsExpired marks all transactions that are expired as expired. MarkTransactionsAsExpired(ctx context.Context) error }
PaymentService is the interface that wraps the basic payment operations.
type PaymentStatus ¶
type PaymentStatus string
PaymentStatus represents the status of a payment.
const ( PaymentStatusNew PaymentStatus = "new" PaymentStatusPending PaymentStatus = "pending" PaymentStatusCompleted PaymentStatus = "completed" PaymentStatusFailed PaymentStatus = "failed" PaymentStatusCanceled PaymentStatus = "canceled" PaymentStatusExpired PaymentStatus = "expired" )
Predefined payment statuses.
type ReferencePayload ¶
type ReferencePayload struct {
Reference string `json:"reference"`
}
Reference payload to check payment by reference task.
type Scheduler ¶
type Scheduler struct{}
Scheduler is a task scheduler for iam service.
func NewScheduler ¶
func NewScheduler() *Scheduler
NewScheduler creates a new task scheduler for iam service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
NewService creates a new payment service instance.
func (*Service) BuildTransaction ¶
func (s *Service) BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error)
BuildTransaction builds a new transaction for the given payment.
func (*Service) CancelPayment ¶
CancelPayment cancels the payment with the given ID.
func (*Service) CancelPaymentByExternalID ¶
CancelPaymentByExternalID cancels the payment with the given external ID.
func (*Service) CreatePayment ¶
CreatePayment creates a new payment.
func (*Service) GeneratePaymentLink ¶
func (s *Service) GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error)
GeneratePaymentLink generates a new payment link for the given payment.
func (*Service) GetPayment ¶
GetPayment returns the payment with the given ID.
func (*Service) GetPaymentByExternalID ¶
GetPaymentByExternalID returns the payment with the given external ID.
func (*Service) GetPendingTransactions ¶
func (s *Service) GetPendingTransactions(ctx context.Context) ([]*Transaction, error)
GetPendingTransactions returns all pending transactions.
func (*Service) GetTransactionByReference ¶
func (s *Service) GetTransactionByReference(ctx context.Context, reference string) (*Transaction, error)
GetTransactionByReference returns the transaction with the given reference.
func (*Service) MarkPaymentsAsExpired ¶
MarkPaymentsAsExpired marks all payments that are expired as expired.
func (*Service) MarkTransactionsAsExpired ¶
MarkTransactionsAsExpired marks all transactions that are expired as expired.
func (*Service) UpdatePaymentStatus ¶
func (s *Service) UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error
UpdatePaymentStatus updates the status of the payment with the given ID.
func (*Service) UpdateTransaction ¶
func (s *Service) UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, signature string) error
UpdateTransaction updates the status and signature of the transaction with the given reference.
type ServiceEvents ¶
type ServiceEvents struct { PaymentService // contains filtered or unexported fields }
func NewServiceEvents ¶
func NewServiceEvents(svc PaymentService, eventFn fireEventFunc) *ServiceEvents
func (*ServiceEvents) BuildTransaction ¶
func (s *ServiceEvents) BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error)
BuildTransaction builds a new transaction for the given payment.
func (*ServiceEvents) CancelPayment ¶
CancelPayment cancels the payment with the given ID.
func (*ServiceEvents) CancelPaymentByExternalID ¶
func (s *ServiceEvents) CancelPaymentByExternalID(ctx context.Context, externalID string) error
CancelPaymentByExternalID cancels the payment with the given external ID.
func (*ServiceEvents) CreatePayment ¶
CreatePayment creates a new payment.
func (*ServiceEvents) GeneratePaymentLink ¶
func (s *ServiceEvents) GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error)
GeneratePaymentLink generates a new payment link for the given payment.
func (*ServiceEvents) UpdatePaymentStatus ¶
func (s *ServiceEvents) UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error
UpdatePaymentStatus updates the status of the payment with the given ID.
func (*ServiceEvents) UpdateTransaction ¶
func (s *ServiceEvents) UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, signature string) error
UpdateTransaction updates the status and signature of the transaction with the given reference.
type ServiceLogger ¶
type ServiceLogger struct { PaymentService // contains filtered or unexported fields }
func NewServiceLogger ¶
func NewServiceLogger(svc PaymentService, log Logger) *ServiceLogger
func (*ServiceLogger) BuildTransaction ¶
func (s *ServiceLogger) BuildTransaction(ctx context.Context, tx *Transaction) (*Transaction, error)
BuildTransaction builds a new transaction for the given payment.
func (*ServiceLogger) CancelPayment ¶
CancelPayment cancels the payment with the given ID.
func (*ServiceLogger) CancelPaymentByExternalID ¶
func (s *ServiceLogger) CancelPaymentByExternalID(ctx context.Context, externalID string) error
CancelPaymentByExternalID cancels the payment with the given external ID.
func (*ServiceLogger) CreatePayment ¶
CreatePayment creates a new payment.
func (*ServiceLogger) GeneratePaymentLink ¶
func (s *ServiceLogger) GeneratePaymentLink(ctx context.Context, paymentID uuid.UUID, mint string, applyBonus bool) (string, error)
GeneratePaymentLink generates a new payment link for the given payment.
func (*ServiceLogger) GetPayment ¶
GetPayment returns the payment with the given ID.
func (*ServiceLogger) GetPaymentByExternalID ¶
func (s *ServiceLogger) GetPaymentByExternalID(ctx context.Context, externalID string) (*Payment, error)
GetPaymentByExternalID returns the payment with the given external ID.
func (*ServiceLogger) GetPendingTransactions ¶
func (s *ServiceLogger) GetPendingTransactions(ctx context.Context) ([]*Transaction, error)
GetPendingTransactions returns all pending transactions.
func (*ServiceLogger) GetTransactionByReference ¶
func (s *ServiceLogger) GetTransactionByReference(ctx context.Context, reference string) (*Transaction, error)
GetTransactionByReference returns the transaction with the given reference.
func (*ServiceLogger) MarkPaymentsAsExpired ¶
func (s *ServiceLogger) MarkPaymentsAsExpired(ctx context.Context) error
MarkPaymentsAsExpired marks all payments that are expired as expired.
func (*ServiceLogger) MarkTransactionsAsExpired ¶
func (s *ServiceLogger) MarkTransactionsAsExpired(ctx context.Context) error
MarkTransactionsAsExpired marks all transactions that are expired as expired.
func (*ServiceLogger) UpdatePaymentStatus ¶
func (s *ServiceLogger) UpdatePaymentStatus(ctx context.Context, id uuid.UUID, status PaymentStatus) error
UpdatePaymentStatus updates the status of the payment with the given ID.
func (*ServiceLogger) UpdateTransaction ¶
func (s *ServiceLogger) UpdateTransaction(ctx context.Context, reference string, status TransactionStatus, signature string) error
UpdateTransaction updates the status and signature of the transaction with the given reference.
type Transaction ¶
type Transaction struct { ID uuid.UUID `json:"id,omitempty"` PaymentID uuid.UUID `json:"payment_id,omitempty"` Reference string `json:"reference,omitempty"` SourceWallet string `json:"source_wallet,omitempty"` SourceMint string `json:"source_mint,omitempty"` DestinationWallet string `json:"destination_wallet,omitempty"` DestinationMint string `json:"destination_mint,omitempty"` Amount uint64 `json:"amount,omitempty"` DiscountAmount uint64 `json:"discount_amount,omitempty"` TotalAmount uint64 `json:"total_amount,omitempty"` AccruedBonusAmount uint64 `json:"accrued_bonus_amount,omitempty"` Message string `json:"message,omitempty"` Memo string `json:"memo,omitempty"` ApplyBonus bool `json:"apply_bonus,omitempty"` Transaction string `json:"transaction,omitempty"` Status TransactionStatus `json:"status,omitempty"` Signature string `json:"signature,omitempty"` }
type TransactionStatus ¶
type TransactionStatus string
TransactionStatus represents the status of a transaction.
const ( TransactionStatusPending TransactionStatus = "pending" TransactionStatusCompleted TransactionStatus = "completed" TransactionStatusFailed TransactionStatus = "failed" )
Predefined transaction statuses.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is a task handler for email delivery.
func NewWorker ¶
func NewWorker(svc paymentService, sol workerSolanaClient, enq paymentEnqueuer) *Worker
NewWorker creates a new payments task handler.
func (*Worker) CheckPaymentByReference ¶
CheckPaymentByReference checks payment status by reference and unsubscribes from account notifications.
func (*Worker) CheckPendingTransactions ¶
CheckPendingTransactions checks pending transactions.
func (*Worker) MarkPaymentsAsExpired ¶
FireEvent sends a webhook event to the specified URL.
func (*Worker) MarkTransactionsAsExpired ¶
MarkTransactionsAsExpired marks transactions as expired.