Documentation ¶
Overview ¶
Package payment provides Payment Types
Index ¶
- Constants
- Variables
- func DeletePaymentTokenTx(db *sql.Tx, token string) error
- func InsertPaymentConfigTx(db *sql.Tx, p *Payment) error
- func InsertPaymentMetadataTx(db *sql.Tx, p *Payment) error
- func InsertPaymentTokenTx(tx *sql.Tx, t *PaymentToken) error
- func InsertPaymentTransactionTx(db *sql.Tx, paymentTx *PaymentTransaction) error
- func InsertPaymentTx(db *sql.Tx, p *Payment) error
- func PaymentMetadataDB(db *sql.DB, p *Payment) error
- func PaymentMetadataTx(db *sql.Tx, p *Payment) error
- type Balance
- type Config
- func (cfg *Config) CallbackConfig() (url, apiVersion, projectKey string)
- func (cfg *Config) HasCallback() bool
- func (cfg *Config) IsConfigured() bool
- func (cfg *Config) SetCallbackAPIVersion(ver string)
- func (cfg *Config) SetCallbackProjectKey(key string)
- func (cfg *Config) SetCallbackURL(url string)
- func (cfg *Config) SetCountry(country string)
- func (cfg *Config) SetExpires(exp time.Time)
- func (cfg *Config) SetLocale(locale string)
- func (cfg *Config) SetPaymentMethodID(id int64)
- func (cfg *Config) SetReturnURL(url string)
- type IDEncoder
- type Payment
- func PaymentByIDDB(db *sql.DB, id PaymentID) (*Payment, error)
- func PaymentByIDTx(db *sql.Tx, id PaymentID) (*Payment, error)
- func PaymentByProjectIDAndIdentDB(db *sql.DB, projectID int64, ident string) (*Payment, error)
- func PaymentByProjectIDAndIdentTx(db *sql.Tx, projectID int64, ident string) (*Payment, error)
- func PaymentByTokenTx(db *sql.Tx, token string, tokenMaxAge time.Duration) (*Payment, error)
- func (p *Payment) Decimal() *decimal.Decimal
- func (p *Payment) DecimalRound(scale int32) *decimal.Decimal
- func (p *Payment) HasTransaction() bool
- func (p *Payment) ID() int64
- func (p *Payment) NewTransaction(s PaymentTransactionStatus) *PaymentTransaction
- func (p *Payment) PaymentID() PaymentID
- func (p *Payment) ProjectID() int64
- func (p *Payment) SetProject(pr *project.Project) error
- func (p *Payment) Valid() bool
- type PaymentID
- type PaymentToken
- type PaymentTransaction
- type PaymentTransactionList
- type PaymentTransactionStatus
Constants ¶
const ( DefaultLocale = "en_US" // MetadataKeyAcceptLanguage is the key for the Accept-Language header // which will be stored in the metadata MetadataKeyAcceptLanguage = "_fAcceptLanguage" MetadataKeyBrowserLocale = "_fBrowserLocale" MetadataKeyRemoteAddress = "_fRemoteAddress" )
const ( PaymentStatusNone PaymentTransactionStatus = "uninitialized" PaymentStatusOpen = "open" PaymentStatusPending = "pending" PaymentStatusPaid = "paid" PaymentStatusSettled = "settled" PaymentStatusAuthorized = "authorized" PaymentStatusError = "error" PaymentStatusCancelled = "cancelled" PaymentStatusFailed = "failed" PaymentStatusChargeback = "chargeback" PaymentStatusRefunded = "refunded" PaymentStatusRefundReversed = "refund-reversed" )
const (
// IdentMaxLen is the maximum allowed length of an identifier
IdentMaxLen = 175
)
Variables ¶
var (
ErrPaymentNotFound = errors.New("payment not found")
)
var (
ErrPaymentTransactionNotFound = errors.New("payment transaction not found")
)
Functions ¶
func InsertPaymentTokenTx ¶
func InsertPaymentTokenTx(tx *sql.Tx, t *PaymentToken) error
func InsertPaymentTransactionTx ¶
func InsertPaymentTransactionTx(db *sql.Tx, paymentTx *PaymentTransaction) error
Types ¶
type Balance ¶
Balance represents a balance which totals the ledger by currency
func (Balance) MarshalJSON ¶
func (*Balance) UnmarshalJSON ¶
type Config ¶
type Config struct { Timestamp time.Time PaymentMethodID sql.NullInt64 Country sql.NullString Locale sql.NullString CallbackURL sql.NullString CallbackAPIVersion sql.NullString CallbackProjectKey sql.NullString ReturnURL sql.NullString Expires *time.Time }
func (*Config) CallbackConfig ¶
func (*Config) HasCallback ¶
func (*Config) IsConfigured ¶
func (*Config) SetCallbackAPIVersion ¶
func (*Config) SetCallbackProjectKey ¶
func (*Config) SetCallbackURL ¶
func (*Config) SetCountry ¶
func (*Config) SetExpires ¶
func (*Config) SetPaymentMethodID ¶
func (*Config) SetReturnURL ¶
type IDEncoder ¶
type IDEncoder struct {
// contains filtered or unexported fields
}
func NewIDEncoder ¶
type Payment ¶
type Payment struct { Created time.Time Ident string Amount int64 Subunits int8 Currency string Config Config TransactionTimestamp time.Time Status PaymentTransactionStatus Metadata map[string]string // contains filtered or unexported fields }
Payment represents a payment
func PaymentByTokenTx ¶
func (*Payment) Decimal ¶
Decimal returns the decimal representation of the Amount and Subunits values
func (*Payment) HasTransaction ¶
HasTransaction returns true if the payment has a payment transaction entry
func (*Payment) NewTransaction ¶
func (p *Payment) NewTransaction(s PaymentTransactionStatus) *PaymentTransaction
NewTransaction creates a new payment transaction for this payment
Its transaction fields will be populated with the copied values from the payment The payment's transaction timestamp and status fields will be updated with the new transaction values
type PaymentID ¶
PaymentID represents an identifier for a payment
It consists of a project ID and a payment ID
func ParsePaymentIDStr ¶
ParsePaymentIDStr parses a given string of the format
123-12345
into a PaymentID.
func (PaymentID) MarshalJSON ¶
MarshalJSON so it can be marshalled to JSON
func (PaymentID) String ¶
String returns the string representation of a payment ID
It is the inverse of the ParsePaymentIDStr
func (*PaymentID) UnmarshalJSON ¶
UnmarshalJSON so it can be unmarshalled from JSON
type PaymentToken ¶
type PaymentToken struct { Token string Created time.Time // contains filtered or unexported fields }
func NewPaymentToken ¶
func NewPaymentToken(id PaymentID) (*PaymentToken, error)
func (*PaymentToken) GenerateToken ¶
func (p *PaymentToken) GenerateToken() error
type PaymentTransaction ¶
type PaymentTransaction struct { Payment *Payment Timestamp time.Time Amount int64 Subunits int8 Currency string Status PaymentTransactionStatus Comment sql.NullString }
PaymentTransaction represents a transaction on a payment
A transaction is any event/status change on a payment
The transactions represents the ledger on a payment
func PaymentTransactionCurrentTx ¶
func PaymentTransactionCurrentTx(db *sql.Tx, p *Payment) (*PaymentTransaction, error)
PaymentTransactionCurrentTx reads the current payment transaction into the given payment (i.e. it sets the TransactionTimestamp and Status fields) and returns the full PaymentTransaction type
If no payment transaction exists, it will return an ErrPaymentTransactionNotFound
func (*PaymentTransaction) Decimal ¶
func (p *PaymentTransaction) Decimal() *decimal.Decimal
type PaymentTransactionList ¶
type PaymentTransactionList []*PaymentTransaction
func PaymentTransactionsBeforeDB ¶
func PaymentTransactionsBeforeDB(db *sql.DB, paymentTx *PaymentTransaction) (PaymentTransactionList, error)
PaymentTransactionsBeforeDB returns a PaymentTransactionList with all transactions before and including the given payment transaction.
The list will be sorted by the earliest tx first.
func PaymentTransactionsBeforeTimestampDB ¶
func PaymentTransactionsBeforeTimestampDB(db *sql.DB, p *Payment, transactionTimestamp time.Time) (PaymentTransactionList, error)
PaymentTransactionsBeforeDB returns a PaymentTransactionList with all transactions before and including the given payment transaction.
The list will be sorted by the earliest tx first.
func (PaymentTransactionList) Balance ¶
func (p PaymentTransactionList) Balance() Balance
type PaymentTransactionStatus ¶
type PaymentTransactionStatus string
func (*PaymentTransactionStatus) Scan ¶
func (s *PaymentTransactionStatus) Scan(v interface{}) error
Scan implements the Scanner interface for sql
func (PaymentTransactionStatus) String ¶
func (s PaymentTransactionStatus) String() string
func (PaymentTransactionStatus) Valid ¶
func (s PaymentTransactionStatus) Valid() bool