Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Currency and interval fields must match across all plans on this subscription. Found mismatch in interval field

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.

like image 752
Jayna Tanawala Avatar asked Aug 14 '19 07:08

Jayna Tanawala


1 Answers

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

like image 109
attacomsian Avatar answered Oct 18 '22 08:10

attacomsian