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.
156 lines
3.8 KiB
Go
156 lines
3.8 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
)
|
|
|
|
type ListTransactionRequest struct {
|
|
UserID string
|
|
AccountID string
|
|
BookedDateGTE time.Time
|
|
BookedDateLTE time.Time
|
|
PageSize int
|
|
NextPageToken string
|
|
}
|
|
|
|
type ListTransactionResponse struct {
|
|
NextPageToken string `json:"nextPageToken"`
|
|
Transactions []Transaction `json:"transactions"`
|
|
}
|
|
|
|
type Amount struct {
|
|
CurrencyCode string `json:"currencyCode"`
|
|
Value struct {
|
|
Scale string `json:"scale"`
|
|
Value string `json:"unscaledValue"`
|
|
} `json:"value"`
|
|
}
|
|
|
|
type Descriptions struct {
|
|
Detailed struct {
|
|
Unstructured string `json:"unstructured"`
|
|
} `json:"detailed"`
|
|
Display string `json:"display"`
|
|
Original string `json:"original"`
|
|
}
|
|
|
|
type Types struct {
|
|
FinancialInstitutionTypeCode string `json:"financialInstitutionTypeCode"`
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
type TransactionDates struct {
|
|
Booked time.Time `json:"booked"`
|
|
Transaction time.Time `json:"transaction"`
|
|
Value time.Time `json:"value"`
|
|
}
|
|
|
|
func (td *TransactionDates) UnmarshalJSON(data []byte) error {
|
|
type datesJSON struct {
|
|
Booked string `json:"booked"`
|
|
Transaction string `json:"transaction"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
var aux datesJSON
|
|
if err := json.Unmarshal(data, &aux); err != nil {
|
|
return err
|
|
}
|
|
|
|
if aux.Booked != "" {
|
|
parsed, err := time.Parse(time.DateOnly, aux.Booked)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid booked date %q: %w", aux.Booked, err)
|
|
}
|
|
td.Booked = parsed
|
|
}
|
|
|
|
if aux.Transaction != "" {
|
|
parsed, err := time.Parse(time.DateOnly, aux.Transaction)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid transaction date %q: %w", aux.Transaction, err)
|
|
}
|
|
td.Transaction = parsed
|
|
}
|
|
|
|
if aux.Value != "" {
|
|
parsed, err := time.Parse(time.DateOnly, aux.Value)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid value date %q: %w", aux.Value, err)
|
|
}
|
|
td.Value = parsed
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type Transaction struct {
|
|
ID string `json:"id"`
|
|
AccountID string `json:"accountId"`
|
|
Status string `json:"status"`
|
|
|
|
BookedDateTime time.Time `json:"bookedDateTime"`
|
|
TransactionDateTime time.Time `json:"transactionDateTime"`
|
|
ValueDateTime time.Time `json:"valueDateTime"`
|
|
|
|
Dates TransactionDates `json:"dates"`
|
|
|
|
Amount Amount `json:"amount"`
|
|
Descriptions Descriptions `json:"descriptions"`
|
|
}
|
|
|
|
func (c *client) ListTransactions(ctx context.Context, req ListTransactionRequest) (ListTransactionResponse, error) {
|
|
authCode, err := c.getUserAccessToken(ctx, GetUserAccessTokenRequest{
|
|
UserID: req.UserID,
|
|
WantedScopes: []Scopes{
|
|
SCOPES_ACCOUNTS_READ,
|
|
SCOPES_TRANSACTIONS_READ,
|
|
SCOPES_USER_READ,
|
|
SCOPES_CREDENTIALS_READ,
|
|
SCOPES_PROVIDERS_READ,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return ListTransactionResponse{}, err
|
|
}
|
|
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_transactions")
|
|
|
|
endpoint := fmt.Sprintf("%s/data/v2/transactions", c.endpoint)
|
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
|
|
if err != nil {
|
|
return ListTransactionResponse{}, err
|
|
}
|
|
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authCode))
|
|
|
|
query := url.Values{}
|
|
query.Add("accountIdIn", req.AccountID)
|
|
if !req.BookedDateGTE.IsZero() {
|
|
query.Add("bookedDateGte", req.BookedDateGTE.Format(time.DateOnly))
|
|
}
|
|
if !req.BookedDateLTE.IsZero() {
|
|
query.Add("bookedDateLte", req.BookedDateLTE.Format(time.DateOnly))
|
|
}
|
|
query.Add("pageSize", strconv.Itoa(req.PageSize))
|
|
if req.NextPageToken != "" {
|
|
query.Add("pageToken", req.NextPageToken)
|
|
}
|
|
request.URL.RawQuery = query.Encode()
|
|
|
|
var response ListTransactionResponse
|
|
_, err = c.userClient.Do(ctx, request, &response, nil)
|
|
if err != nil {
|
|
return ListTransactionResponse{}, err
|
|
}
|
|
|
|
return response, nil
|
|
}
|