data

package
v0.0.0-...-9cf9cea Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FixtureCountryUSA = "USA"
	FixtureCountryUKR = "UKR"
	FixtureAssetUSDC  = "USDC"
)
View Source
const (
	DefaultSMSRegistrationMessageTemplate = "You have a payment waiting for you from the {{.OrganizationName}}. Click {{.RegistrationLink}} to register."
	DefaultOTPMessageTemplate             = "{{.OTP}} is your {{.OrganizationName}} phone verification code."
)
View Source
const (
	// TestnetAlwaysValidOTP is used for testing purposes and will be considered a valid OTP for any testnet account.
	TestnetAlwaysValidOTP = "000000"
	// TestnetAlwaysInvalidOTP is used for testing purposes and will be considered an invalid OTP for any testnet account.
	TestnetAlwaysInvalidOTP = "999999"
)
View Source
const MaxAttemptsAllowed = 15
View Source
const MaxInstructionsPerDisbursement = 10000
View Source
const OTPExpirationTimeMinutes = 30

Variables

View Source
var (
	ErrMaxInstructionsExceeded      = errors.New("maximum number of instructions exceeded")
	ErrReceiverVerificationMismatch = errors.New("receiver verification mismatch")
)
View Source
var (
	DefaultDisbursementSortField = SortFieldCreatedAt
	DefaultDisbursementSortOrder = SortOrderDESC
	AllowedDisbursementFilters   = []FilterKey{FilterKeyStatus, FilterKeyCreatedAtAfter, FilterKeyCreatedAtBefore}
	AllowedDisbursementSorts     = []SortField{SortFieldName, SortFieldCreatedAt}
)
View Source
var (
	ErrRecordNotFound          = errors.New("record not found")
	ErrRecordAlreadyExists     = errors.New("record already exists")
	ErrMismatchNumRowsAffected = errors.New("mismatch number of rows affected")
	ErrMissingInput            = errors.New("missing input")
)
View Source
var (
	DefaultPaymentSortField = SortFieldUpdatedAt
	DefaultPaymentSortOrder = SortOrderDESC
	AllowedPaymentFilters   = []FilterKey{FilterKeyStatus, FilterKeyCreatedAtAfter, FilterKeyCreatedAtBefore, FilterKeyReceiverID}
	AllowedPaymentSorts     = []SortField{SortFieldCreatedAt, SortFieldUpdatedAt}
)
View Source
var (
	DefaultReceiverSortField = SortFieldUpdatedAt
	DefaultReceiverSortOrder = SortOrderDESC
	AllowedReceiverFilters   = []FilterKey{FilterKeyStatus, FilterKeyCreatedAtAfter, FilterKeyCreatedAtBefore}
	AllowedReceiverSorts     = []SortField{SortFieldCreatedAt, SortFieldUpdatedAt}
)
View Source
var (
	ErrWalletNameAlreadyExists           = errors.New("a wallet with this name already exists")
	ErrWalletHomepageAlreadyExists       = errors.New("a wallet with this homepage already exists")
	ErrWalletDeepLinkSchemaAlreadyExists = errors.New("a wallet with this deep link schema already exists")
	ErrInvalidAssetID                    = errors.New("invalid asset ID")
)

Functions

func AssociateAssetWithWalletFixture

func AssociateAssetWithWalletFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, assetID, walletID string)

AssociateAssetWithWalletFixture associates an asset with a wallet

func CompareVerificationValue

func CompareVerificationValue(hashedValue, verificationValue string) bool

func CreateInstructionsFixture

func CreateInstructionsFixture(t *testing.T, instructions []*DisbursementInstruction) []byte

func CreateMockImage

func CreateMockImage(t *testing.T, width, height int, size ImageSize) image.Image

CreateMockImage creates an RGBA image with the given proportion and size. The size is defined by how many different colors are drawn in the image, so the compression format (jpeg or png) will generate a larger file since the image will have more complexity. Note: Depending on the compression format the image size may vary.

Example creating a file:

img := CreateMockImage(t, 3840, 2160, ImageSizeLarge)
f, err := os.Create("image.png")
require.NoError(t, err)
err = jpeg.Encode(f, img, &jpeg.Options{Quality: jpeg.DefaultQuality}
require.NoError(t, err)

Example in memory image:

img := CreateMockImage(t, 1920, 1080, ImageSizeMedium)
buf := new(bytes.Buffer)
err = png.Encode(buf, img)
require.NoError(t, err)
fmt.Println(img.Bytes())

func DeleteAllAssetFixtures

func DeleteAllAssetFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

DeleteAllAssetFixtures deletes all assets in the database

func DeleteAllCountryFixtures

func DeleteAllCountryFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

DeleteAllCountryFixtures deletes all countries in the database

func DeleteAllDisbursementFixtures

func DeleteAllDisbursementFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllFixtures

func DeleteAllFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllMessagesFixtures

func DeleteAllMessagesFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllPaymentsFixtures

func DeleteAllPaymentsFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllReceiverVerificationFixtures

func DeleteAllReceiverVerificationFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllReceiverWalletsFixtures

func DeleteAllReceiverWalletsFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllReceiversFixtures

func DeleteAllReceiversFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

func DeleteAllWalletFixtures

func DeleteAllWalletFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter)

DeleteAllWalletFixtures deletes all wallets in the database

func DisableDisbursementApproval

func DisableDisbursementApproval(t *testing.T, ctx context.Context, orgModel *OrganizationModel)

DisableDisbursementApproval disables disbursement workflow approval for the given organization.

func EnableDisbursementApproval

func EnableDisbursementApproval(t *testing.T, ctx context.Context, orgModel *OrganizationModel)

EnableDisbursementApproval enables disbursement workflow approval for the given organization.

func EnableOrDisableWalletFixtures

func EnableOrDisableWalletFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, enabled bool, walletIDs ...string)

func FromUserRoleArrayToStringArray

func FromUserRoleArrayToStringArray(roles []UserRole) []string

FromUserRoleArrayToStringArray converts an array of UserRole type to an array of string

func HashVerificationValue

func HashVerificationValue(verificationValue string) (string, error)

func UpdateDisbursementInstructionsFixture

func UpdateDisbursementInstructionsFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, disbursementID, fileName string, instructions []*DisbursementInstruction)

Types

type Amount

type Amount struct {
	AssetCode      string `json:"asset_code" db:"asset_code"`
	AssetIssuer    string `json:"asset_issuer" db:"asset_issuer"`
	ReceivedAmount string `json:"received_amount" db:"received_amount"`
}

type Asset

type Asset struct {
	ID        string     `json:"id" db:"id"`
	Code      string     `json:"code" db:"code"`
	Issuer    string     `json:"issuer" db:"issuer"`
	CreatedAt *time.Time `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt *time.Time `json:"updated_at,omitempty" db:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
}

func ClearAndCreateAssetFixtures

func ClearAndCreateAssetFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter) []Asset

ClearAndCreateAssetFixtures deletes all assets in the database then creates new assets for testing

func CreateAssetFixture

func CreateAssetFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, code, issuer string) *Asset

func CreateWalletAssets

func CreateWalletAssets(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, walletID string, assetsIDs []string) []Asset

func GetAssetFixture

func GetAssetFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, code string) *Asset

func GetWalletAssetsFixture

func GetWalletAssetsFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, walletID string) []Asset

func (Asset) Equals

func (a Asset) Equals(other Asset) bool

Equals returns true if the asset is the same as the other asset. Case-insensitive.

func (Asset) EqualsHorizonAsset

func (a Asset) EqualsHorizonAsset(horizonAsset base.Asset) bool

func (Asset) IsNative

func (a Asset) IsNative() bool

IsNative returns true if the asset is the native asset (XLM).

type AssetModel

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

func (*AssetModel) Get

func (a *AssetModel) Get(ctx context.Context, id string) (*Asset, error)

func (*AssetModel) GetAll

func (a *AssetModel) GetAll(ctx context.Context) ([]Asset, error)

GetAll returns all assets in the database.

func (*AssetModel) GetAssetsPerReceiverWallet

func (a *AssetModel) GetAssetsPerReceiverWallet(ctx context.Context, receiverWallets ...*ReceiverWallet) ([]ReceiverWalletAsset, error)

GetAssetsPerReceiverWallet returns the assets associated with a READY payment for each receiver wallet provided.

func (*AssetModel) GetByCodeAndIssuer

func (a *AssetModel) GetByCodeAndIssuer(ctx context.Context, code, issuer string) (*Asset, error)

GetByCodeAndIssuer returns asset filtering by code and issuer.

func (*AssetModel) GetByWalletID

func (a *AssetModel) GetByWalletID(ctx context.Context, walletID string) ([]Asset, error)

GetByWalletID returns all assets associated with a wallet.

func (*AssetModel) GetOrCreate

func (a *AssetModel) GetOrCreate(ctx context.Context, code, issuer string) (*Asset, error)

func (*AssetModel) Insert

func (a *AssetModel) Insert(ctx context.Context, sqlExec db.SQLExecuter, code string, issuer string) (*Asset, error)

Insert is idempotent and returns a new asset if it doesn't exist or the existing one if it does, clearing the deleted_at field if it was marked as deleted.

func (*AssetModel) SoftDelete

func (a *AssetModel) SoftDelete(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Asset, error)

type Country

type Country struct {
	Code      string     `json:"code" db:"code"`
	Name      string     `json:"name" db:"name"`
	CreatedAt time.Time  `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt time.Time  `json:"updated_at,omitempty" db:"updated_at"`
	DeletedAt *time.Time `json:"-" db:"deleted_at"`
}

func ClearAndCreateCountryFixtures

func ClearAndCreateCountryFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter) []Country

ClearAndCreateCountryFixtures deletes all countries in the database then creates new countries for testing

func CreateCountryFixture

func CreateCountryFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, code, name string) *Country

func GetCountryFixture

func GetCountryFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, code string) *Country

type CountryModel

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

func (*CountryModel) Get

func (m *CountryModel) Get(ctx context.Context, code string) (*Country, error)

func (*CountryModel) GetAll

func (m *CountryModel) GetAll(ctx context.Context) ([]Country, error)

GetAll returns all countries in the database

type Disbursement

type Disbursement struct {
	ID                             string                    `json:"id" db:"id"`
	Name                           string                    `json:"name" db:"name"`
	Country                        *Country                  `json:"country,omitempty" db:"country"`
	Wallet                         *Wallet                   `json:"wallet,omitempty" db:"wallet"`
	Asset                          *Asset                    `json:"asset,omitempty" db:"asset"`
	Status                         DisbursementStatus        `json:"status" db:"status"`
	VerificationField              VerificationField         `json:"verification_field,omitempty" db:"verification_field"`
	StatusHistory                  DisbursementStatusHistory `json:"status_history,omitempty" db:"status_history"`
	SMSRegistrationMessageTemplate string                    `json:"sms_registration_message_template" db:"sms_registration_message_template"`
	FileName                       string                    `json:"file_name,omitempty" db:"file_name"`
	FileContent                    []byte                    `json:"-" db:"file_content"`
	CreatedAt                      time.Time                 `json:"created_at" db:"created_at"`
	UpdatedAt                      time.Time                 `json:"updated_at" db:"updated_at"`
	*DisbursementStats
}

func CreateDisbursementFixture

func CreateDisbursementFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, model *DisbursementModel, d *Disbursement) *Disbursement

func CreateDraftDisbursementFixture

func CreateDraftDisbursementFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, model *DisbursementModel, insert Disbursement) *Disbursement

type DisbursementInstruction

type DisbursementInstruction struct {
	Phone             string  `csv:"phone"`
	ID                string  `csv:"id"`
	Amount            string  `csv:"amount"`
	VerificationValue string  `csv:"verification"`
	ExternalPaymentId *string `csv:"paymentID"`
}

type DisbursementInstructionModel

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

func NewDisbursementInstructionModel

func NewDisbursementInstructionModel(dbConnectionPool db.DBConnectionPool) *DisbursementInstructionModel

NewDisbursementInstructionModel creates a new DisbursementInstructionModel.

func (DisbursementInstructionModel) ProcessAll

func (di DisbursementInstructionModel) ProcessAll(ctx context.Context, userID string, instructions []*DisbursementInstruction, disbursement *Disbursement, update *DisbursementUpdate, maxNumberOfInstructions int) error

ProcessAll Processes all disbursement instructions and persists the data to the database.

|--- For each phone number in the instructions:
|    |--- Check if a receiver exists.
|    |    |--- If a receiver does not exist, create one.
|    |--- For each receiver:
|    |    |--- Check if the receiver verification exists.
|    |    |    |--- If the receiver verification does not exist, create one.
|    |    |    |--- If the receiver verification exists:
|    |    |    |    |--- Check if the verification value matches.
|    |    |    |    |    |--- If the verification value does not match and the verification is confirmed, return an error.
|    |    |    |    |    |--- If the verification value does not match and the verification is not confirmed, update the verification value.
|    |    |    |    |    |--- If the verification value matches, continue.
|    |    |--- Check if the receiver wallet exists.
|    |    |    |--- If the receiver wallet does not exist, create one.
|    |    |    |--- If the receiver wallet exists and it's not REGISTERED, retry the invitation SMS.
|    |    |--- Delete all payments tied to this disbursement.
|    |    |--- Create all payments passed in the instructions.

type DisbursementModel

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

func (*DisbursementModel) CompleteDisbursements

func (d *DisbursementModel) CompleteDisbursements(ctx context.Context, sqlExec db.SQLExecuter, disbursementIDs []string) error

CompleteDisbursements sets disbursements statuses to complete after all payments are processed and successfully sent.

func (*DisbursementModel) Count

func (d *DisbursementModel) Count(ctx context.Context, sqlExec db.SQLExecuter, queryParams *QueryParams) (int, error)

Count returns the number of disbursements matching the given query parameters.

func (*DisbursementModel) Get

func (d *DisbursementModel) Get(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Disbursement, error)

func (*DisbursementModel) GetAll

func (d *DisbursementModel) GetAll(ctx context.Context, sqlExec db.SQLExecuter, queryParams *QueryParams) ([]*Disbursement, error)

GetAll returns all disbursements matching the given query parameters.

func (*DisbursementModel) GetByName

func (d *DisbursementModel) GetByName(ctx context.Context, sqlExec db.SQLExecuter, name string) (*Disbursement, error)

func (*DisbursementModel) GetWithStatistics

func (d *DisbursementModel) GetWithStatistics(ctx context.Context, id string) (*Disbursement, error)

func (*DisbursementModel) Insert

func (d *DisbursementModel) Insert(ctx context.Context, disbursement *Disbursement) (string, error)

func (*DisbursementModel) Update

func (*DisbursementModel) UpdateStatus

func (d *DisbursementModel) UpdateStatus(ctx context.Context, sqlExec db.SQLExecuter, userID string, disbursementID string, targetStatus DisbursementStatus) error

UpdateStatus updates the status of the given disbursement.

type DisbursementReceiver

type DisbursementReceiver struct {
	ID             string          `json:"id" db:"id"`
	Email          string          `json:"email,omitempty" db:"email"`
	PhoneNumber    string          `json:"phone_number" db:"phone_number"`
	ExternalID     string          `json:"external_id" db:"external_id"`
	ReceiverWallet *ReceiverWallet `json:"receiver_wallet" db:"receiver_wallet"`
	Payment        *Payment        `json:"payment" db:"payment"`
	CreatedAt      time.Time       `json:"created_at" db:"created_at"`
	UpdatedAt      time.Time       `json:"updated_at" db:"updated_at"`
}

type DisbursementReceiverModel

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

func (DisbursementReceiverModel) Count

func (m DisbursementReceiverModel) Count(ctx context.Context, sqlExec db.SQLExecuter, disbursementID string) (int, error)

func (DisbursementReceiverModel) GetAll

func (m DisbursementReceiverModel) GetAll(ctx context.Context, sqlExec db.SQLExecuter, queryParams *QueryParams, disbursementID string) ([]*DisbursementReceiver, error)

type DisbursementStats

type DisbursementStats struct {
	TotalPayments      int    `json:"total_payments" db:"total_payments"`
	SuccessfulPayments int    `json:"total_payments_sent" db:"total_payments_sent"`
	FailedPayments     int    `json:"total_payments_failed" db:"total_payments_failed"`
	CanceledPayments   int    `json:"total_payments_canceled" db:"total_payments_canceled"`
	RemainingPayments  int    `json:"total_payments_remaining" db:"total_payments_remaining"`
	AmountDisbursed    string `json:"amount_disbursed" db:"amount_disbursed"`
	TotalAmount        string `json:"total_amount" db:"total_amount"`
	AverageAmount      string `json:"average_amount" db:"average_amount"`
}

type DisbursementStatus

type DisbursementStatus string
const (
	DraftDisbursementStatus     DisbursementStatus = "DRAFT"
	ReadyDisbursementStatus     DisbursementStatus = "READY"
	StartedDisbursementStatus   DisbursementStatus = "STARTED"
	PausedDisbursementStatus    DisbursementStatus = "PAUSED"
	CompletedDisbursementStatus DisbursementStatus = "COMPLETED"
)

func DisbursementStatuses

func DisbursementStatuses() []DisbursementStatus

DisbursementStatuses returns a list of all possible disbursement statuses

func ToDisbursementStatus

func ToDisbursementStatus(s string) (DisbursementStatus, error)

ToDisbursementStatus converts a string to a DisbursementStatus

func (DisbursementStatus) SourceStatuses

func (status DisbursementStatus) SourceStatuses() []DisbursementStatus

SourceStatuses returns a list of states that the payment status can transition from given the target state

func (DisbursementStatus) State

func (status DisbursementStatus) State() State

func (DisbursementStatus) TransitionTo

func (status DisbursementStatus) TransitionTo(targetState DisbursementStatus) error

TransitionTo transitions the disbursement status to the target state

func (DisbursementStatus) Validate

func (status DisbursementStatus) Validate() error

Validate validates the disbursement status

type DisbursementStatusHistory

type DisbursementStatusHistory []DisbursementStatusHistoryEntry

func (*DisbursementStatusHistory) Scan

func (dsh *DisbursementStatusHistory) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (DisbursementStatusHistory) Value

Value implements the driver.Valuer interface.

type DisbursementStatusHistoryEntry

type DisbursementStatusHistoryEntry struct {
	UserID    string             `json:"user_id"`
	Status    DisbursementStatus `json:"status"`
	Timestamp time.Time          `json:"timestamp"`
}

type DisbursementUpdate

type DisbursementUpdate struct {
	ID          string
	FileName    string
	FileContent []byte
}

func (*DisbursementUpdate) Validate

func (du *DisbursementUpdate) Validate() error

type FilterKey

type FilterKey string
const (
	FilterKeyStatus          FilterKey = "status"
	FilterKeyReceiverID      FilterKey = "receiver_id"
	FilterKeyCreatedAtAfter  FilterKey = "created_at_after"
	FilterKeyCreatedAtBefore FilterKey = "created_at_before"
)

type ImageSize

type ImageSize int
const (
	ImageSizeSmall ImageSize = iota
	ImageSizeMedium
	ImageSizeLarge
)

type InstructionLine

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

type LogoType

type LogoType string
const (
	PNGLogoType  LogoType = "png"
	JPEGLogoType LogoType = "jpeg"
)

func (LogoType) ToHTTPContentType

func (lt LogoType) ToHTTPContentType() string

type Message

type Message struct {
	ID               string                `db:"id"`
	Type             message.MessengerType `db:"type"`
	AssetID          *string               `db:"asset_id"`
	ReceiverID       string                `db:"receiver_id"`
	WalletID         string                `db:"wallet_id"`
	ReceiverWalletID *string               `db:"receiver_wallet_id"`
	TextEncrypted    string                `db:"text_encrypted"`
	TitleEncrypted   string                `db:"title_encrypted"`
	Status           MessageStatus         `db:"status"`
	StatusHistory    MessageStatusHistory  `db:"status_history"`
	CreatedAt        time.Time             `db:"created_at"`
	UpdatedAt        time.Time             `db:"updated_at"`
}

func CreateMessageFixture

func CreateMessageFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, m *Message) *Message

type MessageInsert

type MessageInsert struct {
	Type             message.MessengerType
	AssetID          *string
	ReceiverID       string
	WalletID         string
	ReceiverWalletID *string
	TextEncrypted    string
	TitleEncrypted   string
	Status           MessageStatus
	StatusHistory    MessageStatusHistory
}

type MessageModel

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

func (*MessageModel) BulkInsert

func (m *MessageModel) BulkInsert(ctx context.Context, sqlExec db.SQLExecuter, newMsgs []*MessageInsert) error

func (*MessageModel) Insert

func (m *MessageModel) Insert(ctx context.Context, newMsg *MessageInsert) (*Message, error)

type MessageStatus

type MessageStatus string
var (
	PendingMessageStatus MessageStatus = "PENDING"
	SuccessMessageStatus MessageStatus = "SUCCESS"
	FailureMessageStatus MessageStatus = "FAILURE"
)

type MessageStatusHistory

type MessageStatusHistory []MessageStatusHistoryEntry

func (*MessageStatusHistory) Scan

func (msh *MessageStatusHistory) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (MessageStatusHistory) Value

func (msh MessageStatusHistory) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type MessageStatusHistoryEntry

type MessageStatusHistoryEntry struct {
	StatusMessage *string       `json:"status_message"`
	Status        MessageStatus `json:"status"`
	Timestamp     time.Time     `json:"timestamp"`
}

type Models

type Models struct {
	Disbursements            *DisbursementModel
	Wallets                  *WalletModel
	Countries                *CountryModel
	Assets                   *AssetModel
	Organizations            *OrganizationModel
	Payment                  *PaymentModel
	Receiver                 *ReceiverModel
	DisbursementInstructions *DisbursementInstructionModel
	ReceiverVerification     *ReceiverVerificationModel
	ReceiverWallet           *ReceiverWalletModel
	DisbursementReceivers    *DisbursementReceiverModel
	Message                  *MessageModel
	DBConnectionPool         db.DBConnectionPool
}

func NewModels

func NewModels(dbConnectionPool db.DBConnectionPool) (*Models, error)

type Organization

type Organization struct {
	ID                string `json:"id" db:"id"`
	Name              string `json:"name" db:"name"`
	TimezoneUTCOffset string `json:"timezone_utc_offset" db:"timezone_utc_offset"`
	// SMSResendInterval is the time period that SDP will wait to resend the invitation SMS to the receivers that aren't registered.
	// If it's nil means resending the invitation SMS is deactivated.
	SMSResendInterval *int64 `json:"sms_resend_interval" db:"sms_resend_interval"`
	// PaymentCancellationPeriodDays is the number of days for a ready payment to be automatically cancelled.
	PaymentCancellationPeriodDays  *int64 `json:"payment_cancellation_period_days" db:"payment_cancellation_period_days"`
	SMSRegistrationMessageTemplate string `json:"sms_registration_message_template" db:"sms_registration_message_template"`
	// OTPMessageTemplate is the message template to send the OTP code to the receivers validates their identity when registering their wallets.
	// The message may have the template values {{.OTP}} and {{.OrganizationName}}, it will be parsed and the values injected when executing the template.
	// When the {{.OTP}} is not found in the message, it's added at the beginning of the message.
	// Example:
	//	{{.OTP}} OTPMessageTemplate
	OTPMessageTemplate string    `json:"otp_message_template" db:"otp_message_template"`
	PrivacyPolicyLink  *string   `json:"privacy_policy_link" db:"privacy_policy_link"`
	IsApprovalRequired bool      `json:"is_approval_required" db:"is_approval_required"`
	CreatedAt          time.Time `json:"created_at" db:"created_at"`
	UpdatedAt          time.Time `json:"updated_at" db:"updated_at"`
}

type OrganizationModel

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

func (*OrganizationModel) Get

func (*OrganizationModel) Update

type OrganizationUpdate

type OrganizationUpdate struct {
	Name                          string `json:",omitempty"`
	TimezoneUTCOffset             string `json:",omitempty"`
	IsApprovalRequired            *bool  `json:",omitempty"`
	SMSResendInterval             *int64 `json:",omitempty"`
	PaymentCancellationPeriodDays *int64 `json:",omitempty"`

	// Using pointers to accept empty strings
	SMSRegistrationMessageTemplate *string `json:",omitempty"`
	OTPMessageTemplate             *string `json:",omitempty"`
	PrivacyPolicyLink              *string `json:",omitempty"`
}

type Payment

type Payment struct {
	ID                   string `json:"id" db:"id"`
	Amount               string `json:"amount" db:"amount"`
	StellarTransactionID string `json:"stellar_transaction_id" db:"stellar_transaction_id"`
	// TODO: evaluate if we will keep or remove StellarOperationID
	StellarOperationID string               `json:"stellar_operation_id" db:"stellar_operation_id"`
	Status             PaymentStatus        `json:"status" db:"status"`
	StatusHistory      PaymentStatusHistory `json:"status_history,omitempty" db:"status_history"`
	Disbursement       *Disbursement        `json:"disbursement,omitempty" db:"disbursement"`
	Asset              Asset                `json:"asset"`
	ReceiverWallet     *ReceiverWallet      `json:"receiver_wallet,omitempty" db:"receiver_wallet"`
	CreatedAt          time.Time            `json:"created_at" db:"created_at"`
	UpdatedAt          time.Time            `json:"updated_at" db:"updated_at"`
	ExternalPaymentID  string               `json:"external_payment_id,omitempty" db:"external_payment_id"`
}

func CreatePaymentFixture

func CreatePaymentFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, model *PaymentModel, p *Payment) *Payment

type PaymentInsert

type PaymentInsert struct {
	ReceiverID        string  `db:"receiver_id"`
	DisbursementID    string  `db:"disbursement_id"`
	Amount            string  `db:"amount"`
	AssetID           string  `db:"asset_id"`
	ReceiverWalletID  string  `db:"receiver_wallet_id"`
	ExternalPaymentID *string `db:"external_payment_id"`
}

func (*PaymentInsert) Validate

func (p *PaymentInsert) Validate() error

type PaymentModel

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

func (*PaymentModel) CancelPaymentsWithinPeriodDays

func (p *PaymentModel) CancelPaymentsWithinPeriodDays(ctx context.Context, sqlExec db.SQLExecuter, periodInDays int64) error

CancelPaymentsWithinPeriodDays cancels automatically payments that are in "READY" status after a certain time period in days.

func (*PaymentModel) Count

func (p *PaymentModel) Count(ctx context.Context, queryParams *QueryParams, sqlExec db.SQLExecuter) (int, error)

Count returns the number of payments matching the given query parameters.

func (*PaymentModel) DeleteAllForDisbursement

func (p *PaymentModel) DeleteAllForDisbursement(ctx context.Context, sqlExec db.SQLExecuter, disbursementID string) error

DeleteAllForDisbursement deletes all payments for a given disbursement.

func (*PaymentModel) Get

func (p *PaymentModel) Get(ctx context.Context, id string, sqlExec db.SQLExecuter) (*Payment, error)

func (*PaymentModel) GetAll

func (p *PaymentModel) GetAll(ctx context.Context, queryParams *QueryParams, sqlExec db.SQLExecuter) ([]Payment, error)

GetAll returns all PAYMENTS matching the given query parameters.

func (*PaymentModel) GetAllReadyToPatchCompletionAnchorTransactions

func (p *PaymentModel) GetAllReadyToPatchCompletionAnchorTransactions(ctx context.Context, sqlExec db.SQLExecuter) ([]Payment, error)

func (*PaymentModel) GetBatchForUpdate

func (p *PaymentModel) GetBatchForUpdate(ctx context.Context, sqlExec db.SQLExecuter, batchSize int) ([]*Payment, error)

func (*PaymentModel) GetByIDs

func (p *PaymentModel) GetByIDs(ctx context.Context, sqlExec db.SQLExecuter, paymentIDs []string) ([]*Payment, error)

GetByIDs returns a list of payments for the given IDs.

func (*PaymentModel) GetReadyByDisbursementID

func (p *PaymentModel) GetReadyByDisbursementID(ctx context.Context, sqlExec db.SQLExecuter, disbursementID string) ([]*Payment, error)

func (*PaymentModel) GetReadyByID

func (p *PaymentModel) GetReadyByID(ctx context.Context, sqlExec db.SQLExecuter, paymentIDs ...string) ([]*Payment, error)

func (*PaymentModel) GetReadyByReceiverWalletID

func (p *PaymentModel) GetReadyByReceiverWalletID(ctx context.Context, sqlExec db.SQLExecuter, receiverWalletID string) ([]*Payment, error)

func (*PaymentModel) InsertAll

func (p *PaymentModel) InsertAll(ctx context.Context, sqlExec db.SQLExecuter, inserts []PaymentInsert) error

InsertAll inserts a batch of payments into the database.

func (*PaymentModel) RetryFailedPayments

func (p *PaymentModel) RetryFailedPayments(ctx context.Context, sqlExec db.SQLExecuter, email string, paymentIDs ...string) error

func (*PaymentModel) Update

func (p *PaymentModel) Update(ctx context.Context, sqlExec db.SQLExecuter, payment *Payment, update *PaymentUpdate) error

Update updates a payment's fields with the given update.

func (*PaymentModel) UpdateStatusByDisbursementID

func (p *PaymentModel) UpdateStatusByDisbursementID(ctx context.Context, sqlExec db.SQLExecuter, disbursementID string, targetStatus PaymentStatus) error

UpdateStatusByDisbursementID updates the status of all payments with a given status for a given disbursement.

func (*PaymentModel) UpdateStatuses

func (p *PaymentModel) UpdateStatuses(ctx context.Context, sqlExec db.SQLExecuter, payments []*Payment, toStatus PaymentStatus) (int64, error)

type PaymentStatus

type PaymentStatus string
const (
	// DraftPaymentStatus is a non-terminal state for payments that were registered in the database but their disbursement has not started yet. Payments in this state can be deleted or transitioned to READY.
	DraftPaymentStatus PaymentStatus = "DRAFT"
	// ReadyPaymentStatus is a non-terminal state for payments that are waiting for the receiver to register. As soon as the receiver registers, the state is transitioned to PENDING.
	ReadyPaymentStatus PaymentStatus = "READY"
	// PendingPaymentStatus is a non-terminal state for payments that were marked for submission to the Stellar network. They can or can not have been submitted yet.
	PendingPaymentStatus PaymentStatus = "PENDING"
	// PausedPaymentStatus is a non-terminal state for payments that were manually paused. Payments in this state can be resumed.
	PausedPaymentStatus PaymentStatus = "PAUSED"
	// SuccessPaymentStatus is a terminal state for payments that were successfully submitted to the Stellar network.
	SuccessPaymentStatus PaymentStatus = "SUCCESS"
	// FailedPaymentStatus is a terminal state for payments that failed when submitted to the Stellar network. Payments in this state can be retried.
	FailedPaymentStatus PaymentStatus = "FAILED"
	// CanceledPaymentStatus is a terminal state for payments that were either manually or automatically canceled.
	CanceledPaymentStatus PaymentStatus = "CANCELED"
)

func PaymentActiveStatuses

func PaymentActiveStatuses() []PaymentStatus

func PaymentInProgressStatuses

func PaymentInProgressStatuses() []PaymentStatus

PaymentInProgressStatuses returns a list of payment statuses that are in progress and could block potential new payments from being initiated if the distribution balance is low.

func PaymentStatuses

func PaymentStatuses() []PaymentStatus

PaymentStatuses returns a list of all possible payment statuses

func ToPaymentStatus

func ToPaymentStatus(s string) (PaymentStatus, error)

ToPaymentStatus converts a string to a PaymentStatus

func (PaymentStatus) SourceStatuses

func (status PaymentStatus) SourceStatuses() []PaymentStatus

SourceStatuses returns a list of states that the payment status can transition from given the target state

func (PaymentStatus) State

func (status PaymentStatus) State() State

func (PaymentStatus) TransitionTo

func (status PaymentStatus) TransitionTo(targetState PaymentStatus) error

TransitionTo transitions the payment status to the target state

func (PaymentStatus) Validate

func (status PaymentStatus) Validate() error

Validate validates the payment status

type PaymentStatusHistory

type PaymentStatusHistory []PaymentStatusHistoryEntry

func (*PaymentStatusHistory) Scan

func (psh *PaymentStatusHistory) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (PaymentStatusHistory) Value

func (psh PaymentStatusHistory) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type PaymentStatusHistoryEntry

type PaymentStatusHistoryEntry struct {
	Status        PaymentStatus `json:"status"`
	StatusMessage string        `json:"status_message"`
	Timestamp     time.Time     `json:"timestamp"`
}

type PaymentUpdate

type PaymentUpdate struct {
	Status               PaymentStatus `db:"status"`
	StatusMessage        string
	StellarTransactionID string `db:"stellar_transaction_id"`
}

func (*PaymentUpdate) Validate

func (p *PaymentUpdate) Validate() error

type QueryBuilder

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

QueryBuilder is a helper struct for building SQL queries

func NewQueryBuilder

func NewQueryBuilder(query string) *QueryBuilder

NewQueryBuilder creates a new QueryBuilder

func (*QueryBuilder) AddCondition

func (qb *QueryBuilder) AddCondition(condition string, value ...interface{}) *QueryBuilder

AddCondition adds a condition to the query If the value is nil or empty, the condition is not added The condition should be a string with a placeholder for the value e.g. "name = ?", "id > ?"

func (*QueryBuilder) AddPagination

func (qb *QueryBuilder) AddPagination(page int, pageLimit int) *QueryBuilder

AddPagination adds a pagination clause to the query

func (*QueryBuilder) AddSorting

func (qb *QueryBuilder) AddSorting(sortField SortField, sortOrder SortOrder, prefix string) *QueryBuilder

AddSorting adds a sorting clause to the query prefix is the prefix to use for the sort field e.g. "d" for "d.created_at"

func (*QueryBuilder) Build

func (qb *QueryBuilder) Build() (string, []interface{})

Build assembles all statements in the correct order and returns the query and the parameters

type QueryParams

type QueryParams struct {
	Query     string
	Page      int
	PageLimit int
	SortBy    SortField
	SortOrder SortOrder
	Filters   map[FilterKey]interface{}
}

type ReceivedAmounts

type ReceivedAmounts []Amount

func (*ReceivedAmounts) Scan

func (ra *ReceivedAmounts) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

type Receiver

type Receiver struct {
	ID          string     `json:"id" db:"id"`
	Email       *string    `json:"email,omitempty" db:"email"`
	PhoneNumber string     `json:"phone_number,omitempty" db:"phone_number"`
	ExternalID  string     `json:"external_id,omitempty" db:"external_id"`
	CreatedAt   *time.Time `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt   *time.Time `json:"updated_at,omitempty" db:"updated_at"`
	ReceiverStats
}

func CreateReceiverFixture

func CreateReceiverFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, r *Receiver) *Receiver

type ReceiverIDs

type ReceiverIDs []string

type ReceiverInsert

type ReceiverInsert struct {
	PhoneNumber string  `db:"phone_number"`
	ExternalId  *string `db:"external_id"`
}

type ReceiverModel

type ReceiverModel struct{}

func (*ReceiverModel) Count

func (r *ReceiverModel) Count(ctx context.Context, sqlExec db.SQLExecuter, queryParams *QueryParams) (int, error)

Count returns the number of receivers matching the given query parameters.

func (*ReceiverModel) DeleteByPhoneNumber

func (r *ReceiverModel) DeleteByPhoneNumber(ctx context.Context, dbConnectionPool db.DBConnectionPool, phoneNumber string) error

DeleteByPhoneNumber deletes a receiver by phone number. It also deletes the associated entries in other tables: messages, payments, receiver_verifications, receiver_wallets, receivers, disbursements, submitter_transactions

func (*ReceiverModel) Get

func (r *ReceiverModel) Get(ctx context.Context, sqlExec db.SQLExecuter, id string) (*Receiver, error)

Get returns a RECEIVER matching the given ID.

func (*ReceiverModel) GetAll

func (r *ReceiverModel) GetAll(ctx context.Context, sqlExec db.SQLExecuter, queryParams *QueryParams) ([]Receiver, error)

GetAll returns all RECEIVERS matching the given query parameters.

func (*ReceiverModel) GetByPhoneNumbers

func (r *ReceiverModel) GetByPhoneNumbers(ctx context.Context, sqlExec db.SQLExecuter, ids []string) ([]*Receiver, error)

GetByPhoneNumbers search for receivers by phone numbers

func (*ReceiverModel) Insert

func (r *ReceiverModel) Insert(ctx context.Context, sqlExec db.SQLExecuter, insert ReceiverInsert) (*Receiver, error)

Insert inserts a new receiver into the database.

func (*ReceiverModel) ParseReceiverIDs

func (r *ReceiverModel) ParseReceiverIDs(receivers []Receiver) ReceiverIDs

ParseReceiverIDs return the array of receivers IDs.

func (*ReceiverModel) Update

func (r *ReceiverModel) Update(ctx context.Context, sqlExec db.SQLExecuter, ID string, receiverUpdate ReceiverUpdate) error

Update updates the receiver Email and/or External ID.

type ReceiverRegistrationRequest

type ReceiverRegistrationRequest struct {
	PhoneNumber       string            `json:"phone_number"`
	OTP               string            `json:"otp"`
	VerificationValue string            `json:"verification"`
	VerificationType  VerificationField `json:"verification_type"`
	ReCAPTCHAToken    string            `json:"recaptcha_token"`
}

type ReceiverStats

type ReceiverStats struct {
	TotalPayments      string          `json:"total_payments,omitempty" db:"total_payments"`
	SuccessfulPayments string          `json:"successful_payments,omitempty" db:"successful_payments"`
	FailedPayments     string          `json:"failed_payments,omitempty" db:"failed_payments"`
	CanceledPayments   string          `json:"canceled_payments,omitempty" db:"canceled_payments"`
	RemainingPayments  string          `json:"remaining_payments,omitempty" db:"remaining_payments"`
	RegisteredWallets  string          `json:"registered_wallets,omitempty" db:"registered_wallets"`
	ReceivedAmounts    ReceivedAmounts `json:"received_amounts,omitempty" db:"received_amounts"`
}

type ReceiverUpdate

type ReceiverUpdate struct {
	Email      string `db:"email"`
	ExternalId string `db:"external_id"`
}

type ReceiverVerification

type ReceiverVerification struct {
	ReceiverID        string            `json:"receiver_id" db:"receiver_id"`
	VerificationField VerificationField `json:"verification_field" db:"verification_field"`
	HashedValue       string            `json:"hashed_value" db:"hashed_value"`
	Attempts          int               `json:"attempts" db:"attempts"`
	CreatedAt         time.Time         `json:"created_at" db:"created_at"`
	UpdatedAt         time.Time         `json:"updated_at" db:"updated_at"`
	ConfirmedAt       *time.Time        `json:"confirmed_at" db:"confirmed_at"`
	FailedAt          *time.Time        `json:"failed_at" db:"failed_at"`
}

func CreateReceiverVerificationFixture

func CreateReceiverVerificationFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, insert ReceiverVerificationInsert) *ReceiverVerification

type ReceiverVerificationInsert

type ReceiverVerificationInsert struct {
	ReceiverID        string            `db:"receiver_id"`
	VerificationField VerificationField `db:"verification_field"`
	VerificationValue string            `db:"hashed_value"`
}

func (*ReceiverVerificationInsert) Validate

func (rvi *ReceiverVerificationInsert) Validate() error

type ReceiverVerificationModel

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

func (*ReceiverVerificationModel) ExceededAttempts

func (*ReceiverVerificationModel) ExceededAttempts(attempts int) bool

ExceededAttempts check if the number of attempts exceeded the max value.

func (*ReceiverVerificationModel) GetAllByReceiverId

func (m *ReceiverVerificationModel) GetAllByReceiverId(ctx context.Context, sqlExec db.SQLExecuter, receiverId string) ([]ReceiverVerification, error)

GetAllByReceiverId returns all receiver verifications by receiver id.

func (*ReceiverVerificationModel) GetByReceiverIDsAndVerificationField

func (m *ReceiverVerificationModel) GetByReceiverIDsAndVerificationField(ctx context.Context, sqlExec db.SQLExecuter, receiverIds []string, verificationField VerificationField) ([]*ReceiverVerification, error)

GetByReceiverIDsAndVerificationField returns receiver verifications by receiver IDs and verification type.

func (*ReceiverVerificationModel) GetLatestByPhoneNumber

func (m *ReceiverVerificationModel) GetLatestByPhoneNumber(ctx context.Context, phoneNumber string) (*ReceiverVerification, error)

GetLatestByPhoneNumber returns the latest updated receiver verification for some receiver that is associated with a phone number.

func (*ReceiverVerificationModel) Insert

func (m *ReceiverVerificationModel) Insert(ctx context.Context, sqlExec db.SQLExecuter, verificationInsert ReceiverVerificationInsert) (string, error)

Insert inserts a new receiver verification

func (*ReceiverVerificationModel) UpdateReceiverVerification

func (m *ReceiverVerificationModel) UpdateReceiverVerification(ctx context.Context, receiverVerification ReceiverVerification, sqlExec db.SQLExecuter) error

UpdateReceiverVerification updates the attempts, confirmed_at, and failed_at values of a receiver verification.

func (*ReceiverVerificationModel) UpdateVerificationValue

func (m *ReceiverVerificationModel) UpdateVerificationValue(ctx context.Context,
	sqlExec db.SQLExecuter,
	receiverID string,
	verificationField VerificationField,
	verificationValue string,
) error

UpdateVerificationValue updates the hashed value of a receiver verification.

func (*ReceiverVerificationModel) UpsertVerificationValue

func (m *ReceiverVerificationModel) UpsertVerificationValue(ctx context.Context, sqlExec db.SQLExecuter, receiverID string, verificationField VerificationField, verificationValue string) error

UpsertVerificationValue creates or updates the receiver's verification. In case the verification exists and it's already confirmed by the receiver it's not updated.

type ReceiverWallet

type ReceiverWallet struct {
	ID              string                       `json:"id" db:"id"`
	Receiver        Receiver                     `json:"receiver" db:"receiver"`
	Wallet          Wallet                       `json:"wallet" db:"wallet"`
	StellarAddress  string                       `json:"stellar_address,omitempty" db:"stellar_address"`
	StellarMemo     string                       `json:"stellar_memo,omitempty" db:"stellar_memo"`
	StellarMemoType string                       `json:"stellar_memo_type,omitempty" db:"stellar_memo_type"`
	Status          ReceiversWalletStatus        `json:"status" db:"status"`
	StatusHistory   ReceiversWalletStatusHistory `json:"status_history,omitempty" db:"status_history"`
	CreatedAt       time.Time                    `json:"created_at" db:"created_at"`
	UpdatedAt       time.Time                    `json:"updated_at" db:"updated_at"`
	OTP             string                       `json:"-" db:"otp"`
	OTPCreatedAt    *time.Time                   `json:"-" db:"otp_created_at"`
	OTPConfirmedAt  *time.Time                   `json:"otp_confirmed_at,omitempty" db:"otp_confirmed_at"`
	// AnchorPlatformAccountID is the ID of the SEP24 transaction initiated by the Anchor Platform where the receiver wallet was registered.
	AnchorPlatformTransactionID       string     `json:"anchor_platform_transaction_id,omitempty" db:"anchor_platform_transaction_id"`
	AnchorPlatformTransactionSyncedAt *time.Time `json:"anchor_platform_transaction_synced_at,omitempty" db:"anchor_platform_transaction_synced_at"`
	InvitedAt                         *time.Time `json:"invited_at,omitempty" db:"invited_at"`
	LastSmsSent                       *time.Time `json:"last_sms_sent,omitempty" db:"last_sms_sent"`
	InvitationSentAt                  *time.Time `json:"invitation_sent_at" db:"invitation_sent_at"`
	ReceiverWalletStats
}

func CreateReceiverWalletFixture

func CreateReceiverWalletFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, receiverID, walletID string, status ReceiversWalletStatus) *ReceiverWallet

type ReceiverWalletAsset

type ReceiverWalletAsset struct {
	WalletID                string         `db:"wallet_id"`
	ReceiverWallet          ReceiverWallet `db:"receiver_wallet"`
	Asset                   Asset          `db:"asset"`
	DisbursementSMSTemplate *string        `json:"-" db:"sms_registration_message_template"`
}

type ReceiverWalletInsert

type ReceiverWalletInsert struct {
	ReceiverID string
	WalletID   string
}

type ReceiverWalletModel

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

func (*ReceiverWalletModel) GetAllPendingRegistrationByDisbursementID

func (rw *ReceiverWalletModel) GetAllPendingRegistrationByDisbursementID(ctx context.Context, sqlExec db.SQLExecuter, disbursementID string) ([]*ReceiverWallet, error)

func (*ReceiverWalletModel) GetAllPendingRegistrationByReceiverWalletIDs

func (rw *ReceiverWalletModel) GetAllPendingRegistrationByReceiverWalletIDs(ctx context.Context, sqlExec db.SQLExecuter, receiverWalletIDs []string) ([]*ReceiverWallet, error)

func (*ReceiverWalletModel) GetAllPendingRegistrations

func (rw *ReceiverWalletModel) GetAllPendingRegistrations(ctx context.Context, sqlExec db.SQLExecuter) ([]*ReceiverWallet, error)

func (*ReceiverWalletModel) GetByReceiverIDAndWalletDomain

func (rw *ReceiverWalletModel) GetByReceiverIDAndWalletDomain(ctx context.Context, receiverId string, walletDomain string, sqlExec db.SQLExecuter) (*ReceiverWallet, error)

GetByReceiverIDAndWalletDomain returns a receiver wallet that match the receiver ID and wallet domain.

func (*ReceiverWalletModel) GetByReceiverIDsAndWalletID

func (rw *ReceiverWalletModel) GetByReceiverIDsAndWalletID(ctx context.Context, sqlExec db.SQLExecuter, receiverIds []string, walletId string) ([]*ReceiverWallet, error)

GetByReceiverIDsAndWalletID returns a list of receiver wallets by receiver IDs and wallet ID.

func (*ReceiverWalletModel) GetByStellarAccountAndMemo

func (rw *ReceiverWalletModel) GetByStellarAccountAndMemo(ctx context.Context, stellarAccount, stellarMemo, clientDomain string) (*ReceiverWallet, error)

GetByStellarAccountAndMemo returns a receiver wallets that match the Stellar Account, memo and client domain.

func (*ReceiverWalletModel) GetWithReceiverIds

func (rw *ReceiverWalletModel) GetWithReceiverIds(ctx context.Context, sqlExec db.SQLExecuter, receiverIds ReceiverIDs) ([]ReceiverWallet, error)

func (*ReceiverWalletModel) Insert

func (rw *ReceiverWalletModel) Insert(ctx context.Context, sqlExec db.SQLExecuter, insert ReceiverWalletInsert) (string, error)

Insert inserts a new receiver wallet into the database.

func (*ReceiverWalletModel) RetryInvitationSMS

func (rw *ReceiverWalletModel) RetryInvitationSMS(ctx context.Context, sqlExec db.SQLExecuter, receiverWalletId string) (*ReceiverWallet, error)

RetryInvitationSMS sets null the invitation_sent_at of a receiver wallet.

func (*ReceiverWalletModel) UpdateAnchorPlatformTransactionSyncedAt

func (rw *ReceiverWalletModel) UpdateAnchorPlatformTransactionSyncedAt(ctx context.Context, sqlExec db.SQLExecuter, receiverWalletID ...string) ([]ReceiverWallet, error)

func (*ReceiverWalletModel) UpdateInvitationSentAt

func (rw *ReceiverWalletModel) UpdateInvitationSentAt(ctx context.Context, sqlExec db.SQLExecuter, receiverWalletID ...string) ([]ReceiverWallet, error)

func (*ReceiverWalletModel) UpdateOTPByReceiverPhoneNumberAndWalletDomain

func (rw *ReceiverWalletModel) UpdateOTPByReceiverPhoneNumberAndWalletDomain(ctx context.Context, receiverPhoneNumber, sep10ClientDomain, otp string) (numberOfUpdatedRows int, err error)

UpdateOTPByReceiverPhoneNumberAndWalletDomain updates receiver wallet OTP if its not verified yet, and returns the number of updated rows.

func (*ReceiverWalletModel) UpdateReceiverWallet

func (rw *ReceiverWalletModel) UpdateReceiverWallet(ctx context.Context, receiverWallet ReceiverWallet, sqlExec db.SQLExecuter) error

UpdateReceiverWallet updates the status, address, OTP confirmation time, and anchor platform transaction ID of a receiver wallet.

func (*ReceiverWalletModel) UpdateStatusByDisbursementID

func (rw *ReceiverWalletModel) UpdateStatusByDisbursementID(ctx context.Context, sqlExec db.SQLExecuter, disbursementID string, from, to ReceiversWalletStatus) error

UpdateStatusByDisbursementID updates the status of the receiver wallets associated with a disbursement.

func (*ReceiverWalletModel) VerifyReceiverWalletOTP

func (rw *ReceiverWalletModel) VerifyReceiverWalletOTP(ctx context.Context, networkPassphrase string, receiverWallet ReceiverWallet, otp string) error

VerifyReceiverWalletOTP validates the receiver wallet OTP.

type ReceiverWalletStats

type ReceiverWalletStats struct {
	TotalPayments     string          `json:"total_payments,omitempty" db:"total_payments"`
	PaymentsReceived  string          `json:"payments_received,omitempty" db:"payments_received"`
	FailedPayments    string          `json:"failed_payments,omitempty" db:"failed_payments"`
	CanceledPayments  string          `json:"canceled_payments,omitempty" db:"canceled_payments"`
	RemainingPayments string          `json:"remaining_payments,omitempty" db:"remaining_payments"`
	ReceivedAmounts   ReceivedAmounts `json:"received_amounts,omitempty" db:"received_amounts"`
	// TotalInvitationSMSResentAttempts holds how many times were resent the Invitation SMS to the receiver
	// since the last invitation has been sent.
	TotalInvitationSMSResentAttempts int64 `json:"-" db:"total_invitation_sms_resent_attempts"`
}

type ReceiversWalletStatus

type ReceiversWalletStatus string
const (
	DraftReceiversWalletStatus      ReceiversWalletStatus = "DRAFT"
	ReadyReceiversWalletStatus      ReceiversWalletStatus = "READY"
	RegisteredReceiversWalletStatus ReceiversWalletStatus = "REGISTERED"
	FlaggedReceiversWalletStatus    ReceiversWalletStatus = "FLAGGED"
)

func (ReceiversWalletStatus) State

func (status ReceiversWalletStatus) State() State

func (ReceiversWalletStatus) TransitionTo

func (status ReceiversWalletStatus) TransitionTo(targetState ReceiversWalletStatus) error

TransitionTo transitions the receiver wallet status to the target state

type ReceiversWalletStatusHistory

type ReceiversWalletStatusHistory []ReceiversWalletStatusHistoryEntry

func (*ReceiversWalletStatusHistory) Scan

func (rwsh *ReceiversWalletStatusHistory) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (ReceiversWalletStatusHistory) Value

Value implements the driver.Valuer interface.

type ReceiversWalletStatusHistoryEntry

type ReceiversWalletStatusHistoryEntry struct {
	Status    ReceiversWalletStatus `json:"status"`
	Timestamp time.Time             `json:"timestamp"`
}

type SortField

type SortField string
const (
	SortFieldName      SortField = "name"
	SortFieldEmail     SortField = "email"
	SortFieldIsActive  SortField = "is_active"
	SortFieldCreatedAt SortField = "created_at"
	SortFieldUpdatedAt SortField = "updated_at"
)

type SortOrder

type SortOrder string
const (
	SortOrderASC  SortOrder = "ASC"
	SortOrderDESC SortOrder = "DESC"
)

type State

type State string

type StateMachine

type StateMachine struct {
	CurrentState State
	Transitions  map[State]map[State]bool
}

func DisbursementStateMachineWithInitialState

func DisbursementStateMachineWithInitialState(initialState DisbursementStatus) *StateMachine

DisbursementStateMachineWithInitialState returns a state machine for disbursements initialized with the given state

func NewStateMachine

func NewStateMachine(initialState State, transitions []StateTransition) *StateMachine

func PaymentStateMachineWithInitialState

func PaymentStateMachineWithInitialState(initialState PaymentStatus) *StateMachine

PaymentStateMachineWithInitialState returns a state machine for Payments initialized with the given state

func ReceiversWalletStateMachineWithInitialState

func ReceiversWalletStateMachineWithInitialState(initialState ReceiversWalletStatus) *StateMachine

ReceiversWalletStateMachineWithInitialState returns a state machine for ReceiversWallets initialized with the given state

func (*StateMachine) CanTransitionTo

func (sm *StateMachine) CanTransitionTo(targetState State) bool

func (*StateMachine) TransitionTo

func (sm *StateMachine) TransitionTo(targetState State) error

type StateTransition

type StateTransition struct {
	From State
	To   State
}

type UserRole

type UserRole string
const (
	// OwnerUserRole has permission to do everything. Also, it's in charge of creating new users and managing Org account.
	OwnerUserRole UserRole = "owner"
	// FinancialControllerUserRole has the same permissions as the OwnerUserRole except for user management.
	FinancialControllerUserRole UserRole = "financial_controller"
	// DeveloperUserRole has only configuration permissions. (wallets, assets, countries management. Also, statistics access permission)
	DeveloperUserRole UserRole = "developer"
	// BusinessUserRole has read-only permissions - except for user management that they can't read any data.
	BusinessUserRole UserRole = "business"
)

Roles description reference: https://stellarfoundation.slack.com/archives/C04C9MLM9UZ/p1681238994830149

func GetAllRoles

func GetAllRoles() []UserRole

GetAllRoles returns all roles available

func (UserRole) IsValid

func (u UserRole) IsValid() bool

func (UserRole) String

func (u UserRole) String() string

type VerificationField

type VerificationField string
const (
	VerificationFieldDateOfBirth VerificationField = "DATE_OF_BIRTH"
	VerificationFieldPin         VerificationField = "PIN"
	VerificationFieldNationalID  VerificationField = "NATIONAL_ID_NUMBER"
)

func GetAllVerificationFields

func GetAllVerificationFields() []VerificationField

GetAllVerificationFields returns all verification fields

type Wallet

type Wallet struct {
	ID                string       `json:"id" db:"id"`
	Name              string       `json:"name" db:"name"`
	Homepage          string       `json:"homepage,omitempty" db:"homepage"`
	SEP10ClientDomain string       `json:"sep_10_client_domain,omitempty" db:"sep_10_client_domain"`
	DeepLinkSchema    string       `json:"deep_link_schema,omitempty" db:"deep_link_schema"`
	Enabled           bool         `json:"enabled" db:"enabled"`
	Assets            WalletAssets `json:"assets,omitempty" db:"assets"`
	CreatedAt         *time.Time   `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt         *time.Time   `json:"updated_at,omitempty" db:"updated_at"`
	DeletedAt         *time.Time   `json:"-" db:"deleted_at"`
}

func ClearAndCreateWalletFixtures

func ClearAndCreateWalletFixtures(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter) []Wallet

ClearAndCreateWalletFixtures deletes all wallets in the database then creates new wallets for testing

func CreateDefaultWalletFixture

func CreateDefaultWalletFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter) *Wallet

func CreateWalletFixture

func CreateWalletFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, name, homepage, sep10ClientDomain, deepLinkSchema string) *Wallet

func GetWalletFixture

func GetWalletFixture(t *testing.T, ctx context.Context, sqlExec db.SQLExecuter, name string) *Wallet

type WalletAssets

type WalletAssets []Asset

func (*WalletAssets) Scan

func (wa *WalletAssets) Scan(src interface{}) error

type WalletInsert

type WalletInsert struct {
	Name              string   `db:"name"`
	Homepage          string   `db:"homepage"`
	SEP10ClientDomain string   `db:"sep_10_client_domain"`
	DeepLinkSchema    string   `db:"deep_link_schema"`
	AssetsIDs         []string `db:"assets_ids"`
}

type WalletModel

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

func (*WalletModel) FindWallets

func (wm *WalletModel) FindWallets(ctx context.Context, enabledFilter *bool) ([]Wallet, error)

FindWallets returns wallets filtering by enabled status.

func (*WalletModel) Get

func (wm *WalletModel) Get(ctx context.Context, id string) (*Wallet, error)

func (*WalletModel) GetAll

func (wm *WalletModel) GetAll(ctx context.Context) ([]Wallet, error)

GetAll returns all wallets in the database

func (*WalletModel) GetAssets

func (wm *WalletModel) GetAssets(ctx context.Context, walletID string) ([]Asset, error)

func (*WalletModel) GetByWalletName

func (wm *WalletModel) GetByWalletName(ctx context.Context, name string) (*Wallet, error)

GetByWalletName returns wallet filtering by wallet name.

func (*WalletModel) GetOrCreate

func (wm *WalletModel) GetOrCreate(ctx context.Context, name, homepage, deepLink, sep10Domain string) (*Wallet, error)

func (*WalletModel) Insert

func (wm *WalletModel) Insert(ctx context.Context, newWallet WalletInsert) (*Wallet, error)

func (*WalletModel) SoftDelete

func (w *WalletModel) SoftDelete(ctx context.Context, walletID string) (*Wallet, error)

func (*WalletModel) Update

func (wm *WalletModel) Update(ctx context.Context, walletID string, enabled bool) (*Wallet, error)

Jump to

Keyboard shortcuts

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