MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / validateTransactionForRefund

Method validateTransactionForRefund

transaction.go:2286–2311  ·  view source on GitHub ↗

validateTransactionForRefund checks if the given transaction is eligible for a refund.

(ctx context.Context, originalTxn *model.Transaction)

Source from the content-addressed store, hash-verified

2284
2285// validateTransactionForRefund checks if the given transaction is eligible for a refund.
2286func (l *LedgerForge) validateTransactionForRefund(ctx context.Context, originalTxn *model.Transaction) error {
2287 ctx, span := tracer.Start(ctx, "validateTransactionForRefund")
2288 defer span.End()
2289
2290 // Validate the transaction status
2291 if originalTxn.Status == StatusRejected {
2292 err := fmt.Errorf("transaction %s is not in a state that can be refunded (status: %s)", originalTxn.TransactionID, originalTxn.Status)
2293 span.RecordError(err)
2294 return err
2295 }
2296
2297 // Check if the transaction has already been refunded
2298 isRefunded, err := l.datasource.IsTransactionRefunded(ctx, originalTxn)
2299 if err != nil {
2300 span.RecordError(err)
2301 return fmt.Errorf("failed to check if transaction %s was already refunded: %w", originalTxn.TransactionID, err)
2302 }
2303 if isRefunded {
2304 err := fmt.Errorf("transaction %s has already been refunded", originalTxn.TransactionID)
2305 span.RecordError(err)
2306 return err
2307 }
2308
2309 span.AddEvent("Transaction validated for refund", trace.WithAttributes(attribute.String("transaction.id", originalTxn.TransactionID)))
2310 return nil
2311}
2312
2313// prepareRefundTransaction creates and configures a new transaction object for the refund.
2314func prepareRefundTransaction(originalTxn *model.Transaction, skipQueue bool) *model.Transaction {

Callers 1

RefundTransactionMethod · 0.95

Calls 2

IsTransactionRefundedMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected