Files
zeekay 7d727874d5 chore: rebrand Formance Payments -> Hanzo Payments (hanzo-fi)
- 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.
2026-07-05 13:08:55 -07:00

123 lines
3.9 KiB
Go

package client
import (
"context"
"fmt"
"time"
"github.com/hanzo-fi/payments/pkg/domain/metrics"
"github.com/hanzo-fi/payments/pkg/domain/models"
"github.com/stripe/stripe-go/v80"
)
const (
expandSource = "data.source"
expandSourceCharge = "data.source.charge"
expandSourceDispute = "data.source.dispute"
expandSourcePayout = "data.source.payout"
expandSourceRefund = "data.source.refund"
expandSourceTransfer = "data.source.transfer"
expandSourcePaymentIntent = "data.source.payment_intent"
expandSourceRefundPaymentIntent = "data.source.refund.payment_intent"
)
func (c *client) GetPayments(
ctx context.Context,
accountID string,
timeline Timeline,
pageSize int64,
) (results []*stripe.BalanceTransaction, _ Timeline, hasMore bool, err error) {
results = make([]*stripe.BalanceTransaction, 0, int(pageSize))
timer := time.NewTimer((models.ActivityStartToCloseTimeoutMinutesLong - 1) * time.Minute)
defer timer.Stop()
for {
select {
case <-ctx.Done():
// if the app is shutting down
return results, timeline, false, fmt.Errorf("context closed before first payment found")
case <-timer.C:
// after the timer expires let's save the state to prevent workflow timeout
return results, timeline, true, nil
default: //fallthrough
}
if timeline.IsCaughtUp() {
break
}
var oldest interface{}
oldest, timeline, hasMore, err = scanForOldest(timeline, pageSize, func(params stripe.ListParams) (stripe.ListContainer, error) {
if accountID != "" {
params.StripeAccount = &accountID
}
params.Context = metrics.OperationContext(ctx, "list_transactions_scan")
transactionParams := &stripe.BalanceTransactionListParams{ListParams: params}
expandBalanceTransactionParams(transactionParams)
itr := c.balanceTransactionClient.List(transactionParams)
return itr.BalanceTransactionList(), wrapSDKErr(itr.Err())
})
if err != nil {
return results, timeline, false, err
}
if hasMore {
continue
}
if oldest == nil {
return results, timeline, false, err
}
results = append(results, oldest.(*stripe.BalanceTransaction))
}
filters := stripe.ListParams{
Context: metrics.OperationContext(ctx, "list_transactions"),
Limit: limit(pageSize, len(results)),
EndingBefore: &timeline.LatestID,
Single: true, // turn off autopagination
}
if accountID != "" {
filters.StripeAccount = &accountID
}
params := &stripe.BalanceTransactionListParams{
ListParams: filters,
}
expandBalanceTransactionParams(params)
itr := c.balanceTransactionClient.List(params)
data := reverseTransactions(itr.BalanceTransactionList().Data)
results = append(results, data...)
if len(results) == 0 {
return results, timeline, itr.BalanceTransactionList().HasMore, wrapSDKErr(itr.Err())
}
timeline.LatestID = results[len(results)-1].ID
c.logger.WithField("account", accountID).WithField("latest_id", timeline.LatestID).Debugf("set latest id after batch with %d entries", len(results))
return results, timeline, itr.BalanceTransactionList().HasMore, wrapSDKErr(itr.Err())
}
func expandBalanceTransactionParams(params *stripe.BalanceTransactionListParams) {
params.AddExpand(expandSource)
params.AddExpand(expandSourceCharge)
params.AddExpand(expandSourceDispute)
params.AddExpand(expandSourcePayout)
params.AddExpand(expandSourceRefund)
params.AddExpand(expandSourceTransfer)
params.AddExpand(expandSourcePaymentIntent)
params.AddExpand(expandSourceRefundPaymentIntent)
}
// Stripe now returns data in reverse chronological order no matter which params we provide so we need to reverse the slice
func reverseTransactions(in []*stripe.BalanceTransaction) []*stripe.BalanceTransaction {
out := make([]*stripe.BalanceTransaction, len(in))
copy(out, in)
for i, j := 0, len(out)-1; i < j; i, j = i+1, j-1 {
out[i], out[j] = out[j], out[i]
}
return out
}