Documentation ¶
Index ¶
- Constants
- Variables
- type BlockchainService
- type CreateLinkProps
- type CreateOpt
- type CreatePaymentProps
- type CreateWithdrawalProps
- type Customer
- type CustomerDetails
- type Link
- type ListOptions
- type Metadata
- type Method
- type Payment
- func (p *Payment) ExpirationDurationMin() int64
- func (p *Payment) IsEditable() bool
- func (p *Payment) LinkID() int64
- func (p *Payment) LinkSuccessAction() *SuccessAction
- func (p *Payment) LinkSuccessMessage() *string
- func (p *Payment) PublicStatus() Status
- func (p *Payment) PublicSuccessAction() *SuccessAction
- func (p *Payment) PublicSuccessMessage() *string
- func (p *Payment) PublicSuccessURL() *string
- func (p *Payment) WithdrawalAddressID() int64
- func (p *Payment) WithdrawalBalanceID() int64
- type PaymentWithRelations
- type Service
- func (s *Service) AssignCustomerByEmail(ctx context.Context, p *Payment, email string) (*Customer, error)
- func (s *Service) CreateCustomer(ctx context.Context, merchantID int64, email string) (*Customer, error)
- func (s *Service) CreatePayment(ctx context.Context, merchantID int64, props CreatePaymentProps, ...) (*Payment, error)
- func (s *Service) CreatePaymentFromLink(ctx context.Context, link *Link) (*Payment, error)
- func (s *Service) CreatePaymentLink(ctx context.Context, merchantID int64, props CreateLinkProps) (*Link, error)
- func (s *Service) CreateWithdrawal(ctx context.Context, merchantID int64, props CreateWithdrawalProps) (*Payment, error)
- func (s *Service) DeletePaymentLinkByPublicID(ctx context.Context, merchantID int64, id uuid.UUID) error
- func (s *Service) Fail(ctx context.Context, pt *Payment) error
- func (s *Service) GetBatchCustomers(ctx context.Context, merchantID int64, ids []int64) ([]*Customer, error)
- func (s *Service) GetBatchExpired(ctx context.Context, limit int64) ([]*Payment, error)
- func (s *Service) GetByID(ctx context.Context, merchantID, id int64) (*Payment, error)
- func (s *Service) GetByMerchantIDs(ctx context.Context, merchantID int64, merchantOrderUUID uuid.UUID) (*Payment, error)
- func (s *Service) GetByMerchantOrderID(ctx context.Context, merchantID int64, merchantOrderUUID uuid.UUID) (*Payment, error)
- func (s *Service) GetByMerchantOrderIDWithRelations(ctx context.Context, merchantID int64, merchantOrderUUID uuid.UUID) (PaymentWithRelations, error)
- func (s *Service) GetByPublicID(ctx context.Context, publicID uuid.UUID) (*Payment, error)
- func (s *Service) GetCustomerByEmail(ctx context.Context, merchantID int64, email string) (*Customer, error)
- func (s *Service) GetCustomerByID(ctx context.Context, merchantID, id int64) (*Customer, error)
- func (s *Service) GetCustomerByUUID(ctx context.Context, merchantID int64, id uuid.UUID) (*Customer, error)
- func (s *Service) GetCustomerDetailsByUUID(ctx context.Context, merchantID int64, id uuid.UUID) (*CustomerDetails, error)
- func (s *Service) GetPaymentLinkByID(ctx context.Context, merchantID, id int64) (*Link, error)
- func (s *Service) GetPaymentLinkByPublicID(ctx context.Context, merchantID int64, id uuid.UUID) (*Link, error)
- func (s *Service) GetPaymentLinkBySlug(ctx context.Context, slug string) (*Link, error)
- func (s *Service) GetPaymentMethod(ctx context.Context, p *Payment) (*Method, error)
- func (s *Service) GetWithdrawalFee(ctx context.Context, merchantID int64, balanceID uuid.UUID) (*WithdrawalFee, error)
- func (s *Service) List(ctx context.Context, merchantID int64, opts ListOptions) ([]*Payment, string, error)
- func (s *Service) ListCustomers(ctx context.Context, merchantID int64, opts ListOptions) ([]*Customer, string, error)
- func (s *Service) ListPaymentLinks(ctx context.Context, merchantID int64) ([]*Link, error)
- func (s *Service) ListWithRelations(ctx context.Context, merchantID int64, opt ListOptions) ([]PaymentWithRelations, string, error)
- func (s *Service) ListWithdrawals(ctx context.Context, status Status, filterByIDs []int64) ([]*Payment, error)
- func (s *Service) ResolveCustomerByEmail(ctx context.Context, merchantID int64, email string) (*Customer, error)
- func (s *Service) SetWebhookTimestamp(ctx context.Context, merchantID, id int64, sentAt time.Time) error
- func (s *Service) Update(ctx context.Context, merchantID, id int64, props UpdateProps) (*Payment, error)
- type Status
- type SuccessAction
- type TransactionResolver
- type Type
- type UpdateProps
- type WithdrawalFee
Constants ¶
const ( MetaBalanceID wallet.MetaDataKey = "balanceID" MetaAddressID wallet.MetaDataKey = "addressID" MetaLinkID wallet.MetaDataKey = "linkID" MetaLinkSuccessAction wallet.MetaDataKey = "linkSuccessAction" MetaLinkSuccessMessage wallet.MetaDataKey = "linkSuccessMessage" )
const ExpirationPeriodForLocked = time.Minute * 20
ExpirationPeriodForLocked expiration period for incoming payment when locked
const ExpirationPeriodForNotLocked = time.Hour * 6
ExpirationPeriodForNotLocked expiration period for non-locked payment e.g. when payment is created but user haven't opened the page or haven't locked a cryptocurrency.
const MerchantIDWildcard = transaction.MerchantIDWildcard
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrAlreadyExists = errors.New("payment already exists") ErrValidation = errors.New("payment is invalid") ErrLinkValidation = errors.New("payment link is invalid") ErrPaymentMethodNotSet = errors.New("payment method is not set yet") ErrPaymentLocked = errors.New("payment is locked for editing") ErrInvalidLimit = errors.New("invalid limit") ErrAddressBalanceMismatch = errors.New("selected address does not match with balance") ErrWithdrawalInsufficientBalance = errors.New("not enough funds") ErrWithdrawalAmountTooSmall = errors.New("withdrawal amount is too small") )
Functions ¶
This section is empty.
Types ¶
type BlockchainService ¶
type BlockchainService interface { blockchain.Resolver blockchain.Convertor blockchain.FeeCalculator }
type CreateLinkProps ¶
type CreateOpt ¶
type CreateOpt func(props *CreatePaymentProps)
type CreatePaymentProps ¶
type CreateWithdrawalProps ¶
type CustomerDetails ¶
type ListOptions ¶
type Method ¶
type Method struct { Currency money.CryptoCurrency TransactionID int64 NetworkID string IsTest bool // contains filtered or unexported fields }
Method payment method.
func MakeMethod ¶
func MakeMethod(tx *transaction.Transaction, currency money.CryptoCurrency) *Method
func (*Method) TX ¶
func (m *Method) TX() *transaction.Transaction
type Payment ¶
type Payment struct { ID int64 PublicID uuid.UUID CreatedAt time.Time UpdatedAt time.Time ExpiresAt *time.Time Type Type Status Status MerchantID int64 MerchantOrderUUID uuid.UUID MerchantOrderID *string Price money.Money RedirectURL string PaymentURL string WebhookSentAt *time.Time Description *string IsTest bool CustomerID *int64 // contains filtered or unexported fields }
func (*Payment) ExpirationDurationMin ¶
func (*Payment) IsEditable ¶
IsEditable checks that payment can be edited (e.g. customer assignment/ selecting payment method)
func (*Payment) LinkSuccessAction ¶
func (p *Payment) LinkSuccessAction() *SuccessAction
func (*Payment) LinkSuccessMessage ¶
func (*Payment) PublicStatus ¶
PublicStatus returns payment's status for public output in the API.
func (*Payment) PublicSuccessAction ¶
func (p *Payment) PublicSuccessAction() *SuccessAction
func (*Payment) PublicSuccessMessage ¶
func (*Payment) PublicSuccessURL ¶
PublicSuccessURL returns successURL or nil based on status.
func (*Payment) WithdrawalAddressID ¶
func (*Payment) WithdrawalBalanceID ¶
type PaymentWithRelations ¶
type PaymentWithRelations struct { Payment *Payment Transaction *transaction.Transaction Customer *Customer Address *merchant.Address Balance *wallet.Balance }
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func New ¶
func New( repo *repository.Queries, basePath string, transactionService TransactionResolver, merchantService *merchant.Service, walletService *wallet.Service, blockchainService BlockchainService, publisher bus.Publisher, logger *zerolog.Logger, ) *Service
func (*Service) AssignCustomerByEmail ¶
func (s *Service) AssignCustomerByEmail(ctx context.Context, p *Payment, email string) (*Customer, error)
AssignCustomerByEmail resolves customer by email and then attaches him to the current payment.
func (*Service) CreateCustomer ¶
func (*Service) CreatePayment ¶
func (*Service) CreatePaymentFromLink ¶
func (*Service) CreatePaymentLink ¶
func (*Service) CreateWithdrawal ¶
func (*Service) DeletePaymentLinkByPublicID ¶
func (*Service) GetBatchCustomers ¶
func (*Service) GetBatchExpired ¶
GetBatchExpired returns list of expired payments. An expired payment is a payment that either has (expires_at != null && expires_at < $ExpiresAt) || (expires_at is null && created_at < $CreatedAt)
func (*Service) GetByMerchantIDs ¶
func (*Service) GetByMerchantOrderID ¶
func (*Service) GetByMerchantOrderIDWithRelations ¶
func (*Service) GetByPublicID ¶
func (*Service) GetCustomerByEmail ¶
func (*Service) GetCustomerByID ¶
func (*Service) GetCustomerByUUID ¶
func (*Service) GetCustomerDetailsByUUID ¶
func (*Service) GetPaymentLinkByID ¶
func (*Service) GetPaymentLinkByPublicID ¶
func (*Service) GetPaymentLinkBySlug ¶
func (*Service) GetPaymentMethod ¶
func (*Service) GetWithdrawalFee ¶
func (*Service) List ¶
func (s *Service) List(ctx context.Context, merchantID int64, opts ListOptions) ([]*Payment, string, error)
List paginates payments by provided merchantID and ListOptions.
func (*Service) ListCustomers ¶
func (*Service) ListPaymentLinks ¶
func (*Service) ListWithRelations ¶
func (s *Service) ListWithRelations(ctx context.Context, merchantID int64, opt ListOptions) ([]PaymentWithRelations, string, error)
ListWithRelations paginates payments with loaded relations.
func (*Service) ListWithdrawals ¶
func (*Service) ResolveCustomerByEmail ¶
func (s *Service) ResolveCustomerByEmail(ctx context.Context, merchantID int64, email string) (*Customer, error)
ResolveCustomerByEmail fetches Customer from DB or creates it on-the-fly.
func (*Service) SetWebhookTimestamp ¶
type SuccessAction ¶
type SuccessAction string
const ( SuccessActionRedirect SuccessAction = "redirect" SuccessActionShowMessage SuccessAction = "showMessage" )
type TransactionResolver ¶
type TransactionResolver interface { GetLatestByPaymentID(ctx context.Context, paymentID int64) (*transaction.Transaction, error) EagerLoadByPaymentIDs(ctx context.Context, merchantID int64, paymentIDs []int64) ([]*transaction.Transaction, error) }
type UpdateProps ¶
type UpdateProps struct {
Status Status
}