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

Method RefundTransaction

transaction.go:2347–2376  ·  view source on GitHub ↗

RefundTransaction processes a refund for a given transaction by its ID. It starts a tracing span, retrieves the original transaction, validates its status, creates a new refund transaction, and queues it. Parameters: - ctx context.Context: The context for the operation. - transactionID string: The

(ctx context.Context, transactionID string, skipQueue bool)

Source from the content-addressed store, hash-verified

2345// - *model.Transaction: A pointer to the refunded Transaction model.
2346// - error: An error if the transaction could not be refunded.
2347func (l *LedgerForge) RefundTransaction(ctx context.Context, transactionID string, skipQueue bool) (*model.Transaction, error) {
2348 ctx, span := tracer.Start(ctx, "RefundTransaction")
2349 defer span.End()
2350
2351 // 1. Retrieve the original transaction (from DB or Queue)
2352 originalTxn, err := l.getOriginalTransactionForRefund(ctx, transactionID)
2353 if err != nil {
2354 span.RecordError(err)
2355 return nil, err // Error includes context from the helper function
2356 }
2357
2358 // 2. Validate if the transaction can be refunded
2359 if err := l.validateTransactionForRefund(ctx, originalTxn); err != nil {
2360 span.RecordError(err)
2361 return nil, err // Error includes context from the helper function
2362 }
2363
2364 // 3. Prepare the refund transaction object
2365 refundTxnObject := prepareRefundTransaction(originalTxn, skipQueue)
2366
2367 // 4. Queue the refund transaction for processing
2368 queuedRefundTxn, err := l.QueueTransaction(ctx, refundTxnObject)
2369 if err != nil {
2370 span.RecordError(err)
2371 return nil, fmt.Errorf("failed to queue refund transaction %s: %w", refundTxnObject.TransactionID, err)
2372 }
2373
2374 span.AddEvent("Refund transaction queued", trace.WithAttributes(attribute.String("refund.transaction.id", queuedRefundTxn.TransactionID)))
2375 return queuedRefundTxn, nil
2376}
2377
2378// processBulkTransactions prepares and queues all transactions in a batch with the given batch ID
2379func (l *LedgerForge) processBulkTransactions(ctx context.Context, transactions []*model.Transaction, batchID string, inflight bool, skipQueue bool) error {

Callers 4

TestRejectTransactionFunction · 0.95
RefundWorkerMethod · 0.95

Calls 5

QueueTransactionMethod · 0.95
prepareRefundTransactionFunction · 0.85
StartMethod · 0.45

Tested by 3

TestRejectTransactionFunction · 0.76