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.
91 lines
2.4 KiB
Go
91 lines
2.4 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/plaid/plaid-go/v34/plaid"
|
|
)
|
|
|
|
const (
|
|
AttemptIDQueryParamID = "attemptID"
|
|
)
|
|
|
|
type CreateLinkTokenRequest struct {
|
|
ApplicationName string
|
|
UserID string
|
|
UserToken string
|
|
Language string
|
|
CountryCode string
|
|
RedirectURI string
|
|
WebhookBaseURL string
|
|
AttemptID string
|
|
}
|
|
|
|
type CreateLinkTokenResponse struct {
|
|
LinkToken string
|
|
Expiration time.Time
|
|
RequestID string
|
|
HostedLinkUrl string
|
|
}
|
|
|
|
func (c *client) CreateLinkToken(ctx context.Context, req CreateLinkTokenRequest) (CreateLinkTokenResponse, error) {
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "create_link_token")
|
|
|
|
countryCode := plaid.CountryCode(req.CountryCode)
|
|
if !countryCode.IsValid() {
|
|
return CreateLinkTokenResponse{}, fmt.Errorf("invalid plaid country code: %s: %w", req.CountryCode, models.ErrInvalidRequest)
|
|
}
|
|
|
|
request := plaid.NewLinkTokenCreateRequest(
|
|
req.ApplicationName,
|
|
req.Language,
|
|
[]plaid.CountryCode{countryCode},
|
|
plaid.LinkTokenCreateRequestUser{
|
|
ClientUserId: req.UserID,
|
|
},
|
|
)
|
|
|
|
url, err := url.Parse(req.WebhookBaseURL)
|
|
if err != nil {
|
|
return CreateLinkTokenResponse{}, fmt.Errorf("invalid webhook base URL: %w", err)
|
|
}
|
|
|
|
url = url.JoinPath("all")
|
|
query := url.Query()
|
|
query.Set(AttemptIDQueryParamID, req.AttemptID)
|
|
url.RawQuery = query.Encode()
|
|
|
|
webhookURL := url.String()
|
|
|
|
request.SetUserToken(req.UserToken)
|
|
request.SetEnableMultiItemLink(true)
|
|
request.SetWebhook(webhookURL)
|
|
request.Products = []plaid.Products{plaid.PRODUCTS_TRANSACTIONS}
|
|
request.SetRedirectUri(req.RedirectURI)
|
|
hostedLink := plaid.NewLinkTokenCreateHostedLink()
|
|
hostedLink.SetCompletionRedirectUri(req.RedirectURI)
|
|
request.SetHostedLink(*hostedLink)
|
|
request.SetAccountFilters(plaid.LinkTokenAccountFilters{
|
|
Depository: &plaid.DepositoryFilter{
|
|
AccountSubtypes: []plaid.DepositoryAccountSubtype{plaid.DEPOSITORYACCOUNTSUBTYPE_CHECKING, plaid.DEPOSITORYACCOUNTSUBTYPE_SAVINGS},
|
|
},
|
|
})
|
|
|
|
resp, _, err := c.client.PlaidApi.LinkTokenCreate(ctx).LinkTokenCreateRequest(*request).Execute()
|
|
if err != nil {
|
|
return CreateLinkTokenResponse{}, wrapSDKError(err)
|
|
}
|
|
|
|
return CreateLinkTokenResponse{
|
|
LinkToken: resp.GetLinkToken(),
|
|
Expiration: resp.GetExpiration(),
|
|
RequestID: resp.GetRequestId(),
|
|
HostedLinkUrl: resp.GetHostedLinkUrl(),
|
|
}, nil
|
|
}
|