# Integrate Freemius Billing and Monetization with Command Code

In this guide, you will learn how to set up [Command Code](https://commandcode.ai/) to integrate Freemius monetization, checkout, entitlements, and customer portal features into your SaaS product.

## Preparation[​](#preparation "Direct link to Preparation")

1. Register through the Freemius [Developer Dashboard](https://dashboard.freemius.com/) and create a product.
2. Follow our [plans and pricing documentation](https://freemius.com/help/help/documentation/saas/saas-plans-pricing/.md) to configure your plans, prices, and plan features.
3. Open a terminal in the project that you want Command Code to update and start Command Code.

## Install Freemius Skills[​](#install-freemius-skills "Direct link to Install Freemius Skills")

From the project root, run the following command:

* npm
* Yarn
* pnpm
* Bun

```
npx skills add freemius/freemius-ai
```

```
yarn dlx skills add freemius/freemius-ai
```

```
pnpm dlx skills add freemius/freemius-ai
```

```
bun x skills add freemius/freemius-ai
```

Select Command Code and install all the Freemius skills when prompted to get the complete checkout, entitlement, and customer portal workflow.

## Set Your Freemius API Key[​](#set-your-freemius-api-key "Direct link to Set Your Freemius API Key")

On the **Settings** → **API & Keys** page, copy the `.env` file under **Usage examples** and save it in your project root.

![Freemius API and keys page showing the generated environment file](/help/assets/ideal-img/freemius-env-file.aeb19fb.480.png)

Protect Your API Keys

Never commit the `.env` file to your repository. Store production credentials in your deployment platform's secrets manager.

## Prompt Your First Integration[​](#prompt-your-first-integration "Direct link to Prompt Your First Integration")

Prompt Command Code with a brief description of how you want to integrate Freemius and gate premium features behind a paywall. For example:

prompt

```
Integrate Freemius monetization into my software. I want to offer subscriptions with multiple plans for continued access and top-up plans for purchasing additional credits. Use the relevant Freemius skills. The .env file already contains the secrets needed to connect to the Freemius platform. You can query the Freemius API directly with the Freemius JS SDK to find the pricing IDs of the relevant plans. First inspect the existing application and propose an integration plan. After I approve the plan, implement it and run the relevant tests.
```

Command Code will use the installed skills and your Freemius product configuration to implement the relevant pricing table, checkout, entitlements, top-up credits, and customer portal features. It may also create or update a top-level `AGENTS.md` file with instructions for maintaining the integration.

Plan Before You Prompt

For a complex product setup, enter Command Code's [Plan mode](https://commandcode.ai/docs/plan-mode) with `/plan`. Ask it to inspect the codebase and propose an implementation without editing files. Review the proposed architecture, especially the authentication, entitlement storage, webhook handling, and checkout flow. Approve the plan when you are ready for Command Code to implement it.

Explain whether you sell subscriptions, top-up credits, or both. Also mention whether a user can hold more than one subscription and where premium access must be enforced.

## Complete the Dashboard Setup[​](#complete-the-dashboard-setup "Direct link to Complete the Dashboard Setup")

After implementing the integration, Command Code may ask you to configure URLs in the Freemius Developer Dashboard:

* Go to **Settings** → **Checkout & Redirection** to configure the post-checkout redirection URL.
* Go to **Settings** → **Webhooks** to add the webhook endpoint created for your application.

Use the exact URLs and events that Command Code reports for your implementation.

## Test the Integration[​](#test-the-integration "Direct link to Test the Integration")

Command Code should adapt the Freemius integration to your application's existing structure. Verify that it created or updated the following features:

1. **Pricing Table**: A pricing experience that displays the plans, prices, billing cycles, and features configured for your Freemius product.

   ![Freemius pricing table with subscription and one-time purchase options](/help/assets/ideal-img/freemius-pricing-table.6c69dbd.480.png)

2. **Checkout**: A purchase flow that opens Freemius Checkout with the selected plan and returns the user to your application after a successful purchase.

   ![Freemius checkout flow for subscription purchase](/help/assets/ideal-img/freemius-checkout.3ede917.480.png)

3. **Entitlements and Paywalls**: Backend and frontend checks that protect premium features, show a paywall to users without access, and grant access after the appropriate entitlement is received.

   ![Application paywall UI for controlling premium feature access](/help/assets/ideal-img/freemius-paywall-ui.4f8ba0f.480.png)

4. **Account Page and Customer Portal**: An added or updated account area that displays relevant subscription or purchase information and gives users access to the Freemius Customer Portal.

   ![Integrated customer portal for subscription and billing management](/help/assets/ideal-img/freemius-integrated-customer-portal.6e7c546.480.png)

Test these features with users who have and do not have active entitlements. Also verify that checkout redirection and webhook events update access and account information correctly.

## Troubleshooting and Updates[​](#troubleshooting-and-updates "Direct link to Troubleshooting and Updates")

If the integration does not work as expected, describe the observed and expected behavior and ask Command Code to use the `freemius-troubleshooting` skill. Before troubleshooting, update the installed skills:

```
npx skills update -y
```

For more information, examples, and best practices, see the [Freemius Skills documentation](https://freemius.com/help/help/documentation/ai/skills/.md).
