payment

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaBalanceID wallet.MetaDataKey = "balanceID"
	MetaAddressID wallet.MetaDataKey = "addressID"

	MetaLinkID             wallet.MetaDataKey = "linkID"
	MetaLinkSuccessAction  wallet.MetaDataKey = "linkSuccessAction"
	MetaLinkSuccessMessage wallet.MetaDataKey = "linkSuccessMessage"
)
View Source
const ExpirationPeriodForLocked = time.Minute * 20

ExpirationPeriodForLocked expiration period for incoming payment when locked

View Source
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.

View Source
const MerchantIDWildcard = transaction.MerchantIDWildcard

Variables

View Source
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 CreateLinkProps

type CreateLinkProps struct {
	Name string

	Price       money.Money
	Description *string

	SuccessAction  SuccessAction
	RedirectURL    *string
	SuccessMessage *string

	IsTest bool
}

type CreateOpt

type CreateOpt func(props *CreatePaymentProps)
func FromLink(link *Link) CreateOpt

type CreatePaymentProps

type CreatePaymentProps struct {
	MerchantOrderUUID uuid.UUID
	MerchantOrderID   *string

	Money money.Money

	RedirectURL *string

	Description *string

	IsTest bool
	// contains filtered or unexported fields
}

type CreateWithdrawalProps

type CreateWithdrawalProps struct {
	BalanceID uuid.UUID
	AddressID uuid.UUID
	AmountRaw string // "0.123"
}

type Customer

type Customer struct {
	ID         int64
	MerchantID int64
	UUID       uuid.UUID

	CreatedAt time.Time
	UpdatedAt time.Time

	Email string
}

type CustomerDetails

type CustomerDetails struct {
	Customer
	SuccessfulPayments int64
	RecentPayments     []*Payment
}
type Link struct {
	ID       int64
	PublicID uuid.UUID
	Slug     string
	URL      string

	CreatedAt time.Time
	UpdatedAt time.Time

	MerchantID int64
	Name       string

	Price       money.Money
	Description *string

	SuccessAction  SuccessAction
	RedirectURL    *string
	SuccessMessage *string

	IsTest bool
}

type ListOptions

type ListOptions struct {
	Limit        int
	Cursor       string
	ReverseOrder bool
	FilterByType []Type
}

type Metadata

type Metadata = wallet.MetaData

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 (p *Payment) ExpirationDurationMin() int64

func (*Payment) IsEditable

func (p *Payment) IsEditable() bool

IsEditable checks that payment can be edited (e.g. customer assignment/ selecting payment method)

func (*Payment) LinkID

func (p *Payment) LinkID() int64

func (*Payment) LinkSuccessAction

func (p *Payment) LinkSuccessAction() *SuccessAction

func (*Payment) LinkSuccessMessage

func (p *Payment) LinkSuccessMessage() *string

func (*Payment) PublicStatus

func (p *Payment) PublicStatus() Status

PublicStatus returns payment's status for public output in the API.

func (*Payment) PublicSuccessAction

func (p *Payment) PublicSuccessAction() *SuccessAction

func (*Payment) PublicSuccessMessage

func (p *Payment) PublicSuccessMessage() *string

func (*Payment) PublicSuccessURL

func (p *Payment) PublicSuccessURL() *string

PublicSuccessURL returns successURL or nil based on status.

func (*Payment) WithdrawalAddressID

func (p *Payment) WithdrawalAddressID() int64

func (*Payment) WithdrawalBalanceID

func (p *Payment) WithdrawalBalanceID() int64

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 (s *Service) CreateCustomer(ctx context.Context, merchantID int64, email string) (*Customer, error)

func (*Service) CreatePayment

func (s *Service) CreatePayment(
	ctx context.Context,
	merchantID int64,
	props CreatePaymentProps,
	opts ...CreateOpt,
) (*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 (*Service) CreateWithdrawal

func (s *Service) CreateWithdrawal(ctx context.Context, merchantID int64, props CreateWithdrawalProps) (*Payment, error)

func (*Service) DeletePaymentLinkByPublicID

func (s *Service) DeletePaymentLinkByPublicID(ctx context.Context, merchantID int64, id uuid.UUID) error

func (*Service) Fail added in v0.5.4

func (s *Service) Fail(ctx context.Context, pt *Payment) error

func (*Service) GetBatchCustomers

func (s *Service) GetBatchCustomers(ctx context.Context, merchantID int64, ids []int64) ([]*Customer, error)

func (*Service) GetBatchExpired

func (s *Service) GetBatchExpired(ctx context.Context, limit int64) ([]*Payment, error)

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) GetByID

func (s *Service) GetByID(ctx context.Context, merchantID, id int64) (*Payment, error)

func (*Service) GetByMerchantIDs

func (s *Service) GetByMerchantIDs(ctx context.Context, merchantID int64, merchantOrderUUID uuid.UUID) (*Payment, error)

func (*Service) GetByMerchantOrderID

func (s *Service) GetByMerchantOrderID(
	ctx context.Context,
	merchantID int64,
	merchantOrderUUID uuid.UUID,
) (*Payment, error)

func (*Service) GetByMerchantOrderIDWithRelations

func (s *Service) GetByMerchantOrderIDWithRelations(
	ctx context.Context,
	merchantID int64,
	merchantOrderUUID uuid.UUID,
) (PaymentWithRelations, error)

func (*Service) GetByPublicID

func (s *Service) GetByPublicID(ctx context.Context, publicID uuid.UUID) (*Payment, error)

func (*Service) GetCustomerByEmail

func (s *Service) GetCustomerByEmail(ctx context.Context, merchantID int64, email string) (*Customer, error)

func (*Service) GetCustomerByID

func (s *Service) GetCustomerByID(ctx context.Context, merchantID, id int64) (*Customer, error)

func (*Service) GetCustomerByUUID

func (s *Service) GetCustomerByUUID(ctx context.Context, merchantID int64, id uuid.UUID) (*Customer, error)

func (*Service) GetCustomerDetailsByUUID

func (s *Service) GetCustomerDetailsByUUID(ctx context.Context, merchantID int64, id uuid.UUID) (*CustomerDetails, error)

func (*Service) GetPaymentLinkByID

func (s *Service) GetPaymentLinkByID(ctx context.Context, merchantID, id int64) (*Link, error)

func (*Service) GetPaymentLinkByPublicID

func (s *Service) GetPaymentLinkByPublicID(ctx context.Context, merchantID int64, id uuid.UUID) (*Link, error)

func (*Service) GetPaymentLinkBySlug

func (s *Service) GetPaymentLinkBySlug(ctx context.Context, slug string) (*Link, error)

func (*Service) GetPaymentMethod

func (s *Service) GetPaymentMethod(ctx context.Context, p *Payment) (*Method, error)

func (*Service) GetWithdrawalFee

func (s *Service) GetWithdrawalFee(ctx context.Context, merchantID int64, balanceID uuid.UUID) (*WithdrawalFee, error)

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 (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 (*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 (s *Service) ListWithdrawals(ctx context.Context, status Status, filterByIDs []int64) ([]*Payment, error)

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

func (s *Service) SetWebhookTimestamp(ctx context.Context, merchantID, id int64, sentAt time.Time) error

func (*Service) Update

func (s *Service) Update(ctx context.Context, merchantID, id int64, props UpdateProps) (*Payment, error)

type Status

type Status string
const (
	// StatusPending just created
	StatusPending Status = "pending"

	// StatusLocked customer filled the form
	StatusLocked Status = "locked"

	// StatusInProgress underlying tx is in progress
	StatusInProgress Status = "inProgress"

	StatusSuccess Status = "success"
	StatusFailed  Status = "failed"
)

func (Status) String

func (s Status) String() string

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 Type

type Type string
const (
	TypePayment    Type = "payment"
	TypeWithdrawal Type = "withdrawal"
)

func (Type) String

func (t Type) String() string

type UpdateProps

type UpdateProps struct {
	Status Status
}

type WithdrawalFee

type WithdrawalFee struct {
	CalculatedAt time.Time
	Blockchain   money.Blockchain
	Currency     string
	USDFee       money.Money
	CryptoFee    money.Money
	IsTest       bool
}

Jump to

Keyboard shortcuts

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