Skip to content

Commit

Permalink
fix: check if payment exists on order response
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jul 23, 2024
1 parent 4ce061e commit 36ba944
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions api/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func (api *api) requestLSPS1Invoice(ctx context.Context, request *NewInstantChan
// TODO: add onchain
}
type newLSPS1ChannelResponse struct {
Payment newLSPS1ChannelPayment `json:"payment"`
Payment *newLSPS1ChannelPayment `json:"payment"`
}

var newChannelResponse newLSPS1ChannelResponse
Expand All @@ -632,13 +632,16 @@ func (api *api) requestLSPS1Invoice(ctx context.Context, request *NewInstantChan
return "", 0, fmt.Errorf("failed to deserialize json %s %s", request.LSPUrl, string(body))
}

invoice = newChannelResponse.Payment.Bolt11.Invoice
fee, err = strconv.ParseUint(newChannelResponse.Payment.Bolt11.FeeTotalSat, 10, 64)
if err != nil {
logger.Logger.WithError(err).WithFields(logrus.Fields{
"url": request.LSPUrl,
}).Error("Failed to parse fee")
return "", 0, fmt.Errorf("failed to parse fee %v", err)
// if there is no payment, we expect the payment to already be made by the Alby API
if newChannelResponse.Payment != nil {
invoice = newChannelResponse.Payment.Bolt11.Invoice
fee, err = strconv.ParseUint(newChannelResponse.Payment.Bolt11.FeeTotalSat, 10, 64)
if err != nil {
logger.Logger.WithError(err).WithFields(logrus.Fields{
"url": request.LSPUrl,
}).Error("Failed to parse fee")
return "", 0, fmt.Errorf("failed to parse fee %v", err)
}
}

return invoice, fee, nil
Expand Down

0 comments on commit 36ba944

Please sign in to comment.