Skip to content

Instantly share code, notes, and snippets.

@Larrik
Created February 20, 2017 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Larrik/bafb3af39e7a06f9e4518b6311efb850 to your computer and use it in GitHub Desktop.
Save Larrik/bafb3af39e7a06f9e4518b6311efb850 to your computer and use it in GitHub Desktop.
# Existing subscription is only an hour old or so, 6 month interval
# Remove 2 plans totalling 137.4 per 6 months, replace them with 2 plans totalling 199.35 / year
send_kwargs = {
'customer': u'cus_A9hP84PRfngyGi',
'subscription': u'sub_A9hPkvSfTNTrPy',
'subscription_items': [
{u'plan': u'lcp_annual_print_usd'}, # $59.40 / year
{u'plan': u'lcp_annual_online_usd'}, # 129.95 / year
{'deleted': True, 'id': u'si_19pO0N4FL92IQeJUaDdYbQPQ'}, # $95.70 / year
{'deleted': True, 'id': u'si_19pO0N4FL92IQeJU9SRI0IhH'} # $41.70 / year
],
'subscription_proration_date': 1487624768}
# Preview change, expecting a total price of $61.95 (or a little less)
inv = stripe.Invoice.upcoming(**send_kwargs)
# at this point, I'm getting 3 lines back instead of 4, and a total price of $-77.99
<Invoice invoice at 0x7fb981778e30> JSON: {
"amount_due": 0,
"application_fee": null,
"attempt_count": 0,
"attempted": false,
"charge": null,
"closed": false,
"currency": "usd",
"customer": "cus_A9hP84PRfngyGi",
"date": 1487626394,
"description": null,
"discount": null,
"ending_balance": null,
"forgiven": false,
"lines": {
"data": [
{
"amount": -4170,
"currency": "usd",
"description": "Unused time on LCP Semi-Annual Print - USD after 20 Feb 2017",
"discountable": false,
"id": "ii_19pOmU4FL92IQeJUz5j0BZPK",
"livemode": false,
"metadata": {},
"object": "line_item",
"period": {
"end": 1503261811,
"start": 1487624768
},
"plan": {
"amount": 4170,
"created": 1487365977,
"currency": "usd",
"id": "lcp_semiannual_print_usd",
"interval": "month",
"interval_count": 6,
"livemode": false,
"metadata": {},
"name": "LCP Semi-Annual Print - USD",
"object": "plan",
"statement_descriptor": null,
"trial_period_days": null
},
"proration": true,
"quantity": 1,
"subscription": "sub_A9hPkvSfTNTrPy",
"subscription_item": "si_19pO0N4FL92IQeJU9SRI0IhH",
"type": "invoiceitem"
},
{
"amount": -9569,
"currency": "usd",
"description": "Unused time on LCP Semi Annual Online - USD after 20 Feb 2017",
"discountable": false,
"id": "ii_19pOmU4FL92IQeJUEaI9d9Hi",
"livemode": false,
"metadata": {},
"object": "line_item",
"period": {
"end": 1503261811,
"start": 1487624768
},
"plan": {
"amount": 9570,
"created": 1482172088,
"currency": "usd",
"id": "lcp_semiannual_online_usd",
"interval": "month",
"interval_count": 6,
"livemode": false,
"metadata": {},
"name": "LCP Semi Annual Online - USD",
"object": "plan",
"statement_descriptor": null,
"trial_period_days": null
},
"proration": true,
"quantity": 1,
"subscription": "sub_A9hPkvSfTNTrPy",
"subscription_item": "si_19pO0N4FL92IQeJUaDdYbQPQ",
"type": "invoiceitem"
},
{
"amount": 5940,
"currency": "usd",
"description": null,
"discountable": true,
"id": "sub_A9hPkvSfTNTrPy",
"livemode": false,
"metadata": {
"is_free_trial": "False",
"is_gift_redemption": "False",
"is_online": "True",
"is_print": "True",
"offer_plan_enforce_locale": "False",
"offer_plan_is_default_plan": "True",
"offer_plan_limit_to_currency": "USD",
"offer_plan_name": "Main Subscription Plans",
"offer_plan_new_subscribe_only": "False",
"offer_plan_object_id": "1",
"offer_plan_renewal_only": "False",
"offer_plan_url": "main-subscription-plans",
"rate_plan_object_ids": "13,8"
},
"object": "line_item",
"period": {
"end": 1519162394,
"start": 1487626394
},
"plan": {
"amount": 5940,
"created": 1487365926,
"currency": "usd",
"id": "lcp_annual_print_usd",
"interval": "year",
"interval_count": 1,
"livemode": false,
"metadata": {},
"name": "LCP Annual Print - USD",
"object": "plan",
"statement_descriptor": null,
"trial_period_days": null
},
"proration": false,
"quantity": 1,
"subscription": null,
"subscription_item": "si_19pOmU4FL92IQeJUM6snVKRo",
"type": "subscription"
}
],
"has_more": false,
"object": "list",
"total_count": 3,
"url": "/v1/invoices/upcoming/lines?customer=cus_A9hP84PRfngyGi&subscription=sub_A9hPkvSfTNTrPy&subscription_proration_date=1487624768"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": 1487629994,
"object": "invoice",
"paid": false,
"period_end": 1487626394,
"period_start": 1487626394,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": "sub_A9hPkvSfTNTrPy",
"subscription_proration_date": 1487624768,
"subtotal": -7799,
"tax": null,
"tax_percent": null,
"total": -7799,
"webhooks_delivered_at": null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment