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.
165 lines
3.5 KiB
Go
165 lines
3.5 KiB
Go
package workflow
|
|
|
|
import (
|
|
"github.com/hanzo-fi/payments/internal/connectors/engine/activities"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"go.temporal.io/sdk/temporal"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
type ReversePayout struct {
|
|
TaskID models.TaskID
|
|
ConnectorID models.ConnectorID
|
|
PaymentInitiationReversalID models.PaymentInitiationReversalID
|
|
}
|
|
|
|
func (w Workflow) runReversePayout(
|
|
ctx workflow.Context,
|
|
reversePayout ReversePayout,
|
|
) error {
|
|
paymentID, err := w.reversePayout(ctx, reversePayout)
|
|
if err != nil {
|
|
errUpdateTask := w.updateTasksError(
|
|
ctx,
|
|
reversePayout.TaskID,
|
|
&reversePayout.ConnectorID,
|
|
err,
|
|
)
|
|
if errUpdateTask != nil {
|
|
return errUpdateTask
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
return w.updateTaskSuccess(
|
|
ctx,
|
|
reversePayout.TaskID,
|
|
&reversePayout.ConnectorID,
|
|
paymentID,
|
|
)
|
|
}
|
|
|
|
func (w Workflow) reversePayout(
|
|
ctx workflow.Context,
|
|
reversePayout ReversePayout,
|
|
) (string, error) {
|
|
// Get the payment initiation reversal
|
|
piReversal, err := activities.StoragePaymentInitiationReversalsGet(
|
|
infiniteRetryContext(ctx),
|
|
reversePayout.PaymentInitiationReversalID,
|
|
)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
pi, err := activities.StoragePaymentInitiationsGet(
|
|
infiniteRetryContext(ctx),
|
|
piReversal.PaymentInitiationID,
|
|
)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := w.validateReverse(
|
|
ctx,
|
|
ValidateReverse{
|
|
ConnectorID: reversePayout.ConnectorID,
|
|
PI: pi,
|
|
PIReversal: piReversal,
|
|
},
|
|
); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
pspPI, err := w.getPSPPI(ctx, pi)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
pspReversal := models.FromPaymentInitiationReversalToPSPPaymentInitiationReversal(
|
|
piReversal,
|
|
pspPI,
|
|
)
|
|
|
|
reversePayoutResponse, errPlugin := activities.PluginReversePayout(
|
|
infiniteRetryContext(ctx),
|
|
reversePayout.ConnectorID,
|
|
models.ReversePayoutRequest{
|
|
PaymentInitiationReversal: pspReversal,
|
|
},
|
|
)
|
|
switch errPlugin {
|
|
case nil:
|
|
payment, err := models.FromPSPPaymentToPayment(reversePayoutResponse.Payment, reversePayout.ConnectorID)
|
|
if err != nil {
|
|
return "", temporal.NewNonRetryableApplicationError(
|
|
"failed to convert payment",
|
|
ErrValidation,
|
|
err,
|
|
)
|
|
}
|
|
|
|
// Store refund for the payment initiation
|
|
if err := w.storePIPaymentWithStatus(
|
|
ctx,
|
|
payment,
|
|
pi.ID,
|
|
getPIStatusFromPayment(payment.Status),
|
|
); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
err = w.addPIReversalAdjustment(
|
|
ctx,
|
|
models.PaymentInitiationReversalAdjustmentID{
|
|
PaymentInitiationReversalID: reversePayout.PaymentInitiationReversalID,
|
|
CreatedAt: workflow.Now(ctx),
|
|
Status: models.PAYMENT_INITIATION_REVERSAL_STATUS_PROCESSED,
|
|
},
|
|
nil,
|
|
nil,
|
|
)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return payment.ID.String(), nil
|
|
|
|
default:
|
|
err := w.addPIReversalAdjustment(
|
|
ctx,
|
|
models.PaymentInitiationReversalAdjustmentID{
|
|
PaymentInitiationReversalID: reversePayout.PaymentInitiationReversalID,
|
|
CreatedAt: workflow.Now(ctx),
|
|
Status: models.PAYMENT_INITIATION_REVERSAL_STATUS_FAILED,
|
|
},
|
|
errPlugin,
|
|
nil,
|
|
)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
err = w.addPIAdjustment(
|
|
ctx,
|
|
models.PaymentInitiationAdjustmentID{
|
|
PaymentInitiationID: pi.ID,
|
|
CreatedAt: workflow.Now(ctx),
|
|
Status: models.PAYMENT_INITIATION_ADJUSTMENT_STATUS_REVERSE_FAILED,
|
|
},
|
|
pi.Amount,
|
|
&pi.Asset,
|
|
nil,
|
|
nil,
|
|
)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return "", errPlugin
|
|
}
|
|
}
|
|
|
|
var RunReversePayout = "ReversePayout"
|