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: 14 Imported by: 5

Documentation

Overview

Package payment provides the payment service

This service handles all payment related business logic

Index

Constants

View Source
const (
	// general database error
	ErrDB errorID = iota
	// lock wait timeout
	ErrDBLockTimeout
	// duplicate Ident in payment
	ErrDuplicateIdent
	// callback config error
	ErrPaymentCallbackConfig
	// payment method not found
	ErrPaymentMethodNotFound
	// payment method project mismatch
	ErrPaymentMethodConflict
	// payment method inactive
	ErrPaymentMethodInactive
	// payment method disabled
	ErrPaymentMethodDisabled
	// internal error
	ErrInternal
	// intent timeout
	ErrIntentTimeout
	// intent not allowed
	ErrIntentNotAllowed
)
View Source
const (
	// PaymentTokenMaxAgeDefault is the default maximum age of payment tokens
	PaymentTokenMaxAgeDefault = time.Minute * 15
	// PaymentTokenParam is the name of the token parameter
	PaymentTokenParam = "token"
)

Variables

This section is empty.

Functions

func CanCallback

func CanCallback(c Callbacker) bool

Types

type Callbacker

type Callbacker interface {
	HasCallback() bool
	CallbackConfig() (url, apiVersion, projectKey string)
}

Callbacker describes a type that can provide information about callbacks to be made

type CommitIntentFunc

type CommitIntentFunc func()

type CommitIntentWorker

type CommitIntentWorker interface {
	CommitIntent(paymentTx *payment.PaymentTransaction) error
}

CommitIntentWorker are invoked when the intent is committed through the returned CommitIntentFunc. The intended state change is considered committed and subsequent actions can be taken.

The default Payment Service has the notification registered as a default commit intent worker.

type PostIntentWorker

type PostIntentWorker interface {
	PostIntent(p payment.Payment, paymentTx payment.PaymentTransaction) <-chan error
}

PostIntentWorker are invoked concurrently right before the Intent* methods will return the matching Transaction. At this point the intent cannot be cancelled. Any errors sent through the returned channel will be logged.

type PreIntentWorker

type PreIntentWorker interface {
	PreIntent(p payment.Payment, paymentTx payment.PaymentTransaction, done <-chan struct{}, res chan<- error)
}

IntentWorkers are the primary means of synchronizing and controlling changes on payment states.

IntentWorkers are registered with the payment service via the Service.RegiserIntentWorker method.

Whenever another service or process wishes to change the state of a payment, it should do so by invoking one of the Intent* methods. These methods will create the matching PaymentTransaction types and start the intent procedure.

PreIntent is invoked prior to the intent creation. Any errors sent through the res channel will cancel the intent procedure and the calling service will receive the first encountered error. Once the done channel is closed, the intent procedure won't accept any results of the IntentWorker anymore. This is usually due to timeout.

type Service

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

Service is the payment service

func NewService

func NewService(ctx *service.Context) (*Service, error)

NewService creates a new payment service

func (*Service) CreatePayment

func (s *Service) CreatePayment(tx *sql.Tx, p *payment.Payment) error

CreatePayment creates a new payment

func (*Service) CreatePaymentToken

func (s *Service) CreatePaymentToken(tx *sql.Tx, p *payment.Payment) (*payment.PaymentToken, error)

CreatePaymentToken creates a new random payment token

func (*Service) DecodedPaymentID

func (s *Service) DecodedPaymentID(id payment.PaymentID) payment.PaymentID

DecodedPaymentID returns a payment id with the id part decoded

func (*Service) DeletePaymentToken

func (s *Service) DeletePaymentToken(tx *sql.Tx, token string) error

DeletePaymentToken deletes/invalidates the given payment token

func (*Service) EncodedPaymentID

func (s *Service) EncodedPaymentID(id payment.PaymentID) payment.PaymentID

EncodedPaymentID returns a payment id with the id part encoded

func (*Service) IntentAuthorized

func (s *Service) IntentAuthorized(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)

func (*Service) IntentCancel

func (*Service) IntentOpen

func (*Service) IntentPaid

func (*Service) IsInitialized

func (s *Service) IsInitialized(p *payment.Payment) bool

IsInitialized returns true when the payment is in a processing state, i.e. when there is at least one transaction present

func (*Service) IsProcessablePayment

func (s *Service) IsProcessablePayment(p *payment.Payment) bool

IsProcessablePayment returns true if the given payment is considered processable

All required fields are present.

func (*Service) PaymentByToken

func (s *Service) PaymentByToken(tx *sql.Tx, token string) (*payment.Payment, error)

PaymentByToken returns the payment associated with the given payment token

TODO use token max age from config

func (*Service) PaymentTransaction

func (s *Service) PaymentTransaction(tx *sql.Tx, p *payment.Payment) (*payment.PaymentTransaction, error)

PaymentTransaction returns the current payment transaction for the given payment

PaymentTransaction will return a payment.ErrPaymentTransactionNotFound if no such transaction exists (i.e. the payment is uninitialized)

func (*Service) RegisterCommitIntentWorker

func (s *Service) RegisterCommitIntentWorker(worker CommitIntentWorker)

func (*Service) RegisterPostIntentWorker

func (s *Service) RegisterPostIntentWorker(worker PostIntentWorker)

func (*Service) RegisterPreIntentWorker

func (s *Service) RegisterPreIntentWorker(worker PreIntentWorker)

func (*Service) SetPaymentConfig

func (s *Service) SetPaymentConfig(tx *sql.Tx, p *payment.Payment) error

SetPaymentConfig sets/updates the payment configuration

func (*Service) SetPaymentMetadata

func (s *Service) SetPaymentMetadata(tx *sql.Tx, p *payment.Payment) error

SetPaymentMetadata sets/updates the payment metadata

func (*Service) SetPaymentTransaction

func (s *Service) SetPaymentTransaction(tx *sql.Tx, paymentTx *payment.PaymentTransaction) error

SetPaymentTransaction adds a new payment transaction

If a callback method is configured for this payment/project, it will send a callback notification

Directories

Path Synopsis
Package notification provides notification (or callback) related functionality
Package notification provides notification (or callback) related functionality
v2
Package notification provides the Notification type for notifications in the version: 2.x
Package notification provides the Notification type for notifications in the version: 2.x

Jump to

Keyboard shortcuts

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