diff --git a/controllers_v2/invoice.ctrl.go b/controllers_v2/invoice.ctrl.go index 1af5df2..b595ad3 100644 --- a/controllers_v2/invoice.ctrl.go +++ b/controllers_v2/invoice.ctrl.go @@ -24,7 +24,7 @@ type Invoice struct { PaymentHash string `json:"payment_hash"` PaymentRequest string `json:"payment_request"` Description string `json:"description"` - DescriptionHash string `json:"description_hash"` + DescriptionHash string `json:"description_hash,omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"` Destination string `json:"destination"` Amount int64 `json:"amount"` @@ -36,7 +36,7 @@ type Invoice struct { ExpiresAt time.Time `json:"expires_at"` IsPaid bool `json:"is_paid"` Keysend bool `json:"keysend"` - CustomRecords map[uint64][]byte `json:"custom_records"` + CustomRecords map[uint64][]byte `json:"custom_records,omitempty"` } // GetOutgoingInvoices godoc @@ -108,7 +108,6 @@ func (controller *InvoiceController) GetIncomingInvoices(c echo.Context) error { PaymentRequest: invoice.PaymentRequest, Description: invoice.Memo, DescriptionHash: invoice.DescriptionHash, - PaymentPreimage: invoice.Preimage, Destination: invoice.DestinationPubkeyHex, Amount: invoice.Amount, Fee: invoice.Fee, @@ -126,7 +125,7 @@ func (controller *InvoiceController) GetIncomingInvoices(c echo.Context) error { } type AddInvoiceRequestBody struct { - Amount int64 `json:"amount" validate:"required,gt=0"` + Amount int64 `json:"amount" validate:"required,gte=0"` Description string `json:"description"` DescriptionHash string `json:"description_hash" validate:"omitempty,hexadecimal,len=64"` } @@ -163,13 +162,9 @@ func (controller *InvoiceController) AddInvoice(c echo.Context) error { return c.JSON(http.StatusBadRequest, responses.BadArgumentsError) } - amount, err := controller.svc.ParseInt(body.Amount) - if err != nil || amount < 0 { - return c.JSON(http.StatusBadRequest, responses.BadArgumentsError) - } - c.Logger().Infof("Adding invoice: user_id:%v memo:%s value:%v description_hash:%s", userID, body.Description, amount, body.DescriptionHash) + c.Logger().Infof("Adding invoice: user_id:%v memo:%s value:%v description_hash:%s", userID, body.Description, body.Amount, body.DescriptionHash) - invoice, err := controller.svc.AddIncomingInvoice(c.Request().Context(), userID, amount, body.Description, body.DescriptionHash) + invoice, err := controller.svc.AddIncomingInvoice(c.Request().Context(), userID, body.Amount, body.Description, body.DescriptionHash) if err != nil { c.Logger().Errorf("Error creating invoice: user_id:%v error: %v", userID, err) sentry.CaptureException(err) @@ -215,7 +210,7 @@ func (controller *InvoiceController) GetInvoice(c echo.Context) error { Amount: invoice.Amount, Fee: invoice.Fee, Status: invoice.State, - Type: common.InvoiceTypeUser, + Type: invoice.Type, ErrorMessage: invoice.ErrorMessage, SettledAt: invoice.SettledAt.Time, ExpiresAt: invoice.ExpiresAt.Time, diff --git a/controllers_v2/keysend.ctrl.go b/controllers_v2/keysend.ctrl.go index 6708511..7b674a1 100644 --- a/controllers_v2/keysend.ctrl.go +++ b/controllers_v2/keysend.ctrl.go @@ -29,12 +29,11 @@ type KeySendRequestBody struct { } type KeySendResponseBody struct { - Amount int64 `json:"amount,omitempty"` - Fee int64 `json:"fee,omitempty"` + Amount int64 `json:"amount"` + Fee int64 `json:"fee"` Description string `json:"description,omitempty"` DescriptionHash string `json:"description_hash,omitempty"` Destination string `json:"destination,omitempty"` - PaymentError string `json:"payment_error,omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"` PaymentHash string `json:"payment_hash,omitempty"` } @@ -112,12 +111,10 @@ func (controller *KeySendController) KeySend(c echo.Context) error { } responseBody := &KeySendResponseBody{ - Amount: sendPaymentResponse.Invoice.Amount, - Fee: sendPaymentResponse.Invoice.Fee, - Description: sendPaymentResponse.Invoice.Memo, - DescriptionHash: sendPaymentResponse.Invoice.DescriptionHash, - Destination: sendPaymentResponse.Invoice.DestinationPubkeyHex, - PaymentError: sendPaymentResponse.PaymentError, + Amount: sendPaymentResponse.PaymentRoute.TotalAmt, + Fee: sendPaymentResponse.PaymentRoute.TotalFees, + Description: reqBody.Memo, + Destination: reqBody.Destination, PaymentPreimage: sendPaymentResponse.PaymentPreimageStr, PaymentHash: sendPaymentResponse.PaymentHashStr, } diff --git a/controllers_v2/payinvoice.ctrl.go b/controllers_v2/payinvoice.ctrl.go index 157d8e6..076a241 100644 --- a/controllers_v2/payinvoice.ctrl.go +++ b/controllers_v2/payinvoice.ctrl.go @@ -28,11 +28,10 @@ type PayInvoiceRequestBody struct { type PayInvoiceResponseBody struct { PaymentRequest string `json:"payment_request,omitempty"` Amount int64 `json:"amount,omitempty"` - Fee int64 `json:"fee,omitempty"` + Fee int64 `json:"fee"` Description string `json:"description,omitempty"` DescriptionHash string `json:"description_hash,omitempty"` Destination string `json:"destination,omitempty"` - PaymentError string `json:"payment_error,omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"` PaymentHash string `json:"payment_hash,omitempty"` } @@ -120,12 +119,12 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { }) } responseBody := &PayInvoiceResponseBody{ - Amount: sendPaymentResponse.Invoice.Amount, - Fee: sendPaymentResponse.Invoice.Fee, - Description: sendPaymentResponse.Invoice.Memo, - DescriptionHash: sendPaymentResponse.Invoice.DescriptionHash, - Destination: sendPaymentResponse.Invoice.DestinationPubkeyHex, - PaymentError: sendPaymentResponse.PaymentError, + PaymentRequest: paymentRequest, + Amount: sendPaymentResponse.PaymentRoute.TotalAmt, + Fee: sendPaymentResponse.PaymentRoute.TotalFees, + Description: invoice.Memo, + DescriptionHash: invoice.DescriptionHash, + Destination: invoice.DestinationPubkeyHex, PaymentPreimage: sendPaymentResponse.PaymentPreimageStr, PaymentHash: sendPaymentResponse.PaymentHashStr, } diff --git a/lib/responses/errors.go b/lib/responses/errors.go index e35a88c..5e0ddbc 100644 --- a/lib/responses/errors.go +++ b/lib/responses/errors.go @@ -35,7 +35,7 @@ var BadAuthError = ErrorResponse{ var NotEnoughBalanceError = ErrorResponse{ Error: true, Code: 2, - Message: "not enough balance. Make sure you have at least 1%% reserved for potential fees", + Message: "not enough balance. Make sure you have at least 1% reserved for potential fees", } func HTTPErrorHandler(err error, c echo.Context) {