Documentation ¶
Overview ¶
Package payment provides the payment service
This service handles all payment related business logic
Index ¶
- Constants
- func CanCallback(c Callbacker) bool
- type Callbacker
- type CommitIntentFunc
- type CommitIntentWorker
- type PostIntentWorker
- type PreIntentWorker
- type Service
- func (s *Service) CreatePayment(tx *sql.Tx, p *payment.Payment) error
- func (s *Service) CreatePaymentToken(tx *sql.Tx, p *payment.Payment) (*payment.PaymentToken, error)
- func (s *Service) DecodedPaymentID(id payment.PaymentID) payment.PaymentID
- func (s *Service) DeletePaymentToken(tx *sql.Tx, token string) error
- func (s *Service) EncodedPaymentID(id payment.PaymentID) payment.PaymentID
- func (s *Service) IntentAuthorized(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
- func (s *Service) IntentCancel(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
- func (s *Service) IntentOpen(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
- func (s *Service) IntentPaid(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
- func (s *Service) IsInitialized(p *payment.Payment) bool
- func (s *Service) IsProcessablePayment(p *payment.Payment) bool
- func (s *Service) PaymentByToken(tx *sql.Tx, token string) (*payment.Payment, error)
- func (s *Service) PaymentTransaction(tx *sql.Tx, p *payment.Payment) (*payment.PaymentTransaction, error)
- func (s *Service) RegisterCommitIntentWorker(worker CommitIntentWorker)
- func (s *Service) RegisterPostIntentWorker(worker PostIntentWorker)
- func (s *Service) RegisterPreIntentWorker(worker PreIntentWorker)
- func (s *Service) SetPaymentConfig(tx *sql.Tx, p *payment.Payment) error
- func (s *Service) SetPaymentMetadata(tx *sql.Tx, p *payment.Payment) error
- func (s *Service) SetPaymentTransaction(tx *sql.Tx, paymentTx *payment.PaymentTransaction) error
Constants ¶
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 )
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 ¶
NewService creates a new payment service
func (*Service) CreatePayment ¶
CreatePayment creates a new payment
func (*Service) CreatePaymentToken ¶
CreatePaymentToken creates a new random payment token
func (*Service) DecodedPaymentID ¶
DecodedPaymentID returns a payment id with the id part decoded
func (*Service) DeletePaymentToken ¶
DeletePaymentToken deletes/invalidates the given payment token
func (*Service) EncodedPaymentID ¶
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 (s *Service) IntentCancel(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
func (*Service) IntentOpen ¶
func (s *Service) IntentOpen(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
func (*Service) IntentPaid ¶
func (s *Service) IntentPaid(p *payment.Payment, timeout time.Duration) (*payment.PaymentTransaction, CommitIntentFunc, error)
func (*Service) IsInitialized ¶
IsInitialized returns true when the payment is in a processing state, i.e. when there is at least one transaction present
func (*Service) IsProcessablePayment ¶
IsProcessablePayment returns true if the given payment is considered processable
All required fields are present.
func (*Service) PaymentByToken ¶
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 ¶
SetPaymentConfig sets/updates the payment configuration
func (*Service) SetPaymentMetadata ¶
SetPaymentMetadata sets/updates the payment metadata
func (*Service) SetPaymentTransaction ¶
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 |