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.
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package routable
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/hanzo-fi/payments/ee/plugins/routable/client"
|
|
"github.com/hanzo-fi/payments/ee/plugins/routable/mappers"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
)
|
|
|
|
// createPayout branches on Routable's HTTP status (201 sync vs 202
|
|
// async) rather than guessing from a half-mapped Payment. See
|
|
// MAPPINGS.md §5.4 for the full response-handling matrix.
|
|
func (p *Plugin) createPayout(ctx context.Context, req models.CreatePayoutRequest) (models.CreatePayoutResponse, error) {
|
|
payable, status, err := p.initiatePayable(ctx, req.PaymentInitiation)
|
|
if err != nil {
|
|
return models.CreatePayoutResponse{}, err
|
|
}
|
|
|
|
if status == http.StatusAccepted {
|
|
id := payable.ID
|
|
return models.CreatePayoutResponse{PollingPayoutID: &id}, nil
|
|
}
|
|
|
|
payment, err := mappers.PayableToPSPPayment(*payable)
|
|
if err != nil {
|
|
return models.CreatePayoutResponse{}, fmt.Errorf("mapping payable response: %w", err)
|
|
}
|
|
if mappers.IsTerminalStatus(payment.Status) {
|
|
return models.CreatePayoutResponse{Payment: &payment}, nil
|
|
}
|
|
id := payment.Reference
|
|
return models.CreatePayoutResponse{PollingPayoutID: &id}, nil
|
|
}
|
|
|
|
// pollPayableStatus is shared by PollPayoutStatus and PollTransferStatus.
|
|
func (p *Plugin) pollPayableStatus(ctx context.Context, payableID string) (models.PollPayoutStatusResponse, error) {
|
|
if payableID == "" {
|
|
return models.PollPayoutStatusResponse{}, errors.New("missing payable id")
|
|
}
|
|
|
|
pa, err := p.client.GetPayable(ctx, payableID)
|
|
if err != nil {
|
|
// 404 right after a 202 = Routable's eventual-consistency
|
|
// window; tell the engine "not yet" and retry on schedule.
|
|
if errors.Is(err, client.ErrPayableNotFound) {
|
|
return models.PollPayoutStatusResponse{}, nil
|
|
}
|
|
return models.PollPayoutStatusResponse{}, fmt.Errorf("polling payable %s: %w", payableID, err)
|
|
}
|
|
|
|
payment, err := mappers.PayableToPSPPayment(*pa)
|
|
if err != nil {
|
|
return models.PollPayoutStatusResponse{}, fmt.Errorf("mapping payable: %w", err)
|
|
}
|
|
// Link PI ↔ Payment now; FETCH_PAYMENTS picks up further transitions.
|
|
return models.PollPayoutStatusResponse{Payment: &payment}, nil
|
|
}
|