#big-sister_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1219425682577166497
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, did listing all invoices and detecting for if the coupon used work? There is not an API call that you can make the coupon, https://docs.stripe.com/api/coupons/list to get this data.
list all coupons doesnt appear that it would return information about invoices or subscriptions
That is correct, it would not.
whats the recommended approach? surely businesses want to be able to measure the revenue associated with a coupon?
did listing all invoices and detecting for if the coupon used work?
not yet
I would recommend trying that first. Let me know if that does not work.
def revenue_by_month_for_coupon(coupon_name)
puts "Fetching all invoices..."
all_invoices = Stripe::Invoice.list # No limit specified
# Initialize a hash to store revenue by month for the specified coupon
revenue_by_month = Hash.new(0)
all_invoices.auto_paging_each do |invoice|
# Check if the invoice has the discount applied and matches the specified coupon name
if invoice.discount&.coupon&.name == coupon_name
invoice_month = Time.at(invoice.created).strftime("%Y-%m")
actual_payment = invoice.amount_paid / 100.0 # Assuming amount_paid is in cents
revenue_by_month[invoice_month] += actual_payment
puts "Invoice ID: #{invoice.id}, Coupon: #{coupon_name}, Month: #{invoice_month}, Actual Payment: $#{actual_payment}"
end
end
# Output the total revenue by month for the specified coupon
revenue_by_month.each do |month, revenue|
puts "Month: #{month}, Total Revenue from Coupon '#{coupon_name}': $#{revenue}"
end
return revenue_by_month
end
this seems to work at least with our limited data set as a solution for coupon -> revenue that coupon has been associated with
doesnt seem to be coming along as part of the response
maybe it needs to be requested?
i think for my use case- i want to measure the total revenue of invoices where a coupon appeared, so if there was another coupon i still want to only count the amount paid
in this case- its configured right unless im misunderstanding your suggestion
One Invoice can have 3 separate Coupons on it. Doing this by looking at invoice.discount won't work in that case because you'd only find one
sorry have to run @little vapor is taking over
is there a way to specify that only one coupon can be used?
i think we might have that in place already
You're asking how to configure an Invoice to only use a single coupon?
im asking how to prevent the scenario in which invoice.discount wont work
If you want to make sure Invoices only pass in a single coupon that'd be something you'd have to control in the Invoice creation code on your end - but is there a reason you don't want to use invoice.discounts?