diff --git a/controllers_v2/invoice.ctrl.go b/controllers_v2/invoice.ctrl.go index 43f320f..1af5df2 100644 --- a/controllers_v2/invoice.ctrl.go +++ b/controllers_v2/invoice.ctrl.go @@ -183,6 +183,45 @@ func (controller *InvoiceController) AddInvoice(c echo.Context) error { return c.JSON(http.StatusOK, &responseBody) } + +// GetInvoice godoc +// @Summary Get a specific invoice +// @Description Retrieve information about a specific invoice by payment hash +// @Accept json +// @Produce json +// @Tags Account +// @Param payment_hash path string true "Payment hash" +// @Success 200 {object} Invoice +// @Failure 400 {object} responses.ErrorResponse +// @Failure 500 {object} responses.ErrorResponse +// @Router /v2/invoices/{payment_hash} [get] +// @Security OAuth2Password func (controller *InvoiceController) GetInvoice(c echo.Context) error { - return nil + userID := c.Get("UserID").(int64) + rHash := c.Param("payment_hash") + invoice, err := controller.svc.FindInvoiceByPaymentHash(c.Request().Context(), userID, rHash) + // Probably we did not find the invoice + if err != nil { + c.Logger().Errorf("Invalid checkpayment request user_id:%v payment_hash:%s", userID, rHash) + return c.JSON(http.StatusBadRequest, responses.BadArgumentsError) + } + responseBody := Invoice{ + PaymentHash: invoice.RHash, + PaymentRequest: invoice.PaymentRequest, + Description: invoice.Memo, + DescriptionHash: invoice.DescriptionHash, + PaymentPreimage: invoice.Preimage, + Destination: invoice.DestinationPubkeyHex, + Amount: invoice.Amount, + Fee: invoice.Fee, + Status: invoice.State, + Type: common.InvoiceTypeUser, + ErrorMessage: invoice.ErrorMessage, + SettledAt: invoice.SettledAt.Time, + ExpiresAt: invoice.ExpiresAt.Time, + IsPaid: invoice.State == common.InvoiceStateSettled, + Keysend: invoice.Keysend, + CustomRecords: invoice.DestinationCustomRecords, + } + return c.JSON(http.StatusOK, &responseBody) } diff --git a/docs/docs.go b/docs/docs.go index df51af4..4d28496 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -246,6 +246,55 @@ const docTemplate = `{ } } }, + "/v2/invoices/{payment_hash}": { + "get": { + "security": [ + { + "OAuth2Password": [] + } + ], + "description": "Retrieve information about a specific invoice by payment hash", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Account" + ], + "summary": "Get a specific invoice", + "parameters": [ + { + "type": "string", + "description": "Payment hash", + "name": "payment_hash", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2controllers.Invoice" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.ErrorResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.ErrorResponse" + } + } + } + } + }, "/v2/payments/bolt11": { "post": { "security": [ diff --git a/docs/swagger.json b/docs/swagger.json index 394e889..1f3ad19 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -242,6 +242,55 @@ } } }, + "/v2/invoices/{payment_hash}": { + "get": { + "security": [ + { + "OAuth2Password": [] + } + ], + "description": "Retrieve information about a specific invoice by payment hash", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Account" + ], + "summary": "Get a specific invoice", + "parameters": [ + { + "type": "string", + "description": "Payment hash", + "name": "payment_hash", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v2controllers.Invoice" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/responses.ErrorResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/responses.ErrorResponse" + } + } + } + } + }, "/v2/payments/bolt11": { "post": { "security": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 1cc9159..7d83b9d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -272,6 +272,37 @@ paths: summary: Generate a new invoice tags: - Invoice + /v2/invoices/{payment_hash}: + get: + consumes: + - application/json + description: Retrieve information about a specific invoice by payment hash + parameters: + - description: Payment hash + in: path + name: payment_hash + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v2controllers.Invoice' + "400": + description: Bad Request + schema: + $ref: '#/definitions/responses.ErrorResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/responses.ErrorResponse' + security: + - OAuth2Password: [] + summary: Get a specific invoice + tags: + - Account /v2/invoices/incoming: get: consumes: