I am working on subscriptions for a project and want to be able to show the end-user what they will owe today (prorated difference if upgrading) and what they will pay monthly moving forward. This part is pretty straight forward but the issue comes when I want to also have the user upgrade and apply a new coupon code.
I am submitting the coupon to the Stripe invoices.retrieveUpcoming API and the object that is returned has discount information on it but the line items don't show the discounted prices.
Here is an example output from the API call:
{
"object": "invoice",
"account_country": "US",
"account_name": "MPACT Assessment",
"account_tax_ids": null,
"amount_due": 8950,
"amount_paid": 0,
"amount_remaining": 8950,
"application_fee_amount": null,
"attempt_count": 0,
"attempted": false,
"billing_reason": "upcoming",
"charge": null,
"collection_method": "charge_automatically",
"created": 1619725969,
"currency": "usd",
"custom_fields": null,
"customer": "cus_J9130PfYbywDY7",
"customer_address": null,
"customer_email": "testylittletester@gmail.com",
"customer_name": "Testy Tester",
"customer_phone": null,
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
"description": null,
"discount": {
"id": "di_1IaR98G7MnKgivLUT7aFESCe",
"object": "discount",
"checkout_session": null,
"coupon": {
"id": "test_coupon50",
"object": "coupon",
"amount_off": null,
"created": 1616428624,
"currency": null,
"duration": "forever",
"duration_in_months": null,
"livemode": true,
"max_redemptions": null,
"metadata": {},
"name": "Test Coupon",
"percent_off": 50,
"redeem_by": null,
"times_redeemed": 19,
"valid": true
},
"customer": "cus_J9130PfYbywDY7",
"end": null,
"invoice": "in_1IaR98G7MnKgivLUhmyyoJUi",
"invoice_item": null,
"promotion_code": null,
"start": 1617047590,
"subscription": null
},
"discounts": [
"di_1IaR98G7MnKgivLUT7aFESCe"
],
"due_date": null,
"ending_balance": 0,
"footer": null,
"last_finalization_error": null,
"lines": {
"object": "list",
"data": [
{
"id": "il_tmp1IaR98G7MnKgivLU7VWoVDNL",
"object": "line_item",
"amount": -2900,
"currency": "usd",
"description": "Unused time on Teams Dashboard after 29 Mar 2021",
"discount_amounts": [
{
"amount": 0,
"discount": "di_1IaR98G7MnKgivLUT7aFESCe"
}
],
"discountable": false,
"discounts": [],
"invoice_item": "ii_1IaR98G7MnKgivLU7VWoVDNL",
"livemode": true,
"metadata": {},
"period": {
"end": 1619725969,
"start": 1617047590
},
"plan": {
"id": "teams_starter030421",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 2900,
"amount_decimal": "2900",
"billing_scheme": "per_unit",
"created": 1614974026,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": true,
"metadata": {
"maxTeams": "3"
},
"nickname": "Starter Teams Dashboard",
"product": "prod_J3PgxhjcFS5hSY",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "teams_starter030421",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1614974026,
"currency": "usd",
"livemode": true,
"lookup_key": null,
"metadata": {
"maxTeams": "3"
},
"nickname": "Starter Teams Dashboard",
"product": "prod_J3PgxhjcFS5hSY",
"recurring": {
"aggregate_usage": null,
"interval": "month",
"interval_count": 1,
"trial_period_days": null,
"usage_type": "licensed"
},
"tiers_mode": null,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 2900,
"unit_amount_decimal": "2900"
},
"proration": true,
"quantity": 1,
"subscription": "sub_JCqq4Pb9LCeqPt",
"subscription_item": "si_JCqqKM0mNJwXqR",
"tax_amounts": [],
"tax_rates": [],
"type": "invoiceitem"
},
{
"id": "il_tmp1IaR98G7MnKgivLUFy2gEVp3",
"object": "line_item",
"amount": 7900,
"currency": "usd",
"description": "Remaining time on Teams Dashboard after 29 Mar 2021",
"discount_amounts": [
{
"amount": 0,
"discount": "di_1IaR98G7MnKgivLUT7aFESCe"
}
],
"discountable": false,
"discounts": [],
"invoice_item": "ii_1IaR98G7MnKgivLUFy2gEVp3",
"livemode": true,
"metadata": {},
"period": {
"end": 1619725969,
"start": 1617047590
},
"plan": {
"id": "teams_leader031921",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 7900,
"amount_decimal": "7900",
"billing_scheme": "per_unit",
"created": 1616186579,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": true,
"metadata": {
"maxTeams": "10"
},
"nickname": "Team Leader Dashboard",
"product": "prod_J3PgxhjcFS5hSY",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "teams_leader031921",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1616186579,
"currency": "usd",
"livemode": true,
"lookup_key": null,
"metadata": {
"maxTeams": "10"
},
"nickname": "Team Leader Dashboard",
"product": "prod_J3PgxhjcFS5hSY",
"recurring": {
"aggregate_usage": null,
"interval": "month",
"interval_count": 1,
"trial_period_days": null,
"usage_type": "licensed"
},
"tiers_mode": null,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 7900,
"unit_amount_decimal": "7900"
},
"proration": true,
"quantity": 1,
"subscription": "sub_JCqq4Pb9LCeqPt",
"subscription_item": "si_JCqqKM0mNJwXqR",
"tax_amounts": [],
"tax_rates": [],
"type": "invoiceitem"
},
{
"id": "il_tmp_c014e7ccd7984e",
"object": "line_item",
"amount": 7900,
"currency": "usd",
"description": "1 × Teams Dashboard (at $79.00 / month)",
"discount_amounts": [
{
"amount": 3950,
"discount": "di_1IaR98G7MnKgivLUT7aFESCe"
}
],
"discountable": true,
"discounts": [],
"livemode": true,
"metadata": {},
"period": {
"end": 1622317969,
"start": 1619725969
},
"plan": {
"id": "teams_leader031921",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 7900,
"amount_decimal": "7900",
"billing_scheme": "per_unit",
"created": 1616186579,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": true,
"metadata": {
"maxTeams": "10"
},
"nickname": "Team Leader Dashboard",
"product": "prod_J3PgxhjcFS5hSY",
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"price": {
"id": "teams_leader031921",
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1616186579,
"currency": "usd",
"livemode": true,
"lookup_key": null,
"metadata": {
"maxTeams": "10"
},
"nickname": "Team Leader Dashboard",
"product": "prod_J3PgxhjcFS5hSY",
"recurring": {
"aggregate_usage": null,
"interval": "month",
"interval_count": 1,
"trial_period_days": null,
"usage_type": "licensed"
},
"tiers_mode": null,
"transform_quantity": null,
"type": "recurring",
"unit_amount": 7900,
"unit_amount_decimal": "7900"
},
"proration": false,
"quantity": 1,
"subscription": "sub_JCqq4Pb9LCeqPt",
"subscription_item": "si_JCqqKM0mNJwXqR",
"tax_amounts": [],
"tax_rates": [],
"type": "subscription"
}
],
"has_more": false,
"total_count": 3,
"url": "/v1/invoices/upcoming/lines?customer=cus_J9130PfYbywDY7&subscription=sub_JCqq4Pb9LCeqPt&subscription_proration_behavior=create_prorations"
},
"livemode": true,
"metadata": {},
"next_payment_attempt": 1619729569,
"number": null,
"on_behalf_of": null,
"paid": false,
"payment_intent": null,
"payment_settings": {
"payment_method_options": null,
"payment_method_types": null
},
"period_end": 1619725969,
"period_start": 1617047569,
"post_payment_credit_notes_amount": 0,
"pre_payment_credit_notes_amount": 0,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"status": "draft",
"status_transitions": {
"finalized_at": null,
"marked_uncollectible_at": null,
"paid_at": null,
"voided_at": null
},
"subscription": "sub_JCqq4Pb9LCeqPt",
"subscription_proration_date": 1617047590,
"subtotal": 12900,
"tax": null,
"total": 8950,
"total_discount_amounts": [
{
"amount": 3950,
"discount": "di_1IaR98G7MnKgivLUT7aFESCe"
}
],
"total_tax_amounts": [],
"transfer_data": null,
"webhooks_delivered_at": null
}
If coupons are taken out of the equation, I can simply combine the first two line items to get the difference between the time on their current plan and the time remaining on the new plan. If there is already a coupon applied to this subscription, those amounts are correct but if I attempt to add a new coupon, those amounts are incorrect.
I've tried submitting the payment and comparing the resulting receipt with the items in the upcoming invoice but I can't see a way to consistently determine the amount due today with a new coupon code.
Thanks in advance!
EDIT: This (linked image below) is a screenshot of the receipt that is generated. Basically what I want to do is correctly display these amounts (including a newly entered promotion code/coupon)