getOriginalTransactionForRefund retrieves the original transaction to be refunded, checking both the database and the queue if necessary.
(ctx context.Context, transactionID string)
| 2252 | // getOriginalTransactionForRefund retrieves the original transaction to be refunded, |
| 2253 | // checking both the database and the queue if necessary. |
| 2254 | func (l *LedgerForge) getOriginalTransactionForRefund(ctx context.Context, transactionID string) (*model.Transaction, error) { |
| 2255 | ctx, span := tracer.Start(ctx, "getOriginalTransactionForRefund") |
| 2256 | defer span.End() |
| 2257 | |
| 2258 | originalTxn, err := l.datasource.GetTransaction(ctx, transactionID) |
| 2259 | if err != nil { |
| 2260 | // Check if the error is due to no row found |
| 2261 | if errors.Is(err, sql.ErrNoRows) || strings.Contains(err.Error(), fmt.Sprintf("Transaction with ID '%s' not found", transactionID)) { |
| 2262 | // Check the queue for the transaction |
| 2263 | queuedTxn, queueErr := l.queue.GetTransactionFromQueue(transactionID) |
| 2264 | if queueErr != nil { |
| 2265 | span.RecordError(queueErr) |
| 2266 | // Return the original DB error if queue retrieval also fails |
| 2267 | return nil, fmt.Errorf("transaction %s not found in DB or queue: %w", transactionID, err) |
| 2268 | } |
| 2269 | if queuedTxn == nil { |
| 2270 | err := fmt.Errorf("transaction %s not found in DB or queue", transactionID) |
| 2271 | span.RecordError(err) |
| 2272 | return nil, err |
| 2273 | } |
| 2274 | span.AddEvent("Transaction found in queue", trace.WithAttributes(attribute.String("transaction.id", transactionID))) |
| 2275 | return queuedTxn, nil // Return the transaction found in the queue |
| 2276 | } |
| 2277 | // Return other database errors directly |
| 2278 | span.RecordError(err) |
| 2279 | return nil, fmt.Errorf("failed to get transaction %s from DB: %w", transactionID, err) |
| 2280 | } |
| 2281 | span.AddEvent("Transaction found in DB", trace.WithAttributes(attribute.String("transaction.id", transactionID))) |
| 2282 | return originalTxn, nil |
| 2283 | } |
| 2284 | |
| 2285 | // validateTransactionForRefund checks if the given transaction is eligible for a refund. |
| 2286 | func (l *LedgerForge) validateTransactionForRefund(ctx context.Context, originalTxn *model.Transaction) error { |
no test coverage detected