Building a Stripe Sigma query for revenue recognition on subscriptions - stripe-payments

There are a bunch of separate services and addons for Stripe that will calculate monthly revenue recognition numbers from >1 month subscriptions (e.g. yearly plans).
However, with the arrival of Stripe Sigma, can anyone help on an SQL query that would identify all customers, their subscription period, and charged amount
I'm looking for these fields, at least:
Customer ID
Subscription ID
Subscription start date
Subscription end date
Currency
Charged/paid amount (the upfront payment)
Thanks!

Sharing my first attempt at this
select distinct
invoices.customer_id as customer,
invoices.id as stripe_invoice,
invoice_line_items.period_start as subscription_start,
invoice_line_items.period_end as subscription_end,
date_trunc('month', invoice_line_items.period_start) as recognition_start,
date_add('month', -1, invoice_line_items.period_end) as recognition_end,
invoices.currency as currency,
(invoices.amount_due - coalesce(invoices.tax, 0)) / 100.0 as collected_amount_excl_tax
from invoices
left join invoice_line_items
on invoices.id = invoice_line_items.invoice_id
where invoices.amount_due > 0
and paid
and date_diff('day', invoice_line_items.period_start, invoice_line_items.period_end) > 31
order by invoices.customer_id, invoices.id
Then using a spreadsheet to calculate deferred and recognized every month.
Would love some feedback on what I'm missing / forgetting

Related

Stripe: Can I create a single "1 month free" promo code for multiple products?

I've been reading though the Stripe documentation but can't figure out if it's possible to have a single promotion code for multiple products, to give a 1-month discount, for products which have both monthly and yearly pricing.
Our product setup is like this:
Basic tier product
Monthly price (upsells to yearly price)
Yearly price
Plus tier product
Monthly price (upsells to yearly price)
Yearly price
I’d like to set up a single promotion code to give to customers, to discount the price of one month, regardless of the product they choose and whether they select monthly or yearly billing.
If I set up a 100% discount coupon then I can apply it to both products, but then if the user chooses annual billing, it discounts the price of the entire year (we only want to discount the price of one month).
If we set up fixed-amount discount coupons, then I'd need to create different promotion codes for each product (we only want to give customers a single code).
Maybe this simply isn't possible with Stripe, but it seems like quite a reasonable/common use case, so wanted check.
Any help much appreciated!
Unfortunately this is not possible with a single Stripe coupon. You would need to create at least two different coupons: one for the basic tier product worth one month, and one for the plus tier worth one month.

stripe subscription from first date of the month with initial fee

I want to do stripe monthly subscription with these conditions
monthly charge 30 dollars
payment should be done first date of the month
when registration is done in the middle of the month daily rate fee should be paid at the timing registration is done
for example, user registered August 10th
20 dollars should be paid at that timing
30 us dollar subscription is done at September 1st and following first date of the month
how can I configure this?
I want to know the configuration for stripe.checkout.sessions
In general, you would achieve exactly what you seek by setting the billing cycle anchor on the 1st of the next month and allow a prorated invoice to be generated for the partial period until then:
https://stripe.com/docs/billing/subscriptions/billing-cycle#new-subscriptions
However, this option for the Subscription create API is not available via Checkout:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data
You could achieve a similar result by setting subcription_data[trial_end] to be the 1st of the next month to effectively set the billing anchor then:
https://stripe.com/docs/billing/subscriptions/billing-cycle#using-a-trial-to-change-the-billing-cycle
You'll need to calculate your own prorated amount for the first month, and then add a one-time Price in the line_items alongside the recurring Price to add the prorated amount to the first invoice only:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items

Stripe retrieve all the paid amount on a subscription

I have a subscription with proration. So for the first months, the client is charged 10 euros and for the last month the client is charged 9.99. Sometimes, some coupons are applied and the client is charged 5 euros. How can I get the total of all the amounts paid by this customer for this subscription? I need to get the sum of 10 x (number of months) + 9.99 + 5 x (number of months where coupons was applied).. In other words, I need to get all the amount of all the money he previously paid until now.
You can retrieve all the invoices for a given Customer https://stripe.com/docs/api/invoices/list. If you want the invoices for a particular Subscription, pass in the subscription parameter.
You can then iterate through all the invoices and sum the amounts paid. Note that you can only retrieve up to 100 invoices.

Stripe - A Single Monthly & Metered Product

Building a SaaS service with a $30 monthly fee. There are additional 1-time-use services they can use during the month. To make the payment quick and nearly thoughtless, I want to also run a metered bill.
How would I setup a product in the dashboard for this?
How would my invoice.succeeded/invoice.failed webhooks to discern if they've only paid the metered bill, only next month's bill, or both paid.
Example: Pays $30 for 1 month. Uses additional services (total $5)
Next Month Payment Cases:
If the user pays next month: $30 / month + $5 previous month (single payment totaling $35).
If the user doesn't pay next month: $5 for usage of previous month and subscription status marked as 'canceled'.
I spoke to the Support Chat (they're smart!). They've recommended doing a metered bill with a flat fee of $30. This is great except the monthly fee is paid at the end of the month. When they enroll, no deposit is made until an entire month of service.
The approach here is to have 2 Products/Prices (with the same billing period i.e. monthly) and to create the Subscription with both of these Prices. The first is the fixed price recurring monthly amount of $30. This will be billed up front on every billing cycle.
The second Product/Price should be a metered Price based on volume [1]. You then would report usage to the API during the billing period [2] (specifying the metered subscription item). That will be the one-time occasional use per month. In this model the upcoming Invoice will be for $35, 30 from the standard monthly subscription, and $5 that was reported as used during the previous month.
If a customer doesn't pay the Invoice, it follows the normal Invoice lifecycle [3]. There is no separate billing/payment for Subscription items.
[1] https://stripe.com/docs/billing/subscriptions/model#common-models
[2] https://stripe.com/docs/api/usage_records/create
[3] https://stripe.com/docs/billing/subscriptions/overview#invoice-lifecycle

Creating a stripe subscription with a loyalty/tiered discount

I'm trying to create a subscription in stripe which depending on how long people have been subscribed the price per month goes down e.g.:
1st month 1000$
2nd,3rd,4th month 800$
5-9 months 750$
9-12 600$
< 12 500$
I looked into tiered discounts but couldn't find a relation to the single subscription price since tiered discount seems to only look at currently subscribed units, and not total volume of units since subscription started. Any advice?
You can do this by listening for upcoming invoices and then changing the Plan on the Subscription based on how long the Subscription has been active.
Another option is to use Subscription Schedules.

Resources