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.
141 lines
6.2 KiB
Go
141 lines
6.2 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
errorsutils "github.com/hanzo-fi/payments/pkg/domain/errors"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type CounterpartyDetails struct {
|
|
CounterpartyAccountNumber string `json:"counterparty_account_number,omitempty"`
|
|
CounterpartyAccountNumberFormat string `json:"counterparty_account_number_format,omitempty"`
|
|
CounterpartyBankIdentifier string `json:"counterparty_bank_identifier,omitempty"`
|
|
CounterpartyBankIdentifierFormat string `json:"counterparty_bank_identifier_format,omitempty"`
|
|
}
|
|
|
|
type CheckDetails struct {
|
|
CheckNumber string `json:"check_number,omitempty"`
|
|
CheckKey string `json:"check_key,omitempty"`
|
|
}
|
|
|
|
type PagodaPaymentDetails struct {
|
|
NoticeNumber string `json:"notice_number,omitempty"`
|
|
CreditorFiscalCode string `json:"creditor_fiscal_code,omitempty"`
|
|
Iuv string `json:"iuv,omitempty"`
|
|
}
|
|
|
|
type DirectDebitHoldDetails struct {
|
|
GuardingRate string `json:"guarding_rate,omitempty"`
|
|
}
|
|
|
|
type FinancingInstallmentDetails struct {
|
|
TotalInstallmentNumber int64 `json:"total_installment_number,omitempty"`
|
|
CurrentInstallmentNumber int64 `json:"current_installment_number,omitempty"`
|
|
}
|
|
|
|
type LogoDetails struct {
|
|
Small string `json:"small,omitempty"`
|
|
Medium string `json:"medium,omitempty"`
|
|
}
|
|
|
|
const TransactionStatusDeclined = "declined"
|
|
const TransactionStatusPending = "pending"
|
|
const TransactionStatusCompleted = "completed"
|
|
|
|
type Transactions struct {
|
|
Id string `json:"id"`
|
|
TransactionId string `json:"transaction_id"`
|
|
Amount json.Number `json:"amount"`
|
|
AmountCents int64 `json:"amount_cents"`
|
|
SettledBalance json.Number `json:"settled_balance"`
|
|
SettledBalanceCents int64 `json:"settled_balance_cents"`
|
|
AttachmentsIds *[]string `json:"attachments_ids,omitempty"`
|
|
Logo *LogoDetails `json:"logo,omitempty"`
|
|
LocalAmount json.Number `json:"local_amount,omitempty"`
|
|
LocalAmountCents int64 `json:"local_amount_cents,omitempty"`
|
|
Side string `json:"side"`
|
|
OperationType string `json:"operation_type"`
|
|
Currency string `json:"currency"`
|
|
LocalCurrency string `json:"local_currency"`
|
|
Label string `json:"label"`
|
|
CleanCounterpartyName string `json:"clean_counterparty_name"`
|
|
SettledAt string `json:"settled_at,omitempty"`
|
|
EmittedAt string `json:"emitted_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
Status string `json:"status"`
|
|
Note string `json:"note,omitempty"`
|
|
Reference string `json:"reference,omitempty"`
|
|
VatAmount json.Number `json:"vat_amount,omitempty"`
|
|
VatAmountCents int64 `json:"vat_amount_cents,omitempty"`
|
|
VatRate json.Number `json:"vat_rate,omitempty"`
|
|
InitiatorId string `json:"initiator_id"`
|
|
LabelIds *[]string `json:"label_ids,omitempty"`
|
|
AttachmentLost bool `json:"attachment_lost"`
|
|
AttachmentRequired bool `json:"attachment_required"`
|
|
CardLastDigits string `json:"card_last_digits,omitempty"`
|
|
Category string `json:"category"`
|
|
SubjectType string `json:"subject_type"`
|
|
BankAccountId string `json:"bank_account_id"`
|
|
IsExternalTransaction bool `json:"is_external_transaction"`
|
|
Transfer *CounterpartyDetails `json:"transfer,omitempty"`
|
|
Income *CounterpartyDetails `json:"income,omitempty"`
|
|
SwiftIncome *CounterpartyDetails `json:"swift_income,omitempty"`
|
|
DirectDebit *CounterpartyDetails `json:"direct_debit,omitempty"`
|
|
Check *CheckDetails `json:"check,omitempty"`
|
|
FinancingInstallment *FinancingInstallmentDetails `json:"financing_installment,omitempty"`
|
|
PagodaPayment *PagodaPaymentDetails `json:"pagoda_payment,omitempty"`
|
|
DirectDebitCollection *CounterpartyDetails `json:"direct_debit_collection,omitempty"`
|
|
DirectDebitHold *DirectDebitHoldDetails `json:"direct_debit_hold,omitempty"`
|
|
}
|
|
|
|
func (c *client) GetTransactions(
|
|
ctx context.Context,
|
|
bankAccountId string,
|
|
updatedAtFrom time.Time,
|
|
transactionStatusToFetch string,
|
|
page int,
|
|
pageSize int,
|
|
) ([]Transactions, error) {
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "list_transactions")
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.buildEndpoint("v2/transactions"), http.NoBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
|
}
|
|
|
|
q := req.URL.Query()
|
|
q.Add("per_page", fmt.Sprint(pageSize))
|
|
q.Add("page", fmt.Sprint(page))
|
|
q.Add("sort_by", "updated_at:asc")
|
|
q.Add("bank_account_id", bankAccountId)
|
|
if !updatedAtFrom.IsZero() {
|
|
q.Add("updated_at_from", updatedAtFrom.Format(QontoTimeformat))
|
|
}
|
|
q.Add("status[]", transactionStatusToFetch) // NOTE -- despite taking an array, Qonto only returns 1 status (as of 2025-05-09)
|
|
req.URL.RawQuery = q.Encode()
|
|
|
|
errorResponse := qontoErrors{}
|
|
type qontoResponse struct {
|
|
Transactions []Transactions `json:"transactions"`
|
|
Meta MetaPagination `json:"meta"`
|
|
}
|
|
successResponse := qontoResponse{}
|
|
|
|
_, err = c.httpClient.Do(ctx, req, &successResponse, &errorResponse)
|
|
|
|
if err != nil {
|
|
return nil, errorsutils.NewWrappedError(
|
|
fmt.Errorf("failed to get transactions: %w", errorResponse.Error()),
|
|
err,
|
|
)
|
|
}
|
|
if len(errorResponse.Errors) != 0 {
|
|
return nil, fmt.Errorf("failed to get transactions: %w", errorResponse.Error())
|
|
}
|
|
return successResponse.Transactions, nil
|
|
}
|