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.
100 lines
4.5 KiB
Go
100 lines
4.5 KiB
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/hanzo-fi/payments/pkg/domain/metrics"
|
|
)
|
|
|
|
type ReversePayoutReason string
|
|
|
|
const (
|
|
ReasonDuplicatedEntry ReversePayoutReason = "duplicated_entry"
|
|
ReasonIncorrectAmount ReversePayoutReason = "incorrect_amount"
|
|
ReasonIncorrectReceiverAccount ReversePayoutReason = "incorrect_receiver_account"
|
|
ReasonDebitEarlierThanIntended ReversePayoutReason = "debit_earlier_than_intended"
|
|
ReasonCreditLaterThanIntended ReversePayoutReason = "credit_later_than_intended"
|
|
)
|
|
|
|
type ReversePayoutRequest struct {
|
|
Reason ReversePayoutReason `json:"reason"`
|
|
ACHTransferID string `json:"ach_transfer_id"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
|
|
type ReversePayoutResponse struct {
|
|
ID string `json:"id"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
InitiatedAt string `json:"initiated_at"`
|
|
CompletedAt *string `json:"completed_at"`
|
|
AcknowledgedAt *string `json:"acknowledged_at"`
|
|
CancelledAt *string `json:"cancelled_at"`
|
|
ManualReviewAt *string `json:"manual_review_at"`
|
|
ReturnContestedAt *string `json:"return_contested_at"`
|
|
ReturnDishonoredAt *string `json:"return_dishonored_at"`
|
|
ReturnedAt *string `json:"returned_at"`
|
|
SettledAt *string `json:"settled_at"`
|
|
SubmittedAt *string `json:"submitted_at"`
|
|
EffectiveOn string `json:"effective_on"`
|
|
NSFDeadline *string `json:"nsf_deadline"`
|
|
IdempotencyKey string `json:"idempotency_key"`
|
|
AccountNumberID string `json:"account_number_id"`
|
|
BankAccountID string `json:"bank_account_id"`
|
|
CounterpartyID string `json:"counterparty_id"`
|
|
Amount int64 `json:"amount"`
|
|
CurrencyCode string `json:"currency_code"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status"`
|
|
Type string `json:"type"`
|
|
CompanyID string `json:"company_id"`
|
|
CompanyName string `json:"company_name"`
|
|
CompanyEntryDescription string `json:"company_entry_description"`
|
|
CompanyDiscretionaryData string `json:"company_discretionary_data"`
|
|
EntryClassCode string `json:"entry_class_code"`
|
|
ODFIRoutingNumber string `json:"odfi_routing_number"`
|
|
ReceiverID string `json:"receiver_id"`
|
|
ReceiverName string `json:"receiver_name"`
|
|
TraceNumber string `json:"trace_number"`
|
|
PaymentRelatedInfo string `json:"payment_related_info"`
|
|
ReversalPairTransferID string `json:"reversal_pair_transfer_id"`
|
|
UltimateBeneficiaryCounterpartyID string `json:"ultimate_beneficiary_counterparty_id"`
|
|
UltimateOriginatorCounterpartyID string `json:"ultimate_originator_counterparty_id"`
|
|
AllowOverdraft bool `json:"allow_overdraft"`
|
|
IsIncoming bool `json:"is_incoming"`
|
|
IsOnUs bool `json:"is_on_us"`
|
|
SameDay bool `json:"same_day"`
|
|
IAT string `json:"iat"`
|
|
ReturnDetails []any `json:"return_details"`
|
|
NotificationOfChanges string `json:"notification_of_changes"`
|
|
}
|
|
|
|
func (c *client) ReversePayout(ctx context.Context, req *ReversePayoutRequest) (*ReversePayoutResponse, error) {
|
|
ctx = context.WithValue(ctx, metrics.MetricOperationContextKey, "reverse_payout")
|
|
|
|
body, err := json.Marshal(req)
|
|
if err != nil {
|
|
return &ReversePayoutResponse{}, err
|
|
}
|
|
|
|
endpoint := fmt.Sprintf("transfers/ach/%s/reverse", req.ACHTransferID)
|
|
|
|
request, err := c.newRequest(ctx, http.MethodPost, endpoint, bytes.NewBuffer(body))
|
|
if err != nil {
|
|
return &ReversePayoutResponse{}, fmt.Errorf("failed to create reverse payout request: %w", err)
|
|
}
|
|
|
|
var response ReversePayoutResponse
|
|
var errRes columnError
|
|
_, err = c.httpClient.Do(ctx, request, &response, &errRes)
|
|
if err != nil {
|
|
return &ReversePayoutResponse{}, fmt.Errorf("failed to send reverse payout request: %w", err)
|
|
}
|
|
|
|
return &response, nil
|
|
}
|