7
votes

I am using stripe to implement payment feature. In payment feature I have two subscription plan monthly and yearly respectively. From stripe dashboard I created product and under that created two plans monthly and yearly. As per the name I set interval to monthly and yearly respectively.

I am successfully able to create subscription. But when I try to change my subscription plan I am getting this error: Currency and interval fields must match across all plans on this subscription. Found mismatch in interval field.

Error saying that currency and interval must match. But how can I make them same. For monthly plan I set monthly interval and for yearly plan I set yearly interval which is proper I guess. Don't know where I mistaken.

Here is my code:

const subscription = getSubscription(req.body.subscriptionId);
      subscription.then((value) => {
        id = value.id;
      })
        stripe.subscriptions.update(
          req.body.subscriptionId,
          {
            items: [{
              id: id,
              plan: req.body.planId,
            }]
          },
          function(err, subscription) {
            if(err) {
              console.log('error .... ', err);
              return;
            }
            console.log('updated subscription... ', subscription);
          });


async function getSubscription(subscriptionId) {
  return await stripe.subscriptions.retrieve(subscriptionId);
}

I took this code from this: https://stripe.com/docs/billing/subscriptions/upgrading-downgrading

Please help me out.

3
Can you share the code you're using to update the subscription? I suspect what's happening here is you are trying to update a Subscription, and rather than update the existing Subscription Item, it's creating a second item; as all items on a given Subscription must have the same currency/interval this is causing an error. The update code can help!duck
I edited my question @duck. You can see the code.Jayna Tanawala
Hmm, that code looks okay at my glance, you are updating the existing subscription item id. if you have a request that is failing i'd email the request id req_xxxyyy to stripe and they can take a look and what's going onduck
I had similar issues. It looks like you might be passing in the subscription Id as the item id. The example shows how to retrieve the relevant item id from the subscription. I assume you may need to change "id = value.id;" to "id = value.items.data[0].id;" ?bgx
Yes, @bgx.. I made this mistake.. Thank you for answer and sorry for late reply..Jayna Tanawala

3 Answers

7
votes

For anyone, who is still looking to solve this issue, you have to specify the current subscription item ID while downgrading or upgrading the plan.

Without the existing item ID, it throws an error when the billing interval is different (month <-> year).

const subscription = await stripe.subscriptions.retrieve('SUBSCRIPTION_ID');
stripe.subscriptions.update('SUBSCRIPTION_ID', {
  cancel_at_period_end: false,
  proration_behavior: 'create_prorations',
  items: [{
    id: subscription.items.data[0].id,
    price: 'NEW_PRICE_ID',
  }]
});

The following line is crucial:

id: subscription.items.data[0].id,

Source: Stripe Docs

0
votes

Please check restriction when creating multiple-plan in single subscriptions

Check docs

0
votes

Just wanted to add to this - if you have more than one subscription under the same Customer id, all of those subscriptions must match up in interval. So in my case I was creating multiple subscriptions for testing purposes under the same customer ID. This was causing the: Currency and interval fields must match across all plans on this subscription. Found mismatch in interval field. Once I started with a fresh customer ID, and a new subscription, updating the interval worked fine. (because there is only one subscription, and only one interval to change)