All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m6s
39 lines
1.6 KiB
Go
39 lines
1.6 KiB
Go
package payment
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
agentrecharge "github.com/break/junhong_cmp_fiber/internal/application/agentrecharge"
|
|
"github.com/break/junhong_cmp_fiber/internal/infrastructure/messaging/outbox"
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
)
|
|
|
|
// AgentRechargePaymentEventWriter 将支付确认事实写入公共 Outbox。
|
|
type AgentRechargePaymentEventWriter struct {
|
|
outbox *outbox.Repository
|
|
}
|
|
|
|
// NewAgentRechargePaymentEventWriter 创建代理充值支付确认事件 Writer。
|
|
func NewAgentRechargePaymentEventWriter(repository *outbox.Repository) *AgentRechargePaymentEventWriter {
|
|
return &AgentRechargePaymentEventWriter{outbox: repository}
|
|
}
|
|
|
|
// Append 在支付确认事务内追加稳定的代理充值入账事件。
|
|
func (w *AgentRechargePaymentEventWriter) Append(ctx context.Context, tx *gorm.DB, event agentrecharge.PaymentConfirmedEvent) error {
|
|
if w == nil || w.outbox == nil {
|
|
return errors.New(errors.CodeInternalError, "代理充值支付确认 Outbox Writer 未配置")
|
|
}
|
|
_, err := w.outbox.Append(ctx, tx, outbox.Envelope{
|
|
EventID: event.EventID, EventType: constants.OutboxEventTypeAgentRechargePaymentConfirmed,
|
|
PayloadVersion: constants.AgentRechargePaymentConfirmedPayloadVersionV1,
|
|
AggregateType: "agent_recharge", AggregateID: strconv.FormatUint(uint64(event.RechargeID), 10),
|
|
ResourceType: "payment", ResourceID: strconv.FormatUint(uint64(event.PaymentID), 10),
|
|
BusinessKey: event.EventID, RequestID: event.RequestID, CorrelationID: event.CorrelationID, Payload: event,
|
|
})
|
|
return err
|
|
}
|