add pluggable PayBridge and Dojo payment flow with CMS credentials
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package paymentsvc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var ErrPaymentInProgress = errors.New("payment is already in progress")
|
||||
|
||||
type Provider interface {
|
||||
Sale(ctx context.Context, req SaleRequest) (*Result, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
provider Provider
|
||||
|
||||
mu sync.Mutex
|
||||
busy bool
|
||||
}
|
||||
|
||||
func NewService(provider Provider) *Service {
|
||||
return &Service{provider: provider}
|
||||
}
|
||||
|
||||
func (s *Service) Sale(ctx context.Context, req SaleRequest) (*Result, error) {
|
||||
s.mu.Lock()
|
||||
if s.busy {
|
||||
s.mu.Unlock()
|
||||
return nil, ErrPaymentInProgress
|
||||
}
|
||||
s.busy = true
|
||||
s.mu.Unlock()
|
||||
|
||||
defer func() {
|
||||
s.mu.Lock()
|
||||
s.busy = false
|
||||
s.mu.Unlock()
|
||||
}()
|
||||
|
||||
return s.provider.Sale(ctx, req)
|
||||
}
|
||||
Reference in New Issue
Block a user