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

Method RefundTransaction

api/transactions.go:188–205  ·  view source on GitHub ↗

RefundTransaction processes a refund for a transaction based on the given ID. It retrieves the transaction to be refunded and processes it in batches. If any errors occur during retrieval or processing, it responds with an appropriate error message. Parameters: - c: The Gin context containing the r

(c *gin.Context)

Source from the content-addressed store, hash-verified

186// - 400 Bad Request: If there's an error in retrieving the transaction or no transaction is found to refund.
187// - 201 Created: If the refund is successfully processed.
188func (a Api) RefundTransaction(c *gin.Context) {
189 id, passed := c.Params.Get("id")
190 if !passed {
191 c.JSON(http.StatusBadRequest, gin.H{"error": "id is required. pass id in the route /:id"})
192 return
193 }
194 transaction, err := a.ledgerforge.ProcessTransactionInBatches(c.Request.Context(), id, big.NewInt(0), 1, false, a.ledgerforge.GetRefundableTransactionsByParentID, a.ledgerforge.RefundWorker)
195 if err != nil {
196 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
197 return
198 }
199 if len(transaction) == 0 {
200 c.JSON(http.StatusBadRequest, gin.H{"error": "no transaction to refund"})
201 return
202 }
203 resp := transformTransaction(transaction[0])
204 c.JSON(http.StatusCreated, resp)
205}
206
207// GetTransaction retrieves a transaction by its ID.
208// It returns the transaction details if found. If the ID is not provided or an error

Callers

nothing calls this directly

Calls 4

transformTransactionFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected