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)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package paymentsvc
|
||||
|
||||
type SaleRequest struct {
|
||||
RequestID string `json:"requestId"`
|
||||
Reference string `json:"reference"`
|
||||
Amount int64 `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Success bool `json:"success"`
|
||||
RequestID string `json:"requestId,omitempty"`
|
||||
Operation string `json:"operation,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message,omitempty"`
|
||||
ErrorMessage string `json:"errorMessage,omitempty"`
|
||||
|
||||
TransactionID string `json:"transactionId,omitempty"`
|
||||
ReferenceNumber string `json:"referenceNumber,omitempty"`
|
||||
AuthCode string `json:"authCode,omitempty"`
|
||||
|
||||
Amount int64 `json:"amount"`
|
||||
Currency string `json:"currency"`
|
||||
|
||||
DeviceUsed string `json:"deviceUsed,omitempty"`
|
||||
DeviceType string `json:"deviceType,omitempty"`
|
||||
|
||||
CardNumber string `json:"cardNumber,omitempty"`
|
||||
LastFourDigits string `json:"lastFourDigits,omitempty"`
|
||||
CardType string `json:"cardType,omitempty"`
|
||||
ExpiryDate string `json:"expiryDate,omitempty"`
|
||||
CardHash string `json:"cardHash,omitempty"`
|
||||
CardReference string `json:"cardReference,omitempty"`
|
||||
|
||||
CustomerReceipt string `json:"customerReceipt,omitempty"`
|
||||
MerchantReceipt string `json:"merchantReceipt,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user