payment

package
v0.0.0-...-b3f3fbb Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2015 License: Apache-2.0 Imports: 16 Imported by: 10

Documentation

Overview

Package payment provides Payment Types

Index

Constants

View Source
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"
)
View Source
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"
)
View Source
const (
	// IdentMaxLen is the maximum allowed length of an identifier
	IdentMaxLen = 175
)

Variables

View Source
var (
	ErrPaymentNotFound = errors.New("payment not found")
)
View Source
var (
	ErrPaymentTransactionNotFound = errors.New("payment transaction not found")
)

Functions

func DeletePaymentTokenTx

func DeletePaymentTokenTx(db *sql.Tx, token string) error

func InsertPaymentConfigTx

func InsertPaymentConfigTx(db *sql.Tx, p *Payment) error

func InsertPaymentMetadataTx

func InsertPaymentMetadataTx(db *sql.Tx, p *Payment) error

func InsertPaymentTokenTx

func InsertPaymentTokenTx(tx *sql.Tx, t *PaymentToken) error

func InsertPaymentTransactionTx

func InsertPaymentTransactionTx(db *sql.Tx, paymentTx *PaymentTransaction) error

func InsertPaymentTx

func InsertPaymentTx(db *sql.Tx, p *Payment) error

func PaymentMetadataDB

func PaymentMetadataDB(db *sql.DB, p *Payment) error

func PaymentMetadataTx

func PaymentMetadataTx(db *sql.Tx, p *Payment) error

Types

type Balance

type Balance map[string]*decimal.Decimal

Balance represents a balance which totals the ledger by currency

func (Balance) FlatMap

func (b Balance) FlatMap() map[string]string

func (Balance) MarshalJSON

func (b Balance) MarshalJSON() ([]byte, error)

func (*Balance) UnmarshalJSON

func (b *Balance) UnmarshalJSON(p []byte) error

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 (cfg *Config) CallbackConfig() (url, apiVersion, projectKey string)

func (*Config) HasCallback

func (cfg *Config) HasCallback() bool

func (*Config) IsConfigured

func (cfg *Config) IsConfigured() bool

func (*Config) SetCallbackAPIVersion

func (cfg *Config) SetCallbackAPIVersion(ver string)

func (*Config) SetCallbackProjectKey

func (cfg *Config) SetCallbackProjectKey(key string)

func (*Config) SetCallbackURL

func (cfg *Config) SetCallbackURL(url string)

func (*Config) SetCountry

func (cfg *Config) SetCountry(country string)

func (*Config) SetExpires

func (cfg *Config) SetExpires(exp time.Time)

func (*Config) SetLocale

func (cfg *Config) SetLocale(locale string)

func (*Config) SetPaymentMethodID

func (cfg *Config) SetPaymentMethodID(id int64)

func (*Config) SetReturnURL

func (cfg *Config) SetReturnURL(url string)

type IDEncoder

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

func NewIDEncoder

func NewIDEncoder(p, xor int64) (*IDEncoder, error)

func (*IDEncoder) Hide

func (m *IDEncoder) Hide(i int64) int64

func (*IDEncoder) Show

func (m *IDEncoder) Show(i int64) int64

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 PaymentByIDDB

func PaymentByIDDB(db *sql.DB, id PaymentID) (*Payment, error)

func PaymentByIDTx

func PaymentByIDTx(db *sql.Tx, id PaymentID) (*Payment, error)

func PaymentByProjectIDAndIdentDB

func PaymentByProjectIDAndIdentDB(db *sql.DB, projectID int64, ident string) (*Payment, error)

func PaymentByProjectIDAndIdentTx

func PaymentByProjectIDAndIdentTx(db *sql.Tx, projectID int64, ident string) (*Payment, error)

func PaymentByTokenTx

func PaymentByTokenTx(db *sql.Tx, token string, tokenMaxAge time.Duration) (*Payment, error)

func (*Payment) Decimal

func (p *Payment) Decimal() *decimal.Decimal

Decimal returns the decimal representation of the Amount and Subunits values

func (*Payment) DecimalRound

func (p *Payment) DecimalRound(scale int32) *decimal.Decimal

func (*Payment) HasTransaction

func (p *Payment) HasTransaction() bool

HasTransaction returns true if the payment has a payment transaction entry

func (*Payment) ID

func (p *Payment) ID() int64

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

func (*Payment) PaymentID

func (p *Payment) PaymentID() PaymentID

PaymentID returns the identifier for the payment

func (*Payment) ProjectID

func (p *Payment) ProjectID() int64

func (*Payment) SetProject

func (p *Payment) SetProject(pr *project.Project) error

func (*Payment) Valid

func (p *Payment) Valid() bool

type PaymentID

type PaymentID struct {
	ProjectID int64
	PaymentID int64
}

PaymentID represents an identifier for a payment

It consists of a project ID and a payment ID

func ParseEncodedPaymentIDStr

func ParseEncodedPaymentIDStr(str string, enc *IDEncoder) (PaymentID, error)

func ParsePaymentIDStr

func ParsePaymentIDStr(str string) (PaymentID, error)

ParsePaymentIDStr parses a given string of the format

123-12345

into a PaymentID.

func (PaymentID) Encoded

func (p PaymentID) Encoded(enc *IDEncoder) PaymentID

func (PaymentID) MarshalJSON

func (p PaymentID) MarshalJSON() ([]byte, error)

MarshalJSON so it can be marshalled to JSON

func (PaymentID) String

func (p PaymentID) String() string

String returns the string representation of a payment ID

It is the inverse of the ParsePaymentIDStr

func (*PaymentID) UnmarshalJSON

func (p *PaymentID) UnmarshalJSON(data []byte) error

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

func (*PaymentToken) Valid

func (p *PaymentToken) Valid(timeout time.Duration) bool

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

func (PaymentTransactionStatus) Value

Value implements the Valuer interface for sql

Jump to

Keyboard shortcuts

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