rimpay

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: GPL-3.0-or-later Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderBPay   = "bpay"
	ProviderMasrvi = "masrvi"
	ProviderClick  = "click"
)

Provider constants

View Source
const (
	ErrorCodeInvalidRequest       = types.ErrorCodeInvalidRequest
	ErrorCodeAuthenticationFailed = types.ErrorCodeAuthenticationFailed
	ErrorCodeInsufficientFunds    = types.ErrorCodeInsufficientFunds
	ErrorCodePaymentDeclined      = types.ErrorCodePaymentDeclined
	ErrorCodeNetworkError         = types.ErrorCodeNetworkError
	ErrorCodeTimeout              = types.ErrorCodeTimeout
	ErrorCodeProviderError        = types.ErrorCodeProviderError
	ErrorCodeValidationError      = types.ErrorCodeValidationError
	ErrorCodePaymentExpired       = types.ErrorCodePaymentExpired
)

Re-export constants

View Source
const (
	PaymentStatusPending   = types.PaymentStatusPending
	PaymentStatusSuccess   = types.PaymentStatusSuccess
	PaymentStatusFailed    = types.PaymentStatusFailed
	PaymentStatusCancelled = types.PaymentStatusCancelled
	PaymentStatusExpired   = types.PaymentStatusExpired

	LanguageEnglish = types.LanguageEnglish
	LanguageFrench  = types.LanguageFrench
	LanguageArabic  = types.LanguageArabic
)

Re-export constants

Variables

View Source
var (
	NewPaymentError    = types.NewPaymentError
	NewValidationError = types.NewValidationError
	IsRetryableError   = types.IsRetryableError
)

Re-export constructor functions

View Source
var (
	ErrInvalidConfig        = errors.ErrInvalidConfig
	ErrInvalidRequest       = errors.ErrInvalidRequest
	ErrProviderNotFound     = errors.ErrProviderNotFound
	ErrInvalidProvider      = errors.ErrInvalidProvider
	ErrPaymentFailed        = errors.ErrPaymentFailed
	ErrAuthenticationFailed = errors.ErrAuthenticationFailed
	ErrNetworkError         = errors.ErrNetworkError
	ErrTimeout              = errors.ErrTimeout
)

Re-export common errors

View Source
var DefaultRegistry = NewProviderRegistry()

DefaultRegistry is the default global provider registry

Functions

func RegisterBPayProvider

func RegisterBPayProvider(factory func(ProviderConfig, Logger) (PaymentProvider, error))

RegisterBPayProvider registers the B-PAY provider factory

func RegisterClickProvider added in v0.4.0

func RegisterClickProvider(factory func(ProviderConfig, Logger) (PaymentProvider, error))

RegisterClickProvider registers the CLICK provider factory

func RegisterMasrviProvider

func RegisterMasrviProvider(factory func(ProviderConfig, Logger) (PaymentProvider, error))

RegisterMasrviProvider registers the MASRVI provider factory

Types

type BPayPaymentRequest

type BPayPaymentRequest struct {
	PhoneNumber *phone.Phone           `json:"phone_number"`
	Amount      money.Money            `json:"amount"`
	Description string                 `json:"description"`
	Reference   string                 `json:"reference"`
	Passcode    string                 `json:"passcode"` // B-PAY specific: user passcode
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

BPayPaymentRequest represents a B-PAY specific payment request

func (*BPayPaymentRequest) ToGenericRequest

func (r *BPayPaymentRequest) ToGenericRequest() *PaymentRequest

ToGenericRequest converts B-PAY request to generic payment request

func (*BPayPaymentRequest) Validate

func (r *BPayPaymentRequest) Validate() error

Validate validates the B-PAY payment request

type BPayProvider

type BPayProvider interface {
	// Name returns the provider name
	Name() string

	// IsAvailable checks if the provider is available
	IsAvailable(ctx context.Context) bool

	// ProcessBPayPayment processes a B-PAY payment
	ProcessBPayPayment(ctx context.Context, request *BPayPaymentRequest) (*PaymentResponse, error)

	// GetPaymentStatus gets payment status
	GetPaymentStatus(ctx context.Context, transactionID string) (*TransactionStatus, error)

	// ValidateConfig validates provider configuration
	ValidateConfig() error
}

BPayProvider represents the B-PAY payment provider interface

type ClickNotificationData added in v0.4.0

type ClickNotificationData struct {
	Status      string `json:"status"` // OK / NOK
	PurchaseRef string `json:"purchaseref"`
	Amount      string `json:"amount"`
	Currency    string `json:"currency"`
	ClientID    string `json:"clientid"`
	ClientName  string `json:"cname"`
	Mobile      string `json:"mobile"`
	PaymentRef  string `json:"paymentref"`
	PayID       string `json:"payid"`
	Timestamp   string `json:"timestamp"`
	IPAddress   string `json:"ipaddr"`
	Error       string `json:"error,omitempty"`
	Reason      string `json:"reason,omitempty"`
}

ClickNotificationData is the public shape of a TagPay server-to-server notification (GET query parameters) for the CLICK provider.

type ClickPaymentRequest added in v0.4.0

type ClickPaymentRequest struct {
	PhoneNumber *phone.Phone           `json:"phone_number,omitempty"` // optional
	Amount      money.Money            `json:"amount"`
	Reference   string                 `json:"reference"`
	Description string                 `json:"description,omitempty"`
	SuccessURL  string                 `json:"success_url,omitempty"`
	FailureURL  string                 `json:"failure_url,omitempty"`
	CancelURL   string                 `json:"cancel_url,omitempty"`
	Brand       string                 `json:"brand,omitempty"`
	Language    Language               `json:"language,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

ClickPaymentRequest represents a CLICK (TagPay/BNM) specific payment request.

func (*ClickPaymentRequest) GetLanguage added in v0.4.0

func (r *ClickPaymentRequest) GetLanguage() Language

GetLanguage returns the language with fallback to French.

func (*ClickPaymentRequest) ToGenericRequest added in v0.4.0

func (r *ClickPaymentRequest) ToGenericRequest() *PaymentRequest

ToGenericRequest converts CLICK request to the generic payment request.

func (*ClickPaymentRequest) Validate added in v0.4.0

func (r *ClickPaymentRequest) Validate() error

Validate validates the CLICK payment request.

type ClickProvider added in v0.4.0

type ClickProvider interface {
	// Name returns the provider name
	Name() string

	// IsAvailable checks if the provider is available
	IsAvailable(ctx context.Context) bool

	// ProcessClickPayment processes a CLICK payment
	ProcessClickPayment(ctx context.Context, request *ClickPaymentRequest) (*PaymentResponse, error)

	// GetPaymentStatus gets payment status (note: CLICK uses notifications)
	GetPaymentStatus(ctx context.Context, transactionID string) (*TransactionStatus, error)

	// HandleNotification handles CLICK server-to-server notifications
	HandleNotification(notification *ClickNotificationData) (*TransactionStatus, error)

	// ValidateConfig validates provider configuration
	ValidateConfig() error
}

ClickProvider represents the CLICK (TagPay/BNM) payment provider interface

type Client

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

Client represents the main payment client

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient creates a new payment client

func (*Client) AddBPayProvider

func (c *Client) AddBPayProvider(config ProviderConfig) error

AddBPayProvider adds a B-PAY provider to the client

func (*Client) AddClickProvider added in v0.4.0

func (c *Client) AddClickProvider(config ProviderConfig) error

AddClickProvider adds a CLICK provider to the client

func (*Client) AddMasrviProvider

func (c *Client) AddMasrviProvider(config ProviderConfig) error

AddMasrviProvider adds a MASRVI provider to the client

func (*Client) AddProvider

func (c *Client) AddProvider(name string, provider PaymentProvider) error

AddProvider adds a payment provider to the client

func (*Client) GetBPayProvider

func (c *Client) GetBPayProvider() (BPayProvider, error)

GetBPayProvider returns the B-PAY provider if available

func (*Client) GetClickProvider added in v0.4.0

func (c *Client) GetClickProvider() (ClickProvider, error)

GetClickProvider returns the CLICK provider if available

func (*Client) GetMasrviProvider

func (c *Client) GetMasrviProvider() (MasrviProvider, error)

GetMasrviProvider returns the MASRVI provider if available

func (*Client) GetPaymentStatus

func (c *Client) GetPaymentStatus(ctx context.Context, transactionID string) (*TransactionStatus, error)

GetPaymentStatus retrieves payment status from the first available provider

func (*Client) HandleClickNotification added in v0.4.0

func (c *Client) HandleClickNotification(notification *ClickNotificationData) (*TransactionStatus, error)

HandleClickNotification handles CLICK server-to-server notifications

func (*Client) HandleMasrviNotification

func (c *Client) HandleMasrviNotification(notification *MasrviNotificationData) (*TransactionStatus, error)

HandleMasrviNotification handles MASRVI webhook notifications

func (*Client) ListProviders

func (c *Client) ListProviders() []string

ListProviders returns list of available providers

func (*Client) ProcessBPayPayment

func (c *Client) ProcessBPayPayment(ctx context.Context, request *BPayPaymentRequest) (*PaymentResponse, error)

ProcessBPayPayment processes a payment using B-PAY provider

func (*Client) ProcessClickPayment added in v0.4.0

func (c *Client) ProcessClickPayment(ctx context.Context, request *ClickPaymentRequest) (*PaymentResponse, error)

ProcessClickPayment processes a payment using the CLICK provider

func (*Client) ProcessMasrviPayment

func (c *Client) ProcessMasrviPayment(ctx context.Context, request *MasrviPaymentRequest) (*PaymentResponse, error)

ProcessMasrviPayment processes a payment using MASRVI provider

func (*Client) ProcessPayment

func (c *Client) ProcessPayment(ctx context.Context, request *PaymentRequest) (*PaymentResponse, error)

ProcessPayment processes a payment using the generic interface (deprecated)

type Config

type Config struct {
	Environment     Environment               `json:"environment"`
	DefaultProvider string                    `json:"default_provider"`
	Providers       map[string]ProviderConfig `json:"providers"`
	HTTP            HTTPConfig                `json:"http"`
	Logging         LoggingConfig             `json:"logging"`
	Security        SecurityConfig            `json:"security"`
}

Config represents main configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default configuration

func (*Config) GetProviderConfig

func (c *Config) GetProviderConfig(name string) (ProviderConfig, bool)

GetProviderConfig returns provider configuration

func (*Config) IsProduction

func (c *Config) IsProduction() bool

IsProduction returns true if production environment

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type Environment

type Environment string
const (
	// EnvironmentSandbox for testing
	EnvironmentSandbox Environment = "sandbox"
	// EnvironmentProduction for live transactions
	EnvironmentProduction Environment = "production"
)

type ErrorCode

type ErrorCode = types.ErrorCode

Re-export types from internal/types for public API

type HTTPClient

type HTTPClient interface {
	Do(req *HTTPRequest) (*HTTPResponse, error)
}

type HTTPConfig

type HTTPConfig struct {
	Timeout         time.Duration `json:"timeout"`
	MaxIdleConns    int           `json:"max_idle_conns"`
	MaxConnsPerHost int           `json:"max_conns_per_host"`
	UserAgent       string        `json:"user_agent"`
}

HTTPConfig represents HTTP configuration

type HTTPRequest

type HTTPRequest struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    []byte
	Timeout time.Duration
}

HTTPRequest represents an HTTP request

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Headers    map[string]string
	Body       []byte
}

type Language

type Language = types.Language

Re-export types from internal/types for public API

type Logger

type Logger interface {
	Debug(msg string, fields ...interface{})
	Info(msg string, fields ...interface{})
	Warn(msg string, fields ...interface{})
	Error(msg string, fields ...interface{})
}

type LoggingConfig

type LoggingConfig struct {
	Level  string `json:"level"`
	Format string `json:"format"`
	Output string `json:"output"`
}

LoggingConfig represents logging configuration

type MasrviNotificationData

type MasrviNotificationData struct {
	TransactionID string                 `json:"transaction_id"`
	Status        string                 `json:"status"`
	Reference     string                 `json:"reference"`
	Amount        money.Money            `json:"amount"`
	PhoneNumber   string                 `json:"phone_number"`
	Timestamp     string                 `json:"timestamp"`
	Data          map[string]interface{} `json:"data,omitempty"`
}

MasrviNotificationData represents MASRVI webhook notification

type MasrviPaymentRequest

type MasrviPaymentRequest struct {
	PhoneNumber *phone.Phone           `json:"phone_number"`
	Amount      money.Money            `json:"amount"`
	Description string                 `json:"description"`
	Reference   string                 `json:"reference"`
	CallbackURL string                 `json:"callback_url"` // MASRVI specific: webhook URL
	ReturnURL   string                 `json:"return_url"`   // MASRVI specific: return URL after payment
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

MasrviPaymentRequest represents a MASRVI specific payment request

func (*MasrviPaymentRequest) ToGenericRequest

func (r *MasrviPaymentRequest) ToGenericRequest() *PaymentRequest

ToGenericRequest converts MASRVI request to generic payment request

func (*MasrviPaymentRequest) Validate

func (r *MasrviPaymentRequest) Validate() error

Validate validates the MASRVI payment request

type MasrviProvider

type MasrviProvider interface {
	// Name returns the provider name
	Name() string

	// IsAvailable checks if the provider is available
	IsAvailable(ctx context.Context) bool

	// ProcessPayment processes a MASRVI payment
	ProcessMasrviPayment(ctx context.Context, request *MasrviPaymentRequest) (*PaymentResponse, error)

	// GetPaymentStatus gets payment status (note: MASRVI uses webhooks)
	GetPaymentStatus(ctx context.Context, transactionID string) (*TransactionStatus, error)

	// HandleNotification handles MASRVI webhook notifications
	HandleNotification(notification *MasrviNotificationData) (*TransactionStatus, error)

	// ValidateConfig validates provider configuration
	ValidateConfig() error
}

MasrviProvider represents the MASRVI payment provider interface

type PaymentError

type PaymentError = types.PaymentError

Re-export types from internal/types for public API

type PaymentProvider

type PaymentProvider interface {
	// Name returns the provider name
	Name() string

	// IsAvailable checks if the provider is available
	IsAvailable(ctx context.Context) bool

	// ProcessPayment processes a payment
	ProcessPayment(ctx context.Context, request *PaymentRequest) (*PaymentResponse, error)

	// GetPaymentStatus gets payment status
	GetPaymentStatus(ctx context.Context, transactionID string) (*TransactionStatus, error)

	// ValidateConfig validates provider configuration
	ValidateConfig() error
}

type PaymentRequest

type PaymentRequest = types.PaymentRequest

Re-export types from internal/types for public API

type PaymentResponse

type PaymentResponse = types.PaymentResponse

Re-export types from internal/types for public API

type PaymentStatus

type PaymentStatus = types.PaymentStatus

Re-export types from internal/types for public API

type ProviderConfig

type ProviderConfig struct {
	Enabled     bool                   `json:"enabled"`
	BaseURL     string                 `json:"base_url"`
	Credentials map[string]string      `json:"credentials"`
	Timeout     time.Duration          `json:"timeout"`
	Options     map[string]interface{} `json:"options"`
}

ProviderConfig represents provider configuration

type ProviderFactory

type ProviderFactory func(config ProviderConfig, logger Logger) (PaymentProvider, error)

ProviderFactory creates payment providers

type ProviderRegistry

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

ProviderRegistry manages payment provider factories

func NewProviderRegistry

func NewProviderRegistry() *ProviderRegistry

NewProviderRegistry creates a new provider registry

func (*ProviderRegistry) Create

func (r *ProviderRegistry) Create(name string, config ProviderConfig, logger Logger) (PaymentProvider, error)

Create creates a provider instance

func (*ProviderRegistry) GetRegisteredProviders

func (r *ProviderRegistry) GetRegisteredProviders() []string

GetRegisteredProviders returns list of registered provider names

func (*ProviderRegistry) Register

func (r *ProviderRegistry) Register(name string, factory ProviderFactory)

Register registers a provider factory

type SecurityConfig

type SecurityConfig struct {
	EncryptionKey string        `json:"encryption_key"`
	SigningKey    string        `json:"signing_key"`
	TokenTTL      time.Duration `json:"token_ttl"`
}

SecurityConfig represents security configuration

type StatusEvent

type StatusEvent struct {
	Status    PaymentStatus          `json:"status"`
	Timestamp time.Time              `json:"timestamp"`
	Message   string                 `json:"message,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

StatusEvent represents status change event

type TransactionStatus

type TransactionStatus struct {
	TransactionID     string                 `json:"transaction_id"`
	Status            PaymentStatus          `json:"status"`
	Amount            money.Money            `json:"amount,omitempty"`
	Reference         string                 `json:"reference"`
	ProviderReference string                 `json:"provider_reference,omitempty"`
	Message           string                 `json:"message,omitempty"`
	LastUpdated       time.Time              `json:"last_updated"`
	Events            []StatusEvent          `json:"events,omitempty"`
	ProviderData      map[string]interface{} `json:"provider_data,omitempty"`
}

func (*TransactionStatus) AddEvent

func (ts *TransactionStatus) AddEvent(status PaymentStatus, message string)

AddEvent adds a status event

func (*TransactionStatus) GetLatestEvent

func (ts *TransactionStatus) GetLatestEvent() *StatusEvent

GetLatestEvent returns the most recent status event

func (*TransactionStatus) IsCompleted

func (ts *TransactionStatus) IsCompleted() bool

IsCompleted returns true if transaction is completed

func (*TransactionStatus) IsSuccessful

func (ts *TransactionStatus) IsSuccessful() bool

IsSuccessful returns true if transaction was successful

type Validator

type Validator interface {
	ValidatePaymentRequest(request *PaymentRequest) error
	ValidateAmount(amount money.Money) error
	ValidatePhoneNumber(phone string) error
}

Validator defines validation interface

Jump to

Keyboard shortcuts

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