mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
134 lines
3.8 KiB
Go
134 lines
3.8 KiB
Go
package atlar
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/observe/log"
|
|
"github.com/hanzo-fi/payments/ce/plugins/atlar/client"
|
|
pkgplugins "github.com/hanzo-fi/payments/pkg/domain/plugins"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
)
|
|
|
|
const ProviderName = "atlar"
|
|
|
|
var Registration = pkgplugins.Registration{
|
|
PluginType: models.PluginTypePSP,
|
|
CreateFunc: func(_ models.ConnectorID, name string, logger logging.Logger, rm json.RawMessage) (models.Plugin, error) {
|
|
return New(name, logger, rm)
|
|
},
|
|
Capabilities: capabilities,
|
|
RawConf: Config{},
|
|
PageSize: PAGE_SIZE,
|
|
}
|
|
|
|
type Plugin struct {
|
|
models.Plugin
|
|
|
|
name string
|
|
logger logging.Logger
|
|
|
|
client client.Client
|
|
config Config
|
|
}
|
|
|
|
func New(name string, logger logging.Logger, rawConfig json.RawMessage) (*Plugin, error) {
|
|
config, err := unmarshalAndValidateConfig(rawConfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
baseUrl, err := url.Parse(config.BaseURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Plugin{
|
|
Plugin: pkgplugins.NewBasePlugin(),
|
|
|
|
name: name,
|
|
logger: logger,
|
|
client: client.New(ProviderName, baseUrl, config.AccessKey, config.Secret),
|
|
config: config,
|
|
}, nil
|
|
}
|
|
|
|
func (p *Plugin) Name() string {
|
|
return p.name
|
|
}
|
|
|
|
func (p *Plugin) Config() models.PluginInternalConfig {
|
|
return p.config
|
|
}
|
|
|
|
func (p *Plugin) Install(_ context.Context, req models.InstallRequest) (models.InstallResponse, error) {
|
|
return models.InstallResponse{
|
|
Workflow: workflow(),
|
|
}, nil
|
|
}
|
|
|
|
func (p *Plugin) Uninstall(ctx context.Context, req models.UninstallRequest) (models.UninstallResponse, error) {
|
|
return models.UninstallResponse{}, nil
|
|
}
|
|
|
|
func (p *Plugin) FetchNextAccounts(ctx context.Context, req models.FetchNextAccountsRequest) (models.FetchNextAccountsResponse, error) {
|
|
if p.client == nil {
|
|
return models.FetchNextAccountsResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
return p.fetchNextAccounts(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) FetchNextBalances(ctx context.Context, req models.FetchNextBalancesRequest) (models.FetchNextBalancesResponse, error) {
|
|
if p.client == nil {
|
|
return models.FetchNextBalancesResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
return p.fetchNextBalances(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) FetchNextExternalAccounts(ctx context.Context, req models.FetchNextExternalAccountsRequest) (models.FetchNextExternalAccountsResponse, error) {
|
|
if p.client == nil {
|
|
return models.FetchNextExternalAccountsResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
return p.fetchNextExternalAccounts(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) FetchNextPayments(ctx context.Context, req models.FetchNextPaymentsRequest) (models.FetchNextPaymentsResponse, error) {
|
|
if p.client == nil {
|
|
return models.FetchNextPaymentsResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
return p.fetchNextPayments(ctx, req)
|
|
}
|
|
|
|
func (p *Plugin) CreateBankAccount(ctx context.Context, req models.CreateBankAccountRequest) (models.CreateBankAccountResponse, error) {
|
|
if p.client == nil {
|
|
return models.CreateBankAccountResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
return p.createBankAccount(ctx, req.BankAccount)
|
|
}
|
|
|
|
func (p *Plugin) CreatePayout(ctx context.Context, req models.CreatePayoutRequest) (models.CreatePayoutResponse, error) {
|
|
if p.client == nil {
|
|
return models.CreatePayoutResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
|
|
payoutID, err := p.createPayout(ctx, req.PaymentInitiation)
|
|
if err != nil {
|
|
return models.CreatePayoutResponse{}, err
|
|
}
|
|
|
|
return models.CreatePayoutResponse{
|
|
PollingPayoutID: &payoutID,
|
|
}, nil
|
|
}
|
|
|
|
func (p *Plugin) PollPayoutStatus(ctx context.Context, req models.PollPayoutStatusRequest) (models.PollPayoutStatusResponse, error) {
|
|
if p.client == nil {
|
|
return models.PollPayoutStatusResponse{}, pkgplugins.ErrNotYetInstalled
|
|
}
|
|
|
|
return p.pollPayoutStatus(ctx, req.PayoutID)
|
|
}
|
|
|
|
var _ models.Plugin = &Plugin{}
|