Using "Additional Fees SPI" to add fees at checkout if visitor isn't on a pricing plan

I’m using the “ecommerce additional fees” custom extension to try to add an additional fee at checkout if the visitor isn’t a part of a pricing plan.

Wix Editor Dev Mode SPI’s

I have pricing plans on my site. I’d like to add something at checkout that looks to see what pricing plan the customer is on and if they aren’t on one, then it adds a small additional fee at checkout.

I followed the “additional fees” example, which showed how to add the “Additional Fees SPI” extension, which worked. It shows how to add fees at checkout for fragile items, but I needed to add an additional fee if the customer hasn’t purchased a pricing plan. I tried to enter some elements to retrieve the pricing plan status of the visitor but I’m sure I made a mess of it. The actual name of the pricing plan itself is “$20” (I know, a bad name).I want to charge them a small fee upon checkout if they’re not on that plan. Here’s the code I’m trying to get right:

import { getCurrentUser } from 'wix-users-backend';
import { getSubscriptions } for 'wix-pricing-plans-backend;
import * as ecomAdditionalFees from 'wix-ecommerce-backend';

export async function calculateAdditionalFees() {
  let additionalFees = [];
  const user = await getCurrentUser();
  const userId = user.id;
  const subscriptions = await getSubscriptions(userId);
  const hasRequiredPlan = !subscriptions.some(subscription => subscription.planId === "$20");

  if (!hasRequiredPlan) {
    additionalFees.push({
      code: 'non-monthly-member',
      name: 'Non-Monthly Member',
      price: 2.50,
      taxDetails: { taxable: false }
    }) 
    
  } else 

  // Assuming `currency` is previously set or retrieved
  return {
    currency: 'USD', // This should match your site's currency
    additionalFees
  };
}

I have a few other checkout fees and discounts I’m going to need to add later based on their pricing plan or badge, so I’d be really grateful if you could help me off to a good start with this one. Thanks!

This line says for rather than from. There’s also no getSubscriptions function in this library. https://www.wix.com/velo/reference/wix-pricing-plans-backend/orders/listcurrentmemberorders provides the information needed here.

There’s no library called wix-users-backend but there is a wix-members-backend with functions that do this.

I don’t believe planIds are the plan’s name, they should be uuids. You can see the ids of plans with: https://www.wix.com/velo/reference/wix-pricing-plans-backend/listplans