fix: fiat invoice to Lightning msat conversion by applying real-time BTC FX quotes #7

Merged
hodlbod merged 2 commits from userAdityaa/caravel:fiat-to-msat into master 2026-04-13 21:05:22 +00:00
Contributor

Summary

Stripe invoice amount_due is fiat minor units, not sats/msats. The previous billing logic incorrectly converted amount_due to msats via amount_due * 1000, which implicitly assumed a fixed fiat/BTC rate and caused over/underpayment risk. This change introduces explicit FX-based conversion and propagates invoice currency through both auto-pay and manual bolt11 flows.

Changes

  • Added BTC spot quote fetch from Coinbase endpoint BTC-{CURRENCY}.
  • Added currency-aware conversion from Stripe minor units to msats.
  • Updated invoice.created webhook handling to pass currency to auto-pay.
  • Updated get_invoice_bolt11 path to pass currency to bolt11 generation.
  • Added unit tests for conversion behavior (USD, JPY).

Closes #6

How to verify

  1. Run tests:
  • cd backend
  • cargo test -q
  1. Functional check for manual bolt11:
  • Create or select an open Stripe invoice.
  • Call GET /invoices/:id/bolt11.
  • Confirm generated amount tracks current BTC-{currency} spot (not amount_due * 1000).
### Summary Stripe invoice amount_due is fiat minor units, not sats/msats. The previous billing logic incorrectly converted amount_due to msats via amount_due * 1000, which implicitly assumed a fixed fiat/BTC rate and caused over/underpayment risk. This change introduces explicit FX-based conversion and propagates invoice currency through both auto-pay and manual bolt11 flows. ### Changes * Added BTC spot quote fetch from Coinbase endpoint BTC-{CURRENCY}. * Added currency-aware conversion from Stripe minor units to msats. * Updated invoice.created webhook handling to pass currency to auto-pay. * Updated `get_invoice_bolt11` path to pass currency to bolt11 generation. * Added unit tests for conversion behavior (USD, JPY). Closes #6 ### How to verify 1. Run tests: * cd backend * cargo test -q 2. Functional check for manual bolt11: * Create or select an open Stripe invoice. * Call GET /invoices/:id/bolt11. * Confirm generated amount tracks current BTC-{currency} spot (not amount_due * 1000).
userAdityaa added 2 commits 2026-04-11 18:03:01 +00:00
userAdityaa marked the pull request as work in progress 2026-04-13 15:58:51 +00:00
Owner

LGTM

LGTM
Author
Contributor

Thanks, was testing everything end-to-end on my side and removed the WIP label.

Thanks, was testing everything end-to-end on my side and removed the WIP label.
userAdityaa marked the pull request as ready for review 2026-04-13 17:53:27 +00:00
hodlbod merged commit 9a8d02b286 into master 2026-04-13 21:05:22 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: coracle/caravel#7