mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins). External dep kept: formancehq/go-libs. - plugins: each ce/plugins/* consumed a *published* pkg/domain; added local 'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too. - branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added), goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage), proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl. - CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml + cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet). - kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image. - verified: go build ./... (default + -tags ee) + all 20 nested modules green.
109 lines
3.6 KiB
Go
109 lines
3.6 KiB
Go
package plaid
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
iso6391 "github.com/emvi/iso-639-1"
|
|
"github.com/hanzo-fi/payments/ce/plugins/plaid/client"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
func validateCreateUserLinkRequest(req models.CreateUserLinkRequest) error {
|
|
if req.ApplicationName == "" {
|
|
return fmt.Errorf("missing application name: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.PaymentServiceUser == nil {
|
|
return fmt.Errorf("missing payment service user: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.PaymentServiceUser.Name == "" {
|
|
return fmt.Errorf("missing payment service user name: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.PaymentServiceUser.ContactDetails == nil ||
|
|
req.PaymentServiceUser.ContactDetails.Locale == nil ||
|
|
*req.PaymentServiceUser.ContactDetails.Locale == "" {
|
|
return fmt.Errorf("missing payment service user locale: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.PaymentServiceUser.Address == nil || req.PaymentServiceUser.Address.Country == nil {
|
|
return fmt.Errorf("missing payment service user country: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if _, ok := supportedCountryCodes[*req.PaymentServiceUser.Address.Country]; !ok {
|
|
return fmt.Errorf("unsupported payment service user country: %s: %w", *req.PaymentServiceUser.Address.Country, models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.ClientRedirectURL == nil || *req.ClientRedirectURL == "" {
|
|
return fmt.Errorf("missing redirect URI: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.OpenBankingForwardedUser == nil {
|
|
return fmt.Errorf("missing open banking connections: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if req.OpenBankingForwardedUser.Metadata == nil {
|
|
return fmt.Errorf("missing open banking connections metadata: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
if _, ok := req.OpenBankingForwardedUser.Metadata[UserTokenMetadataKey]; !ok {
|
|
return fmt.Errorf("missing user token: %w", models.ErrInvalidRequest)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func validateLanguageCode(locale string) (string, error) {
|
|
l, err := language.Parse(locale)
|
|
if err != nil {
|
|
return "", fmt.Errorf("invalid locale: %s: %w: %w", locale, err, models.ErrInvalidRequest)
|
|
}
|
|
|
|
iso639LanguageCode, _ := l.Base()
|
|
if !iso6391.ValidCode(iso639LanguageCode.String()) {
|
|
return "", fmt.Errorf("locale base needs to be in iso639-1 format: %s: %w", locale, models.ErrInvalidRequest)
|
|
}
|
|
|
|
if _, ok := supportedLanguage[iso639LanguageCode.String()]; !ok {
|
|
return "", fmt.Errorf("unsupported locale: %s: %w", iso639LanguageCode.String(), models.ErrInvalidRequest)
|
|
}
|
|
|
|
return iso639LanguageCode.String(), nil
|
|
}
|
|
|
|
func (p *Plugin) createUserLink(ctx context.Context, req models.CreateUserLinkRequest) (models.CreateUserLinkResponse, error) {
|
|
if err := validateCreateUserLinkRequest(req); err != nil {
|
|
return models.CreateUserLinkResponse{}, err
|
|
}
|
|
|
|
language, err := validateLanguageCode(*req.PaymentServiceUser.ContactDetails.Locale)
|
|
if err != nil {
|
|
return models.CreateUserLinkResponse{}, err
|
|
}
|
|
|
|
resp, err := p.client.CreateLinkToken(ctx, client.CreateLinkTokenRequest{
|
|
ApplicationName: req.ApplicationName,
|
|
UserID: req.PaymentServiceUser.ID.String(),
|
|
UserToken: req.OpenBankingForwardedUser.Metadata[UserTokenMetadataKey],
|
|
Language: language,
|
|
CountryCode: *req.PaymentServiceUser.Address.Country,
|
|
RedirectURI: *req.ClientRedirectURL,
|
|
WebhookBaseURL: req.WebhookBaseURL,
|
|
AttemptID: req.AttemptID,
|
|
})
|
|
if err != nil {
|
|
return models.CreateUserLinkResponse{}, err
|
|
}
|
|
|
|
return models.CreateUserLinkResponse{
|
|
Link: resp.HostedLinkUrl,
|
|
TemporaryLinkToken: &models.Token{
|
|
Token: resp.LinkToken,
|
|
ExpiresAt: resp.Expiration,
|
|
},
|
|
}, nil
|
|
}
|