add getinvoice endpoint

This commit is contained in:
kiwiidb
2022-06-17 15:44:54 +02:00
parent b256a3fefe
commit adba6d3006
4 changed files with 169 additions and 1 deletions

View File

@@ -183,6 +183,45 @@ func (controller *InvoiceController) AddInvoice(c echo.Context) error {
return c.JSON(http.StatusOK, &responseBody) 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 { 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)
} }

View File

@@ -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": { "/v2/payments/bolt11": {
"post": { "post": {
"security": [ "security": [

View File

@@ -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": { "/v2/payments/bolt11": {
"post": { "post": {
"security": [ "security": [

View File

@@ -272,6 +272,37 @@ paths:
summary: Generate a new invoice summary: Generate a new invoice
tags: tags:
- Invoice - 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: /v2/invoices/incoming:
get: get:
consumes: consumes: