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.
107 lines
2.4 KiB
Go
107 lines
2.4 KiB
Go
package mangopay
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/hanzo-fi/payments/ce/plugins/mangopay/client"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/hanzo-fi/payments/pkg/domain/pagination"
|
|
)
|
|
|
|
type usersState struct {
|
|
LastPage int `json:"lastPage"`
|
|
LastCreationDate time.Time `json:"lastCreationDate"`
|
|
}
|
|
|
|
func (p *Plugin) fetchNextUsers(ctx context.Context, req models.FetchNextOthersRequest) (models.FetchNextOthersResponse, error) {
|
|
var oldState usersState
|
|
if req.State != nil {
|
|
if err := json.Unmarshal(req.State, &oldState); err != nil {
|
|
return models.FetchNextOthersResponse{}, err
|
|
}
|
|
} else {
|
|
oldState = usersState{
|
|
LastPage: 1,
|
|
}
|
|
}
|
|
|
|
newState := usersState{
|
|
LastPage: oldState.LastPage,
|
|
LastCreationDate: oldState.LastCreationDate,
|
|
}
|
|
|
|
var users []models.PSPOther
|
|
var userCreationDates []time.Time
|
|
needMore := false
|
|
hasMore := false
|
|
page := oldState.LastPage
|
|
for {
|
|
pagedUsers, err := p.client.GetUsers(ctx, page, req.PageSize)
|
|
if err != nil {
|
|
return models.FetchNextOthersResponse{}, err
|
|
}
|
|
|
|
users, userCreationDates, err = fillUsers(pagedUsers, users, userCreationDates, oldState)
|
|
if err != nil {
|
|
return models.FetchNextOthersResponse{}, err
|
|
}
|
|
|
|
needMore, hasMore = pagination.ShouldFetchMore(users, pagedUsers, req.PageSize)
|
|
if !needMore || !hasMore {
|
|
break
|
|
}
|
|
|
|
page++
|
|
}
|
|
|
|
if !needMore {
|
|
users = users[:req.PageSize]
|
|
userCreationDates = userCreationDates[:req.PageSize]
|
|
}
|
|
|
|
newState.LastPage = page
|
|
if len(userCreationDates) > 0 {
|
|
newState.LastCreationDate = userCreationDates[len(users)-1]
|
|
}
|
|
|
|
payload, err := json.Marshal(newState)
|
|
if err != nil {
|
|
return models.FetchNextOthersResponse{}, err
|
|
}
|
|
|
|
return models.FetchNextOthersResponse{
|
|
Others: users,
|
|
NewState: payload,
|
|
HasMore: hasMore,
|
|
}, nil
|
|
}
|
|
|
|
func fillUsers(
|
|
pagedUsers []client.User,
|
|
users []models.PSPOther,
|
|
userCreationDates []time.Time,
|
|
oldState usersState,
|
|
) ([]models.PSPOther, []time.Time, error) {
|
|
for _, user := range pagedUsers {
|
|
userCreationDate := time.Unix(user.CreationDate, 0)
|
|
if userCreationDate.Before(oldState.LastCreationDate) {
|
|
continue
|
|
}
|
|
|
|
raw, err := json.Marshal(user)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
users = append(users, models.PSPOther{
|
|
ID: user.ID,
|
|
Other: raw,
|
|
})
|
|
userCreationDates = append(userCreationDates, userCreationDate)
|
|
}
|
|
|
|
return users, userCreationDates, nil
|
|
}
|