validateTransactionForRefund checks if the given transaction is eligible for a refund.
(ctx context.Context, originalTxn *model.Transaction)
| 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 { |
| 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. |
| 2314 | func prepareRefundTransaction(originalTxn *model.Transaction, skipQueue bool) *model.Transaction { |
no test coverage detected