processing

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

package processing implements methods for invoices processing

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStatusInvalid         = errors.New("payment status is invalid")
	ErrPaymentOptionsMissing = errors.New("payment options are not fully fulfilled")
	ErrSignatureVerification = errors.New("unable to verify request signature")
	ErrInboundWallet         = errors.New("inbound wallet error")
)
View Source
var (
	ErrInvalidInput = errors.New("invalid incoming input")
	ErrTransaction  = errors.New("transaction error")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	WebhookBasePath         string `` /* 143-byte string literal not displayed */
	PaymentFrontendBasePath string `` /* 151-byte string literal not displayed */
	PaymentFrontendSubPath  string `` /* 134-byte string literal not displayed */
	// DefaultServiceFee as float percentage. 1% is 0.01
	DefaultServiceFee float64 `yaml:"default_service_fee" env:"PROCESSING_DEFAULT_SERVICE_FEE" env-default:"0" env-description:"Internal variable"`
}

func (*Config) PaymentFrontendPath

func (c *Config) PaymentFrontendPath() string

type DetailedPayment

type DetailedPayment struct {
	Payment       *payment.Payment
	Customer      *payment.Customer
	Merchant      *merchant.Merchant
	PaymentMethod *payment.Method
	PaymentInfo   *PaymentInfo
}

type Input

type Input struct {
	Currency      money.CryptoCurrency
	Amount        money.Money
	SenderAddress string
	TransactionID string
	NetworkID     string
}

type PaymentInfo

type PaymentInfo struct {
	Status           payment.Status
	PaymentLink      string
	RecipientAddress string

	Amount          string
	AmountFormatted string

	ExpiresAt             time.Time
	ExpirationDurationMin int64

	SuccessAction  *payment.SuccessAction
	SuccessURL     *string
	SuccessMessage *string
}

PaymentInfo represents simplified transaction information.

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(
	config Config,
	wallets *wallet.Service,
	merchants *merchant.Service,
	payments *payment.Service,
	transactions *transaction.Service,
	blockchainService BlockchainService,
	tatumProvider *tatum.Provider,
	publisher bus.Publisher,
	locker *lock.Locker,
	logger *zerolog.Logger,
) *Service

func (*Service) BatchCheckIncomingTransactions

func (s *Service) BatchCheckIncomingTransactions(ctx context.Context, transactionIDs []int64) error

func (*Service) BatchCheckInternalTransfers

func (s *Service) BatchCheckInternalTransfers(ctx context.Context, transactionIDs []int64) error

func (*Service) BatchCheckWithdrawals

func (s *Service) BatchCheckWithdrawals(ctx context.Context, transactionIDs []int64) error

func (*Service) BatchCreateInternalTransfers

func (s *Service) BatchCreateInternalTransfers(
	ctx context.Context,
	inboundBalances []*wallet.Balance,
) (*TransferResult, error)

BatchCreateInternalTransfers receives INBOUND balances and transfers funds to OUTBOUND ones.

func (*Service) BatchCreateWithdrawals

func (s *Service) BatchCreateWithdrawals(ctx context.Context, withdrawalIDs []int64) (*TransferResult, error)

BatchCreateWithdrawals ingests list of withdrawals and creates & broadcasts transactions.

func (*Service) BatchExpirePayments

func (s *Service) BatchExpirePayments(ctx context.Context, paymentsIDs []int64) error

func (*Service) EnsureOutboundWallet

func (s *Service) EnsureOutboundWallet(ctx context.Context, chain money.Blockchain) (*wallet.Wallet, bool, error)

EnsureOutboundWallet makes sure that outbound wallet for specified blockchain exists in the database and the system is subscribed to all of selected currencies both for mainnet & testnet. Returning bool indicates whether the wallet was created or returned from db.

func (*Service) GetDetailedPayment

func (s *Service) GetDetailedPayment(ctx context.Context, merchantID, paymentID int64) (*DetailedPayment, error)

func (*Service) LockPaymentOptions

func (s *Service) LockPaymentOptions(ctx context.Context, merchantID, paymentID int64) error

LockPaymentOptions locks payment editing. This method is used to finish payment setup by the end customer.

func (*Service) ProcessInboundTransaction

func (s *Service) ProcessInboundTransaction(
	ctx context.Context,
	tx *transaction.Transaction,
	wt *wallet.Wallet,
	input Input,
) error

ProcessInboundTransaction implements correct business logic for transaction processing

func (*Service) ProcessIncomingWebhook

func (s *Service) ProcessIncomingWebhook(ctx context.Context, walletID uuid.UUID, networkID string, wh TatumWebhook) error

func (*Service) SetPaymentMethod

func (s *Service) SetPaymentMethod(ctx context.Context, p *payment.Payment, ticker string) (*payment.Method, error)

SetPaymentMethod created/changes payment's underlying transaction.

func (*Service) TopupMerchantFromSystem added in v0.6.0

func (s *Service) TopupMerchantFromSystem(ctx context.Context, merchantID int64, in TopupInput) (TopupOut, error)

TopupMerchantFromSystem performs an internal transfer from a non-materialized system balance to merchant's balance. Useful for resolving customer support requests.

func (*Service) ValidateWebhookSignature

func (s *Service) ValidateWebhookSignature(body []byte, hash string) error

ValidateWebhookSignature performs HMAC signature validation

type TatumWebhook

type TatumWebhook struct {
	SubscriptionType string `json:"subscriptionType"`
	TransactionID    string `json:"txId"`
	Address          string `json:"address"`
	Sender           string `json:"counterAddress"`

	// Asset coin name or token contact address or (!) token ticker e.g. USDT_TRON
	Asset string `json:"asset"`

	// Amount "0.000123" (float) instead of "123" (wei-like)
	Amount      string `json:"amount"`
	BlockNumber int64  `json:"blockNumber"`

	// Type can be ['native', 'token', `trc20', 'fee'] or maybe any other
	Type string `json:"type"`

	// Mempool (EMV-based blockchains only) if appears and set to "true", the transaction is in the mempool;
	// if set to "false" or does not appear at all, the transaction has been added to a block
	Mempool bool `json:"mempool"`

	// Chain for ETH test is might be 'ethereum-goerli' or 'sepolia'
	Chain string `json:"chain"`
}

TatumWebhook see https://apidoc.tatum.io/tag/Notification-subscriptions#operation/createSubscription

func (*TatumWebhook) CurrencyType

func (w *TatumWebhook) CurrencyType() money.CryptoCurrencyType

func (*TatumWebhook) MarshalBinary

func (w *TatumWebhook) MarshalBinary() ([]byte, error)

type TopupInput added in v0.6.0

type TopupInput struct {
	Currency money.CryptoCurrency
	Amount   money.Money
	Comment  string
	IsTest   bool
}

type TopupOut added in v0.6.0

type TopupOut struct {
	Payment         *payment.Payment
	Transaction     *transaction.Transaction
	MerchantBalance *wallet.Balance
}

type TransferResult

type TransferResult struct {
	CreatedTransactions      []*transaction.Transaction
	RollbackedTransactionIDs []int64
	UnhandledErrors          []error

	// len(UnhandledErrors) + len(RollbackedTransactionIDs)
	TotalErrors int64
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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