package payment import ( "context" "strings" "time" ) const ( PaymentEventOrderCreated = "order_created" PaymentEventProviderCreated = "provider_created" PaymentEventPaymentSynchronized = "payment_synchronized" PaymentEventPaymentCallback = "payment_callback" PaymentEventFulfillmentStarted = "fulfillment_started" PaymentEventFulfillmentFinished = "fulfillment_finished" PaymentEventRefundStarted = "refund_started" PaymentEventRefundSubmitted = "refund_submitted" PaymentEventRefundConfirmed = "refund_confirmed" ) // PaymentOperation describes who or what initiated a payment state change. // It is carried in context so repo method signatures remain focused on domain // state while event persistence can still retain transport-level attribution. type PaymentOperation struct { Source string Reason string OperatorID uint OperatorName string ClientIP string UserAgent string DeviceID string } type paymentOperationContextKey struct{} func WithPaymentOperation(ctx context.Context, operation PaymentOperation) context.Context { if ctx == nil { ctx = context.Background() } return context.WithValue(ctx, paymentOperationContextKey{}, operation) } func PaymentOperationFromContext(ctx context.Context) PaymentOperation { if ctx == nil { return PaymentOperation{} } operation, _ := ctx.Value(paymentOperationContextKey{}).(PaymentOperation) operation.Source = strings.TrimSpace(operation.Source) operation.Reason = strings.TrimSpace(operation.Reason) operation.OperatorName = strings.TrimSpace(operation.OperatorName) operation.ClientIP = strings.TrimSpace(operation.ClientIP) operation.UserAgent = strings.TrimSpace(operation.UserAgent) operation.DeviceID = strings.TrimSpace(operation.DeviceID) return operation } type PaymentEvent struct { ID uint64 Provider string TradeNo string Type string Source string Status string ProviderStatus string Message string EventID string PayloadHash string Amount int64 Currency string OperatorID uint OperatorName string ClientIP string UserAgent string DeviceID string CreatedAt time.Time } type PaymentCurrencySummary struct { Currency string OrderAmount int64 PaidAmount int64 RefundedAmount int64 SettlementAmount int64 NetAmount int64 } type PaymentOrderSummary struct { OrderCount int64 PendingCount int64 PaidCount int64 RefundedCount int64 IssueCount int64 Currencies []PaymentCurrencySummary }