<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexander Baumann</title>
    <description>The latest articles on DEV Community by Alexander Baumann (@alexbtoast).</description>
    <link>https://dev.to/alexbtoast</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2579132%2F04ac7c39-8967-4ed8-8903-6f4aebdc7034.jpg</url>
      <title>DEV Community: Alexander Baumann</title>
      <link>https://dev.to/alexbtoast</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexbtoast"/>
    <language>en</language>
    <item>
      <title>Stripe Invoice.Upcoming changes: model switching from monthly to yearly</title>
      <dc:creator>Alexander Baumann</dc:creator>
      <pubDate>Mon, 16 Dec 2024 22:22:59 +0000</pubDate>
      <link>https://dev.to/alexbtoast/updating-upcoming-invoice-api-call-using-stripes-python-sdk-fnm</link>
      <guid>https://dev.to/alexbtoast/updating-upcoming-invoice-api-call-using-stripes-python-sdk-fnm</guid>
      <description>&lt;p&gt;How to use the Python SDK &lt;code&gt;stripe.Invoice.upcoming&lt;/code&gt; call to preview a new invoice using a different quantity and plan?&lt;/p&gt;

&lt;p&gt;There is a reference in the Stripe Invoice docs stating values can be passed when retrieving the upcoming invoice to model what-if scenarios&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/billing/invoices/subscription#previewing:%7E:text=When%20fetching%20the,Adding%20a%20coupon" rel="noopener noreferrer"&gt;https://docs.stripe.com/billing/invoices/subscription#previewing:~:text=When%20fetching%20the,Adding%20a%20coupon&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;ex: you can pass a different subscription_quantity or subscription_plan
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When fetching the preview, you can also model what the invoice would look like if you changed the subscription in one of these ways:

Swapping the underlying price.
Altering the quantity.
Applying a trial period.
Adding a coupon.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There isn't enough information in the API or SDK changelogs to determine how to replace the deprecated params we use with new ones&lt;/p&gt;

&lt;p&gt;Old:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upcoming&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;stripe_subscription_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;subscription_quantity&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;quantity_to_calculate_with&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# if None, defaults to current
&lt;/span&gt;        &lt;span class="n"&gt;subscription_proration_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;proration_date_as_unix_seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
        &lt;span class="n"&gt;subscription_plan&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;plan_to_calculate_with&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# if None, defaults to current  
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Attempted New:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;subscription_details&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="n"&gt;proration_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;proration_date_as_unix_seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
     &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;quantity&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;quantity_to_calculate_with&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;plan&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;plan_to_calculate_with&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;stripe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upcoming&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;customer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;stripe_subscription_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;subscription_details&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;subscription_details&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can set the price to the plan id I was using before, the problem I have now is that I cannot model the new invoice price when switching from a monthly to a yearly plan. The error:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;All prices on a subscription must have the same &lt;code&gt;recurring.interval&lt;/code&gt; and &lt;code&gt;recurring.interval_count&lt;/code&gt;. If you meant to update an existing subscription item instead of creating a new one, make sure to include the subscription item ID in your request. See examples at &lt;a href="https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing" rel="noopener noreferrer"&gt;https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>stripe</category>
    </item>
  </channel>
</rss>
