Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(invoice): stripe app invoice sync #1978

Merged
merged 26 commits into from
Dec 22, 2024
Merged

feat(invoice): stripe app invoice sync #1978

merged 26 commits into from
Dec 22, 2024

Conversation

hekike
Copy link
Contributor

@hekike hekike commented Dec 17, 2024

Synchronize OpenMeter invoices with Stripe Invoicing through apps.

How it works

The invoice state machine calls the interfaces of compatible apps like Stripe App to Upsert and Finalize the invoice.
Driven by the state machine, the Stripe App creates, updates, and finalizes a Stripe Invoice object via the Stripe SDK.

If the invoice doesn't exist yet (determined by checking its external invoicing app ID), it is created; otherwise, it is updated in Stripe. Every OpenMeter invoice line and discount is translated to flat InvoiceLineItem(s) in Stripe. Discounts are represented as negative amounts. The update diffs the line items between Stripe and OpenMeter and decides which lines need to be updated, added, or removed in Stripe.

We prioritize synchronizing lines with quantity and per-unit price for greater visibility when they fit Stripe amount cents. When any Stripe line doesn't fit cents without floating points, we synchronize all lines with the total amount (the product of quantity and unit price).

Currently, automatic tax collection is enabled.

Todos:

@hekike hekike added release-note/feature Release note: Exciting New Features area/billing labels Dec 17, 2024
@hekike hekike requested a review from turip December 17, 2024 14:50
openmeter/app/stripe/entity/app/app_invoice.go Outdated Show resolved Hide resolved
openmeter/app/stripe/entity/app/app_invoice.go Outdated Show resolved Hide resolved
openmeter/app/stripe/entity/app/app_invoice.go Outdated Show resolved Hide resolved
openmeter/app/stripe/entity/app/app_invoice.go Outdated Show resolved Hide resolved
@hekike hekike force-pushed the feat/stripe-invoice branch from 1ef8d89 to dffeffa Compare December 18, 2024 18:03
@hekike hekike force-pushed the feat/stripe-invoice branch from c3df7c0 to 93a8ab6 Compare December 20, 2024 16:44
@hekike hekike marked this pull request as ready for review December 20, 2024 18:59
@hekike hekike requested a review from tothandras December 20, 2024 18:59
@hekike hekike changed the title feat(invoice): stripe app feat(invoice): stripe app invoice sync Dec 21, 2024
openmeter/app/stripe/client/invoice.go Show resolved Hide resolved
openmeter/app/stripe/client/invoice.go Outdated Show resolved Hide resolved
openmeter/app/stripe/client/invoice.go Outdated Show resolved Hide resolved
openmeter/app/stripe/client/invoice.go Show resolved Hide resolved
openmeter/app/stripe/client/invoice.go Show resolved Hide resolved
openmeter/app/stripe/entity/app/customer.go Outdated Show resolved Hide resolved
@hekike hekike requested a review from tothandras December 22, 2024 16:14
@hekike hekike merged commit e26cd7b into main Dec 22, 2024
24 checks passed
@hekike hekike deleted the feat/stripe-invoice branch December 22, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/billing release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants