> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Provisioning subscriptions

## Overview

In this quick start guide, we'll demonstrate how to provision subscriptions in Stigg.

**Subscriptions** should be provisioned in Stigg when your customers upgrade or downgrade to a new plan (free, paid, trial, etc.).

When provisioning of a paid subscription is attempted, Stigg is integrated with a billing solution and payment details have not been previously provided by the customer, Stigg will auto-magically redirect customers to a the billing solution's checkout page. After the customer enters the required payment details in the presented checkout page, the relevant subscription will be created in both Stigg and the billing solution.

When no payment is required or when Stigg is not integrated with a billing solution, the subscription will be immediately created in Stigg.

## Before we begin

In order to complete this guide in your application code, please make sure that you have:

* [Modeled your pricing in Stigg](/documentation/modeling-your-pricing-in-stigg/overview)
* [Installed the Stigg Node.js server SDK](/api-and-sdks/integration/backend/nodejs#installing-the-sdk)
* [A Stigg **full access** key](/api-and-sdks/integration/backend/nodejs#retrieving-the-full-access-key)
* [Provisioned a customer](./provisioning-customers)

## Initializing the server SDK

The first step is to initialize Stigg's server SDK with the full access key of the environment that's integrated with Stigg:

```typescript TypeScript theme={null}
import Stigg from '@stigg/node-server-sdk';

const stiggClient = await Stigg.initialize({ apiKey: 'YOUR_FULL_ACCESS_KEY' });

export default stiggClient;
```

<Warning>
  The Stigg SDK instance has an internal cache and supports retries for certain API calls on network errors. In general, you should initialize it once per process (for example: using a singleton design-pattern) and use the same instance throughout the codebase.
</Warning>

## Provisioning a subscription

When a customer subscribes to a new plan (free, paid, trial, etc.), provision a subscription in Stigg. The provision result can be a successfully created subscription, or a redirect link to checkout page of the integrated billing solution in case payment details are required in order to provision the subscription.

```typescript TypeScript theme={null}
const subscription = await stiggClient.provisionSubscription({  
    customerId: 'customer-demo-01',  
    planId: 'plan-basic',  
    addons: [{  // optional
        addonId: 'addon-extra-stuff',  
        quantity: 1,  
    }],  
    startDate: new Date(), // optional
    id: 'subscription-plan-basic',  // optional
    billingPeriod: 'MONTHLY', // optional, relevant only for paid subscriptions  
    unitQuantity: 2, // optional, relevant for subscriptions with per-unit pricing  
    billingInformation: {  // optional
    taxRateIds: [  
      "txr_1LcTSRE1gVT2zwZV07MIRKdf",  
      "txr_1LcTSRE1gVT2zwZV07MIRKdf"  
        ],  
    },
    checkoutOptions: { // optional
        successUrl: "https://your-success-url.com",
        cancelUrl: "https://your-cancel-url.com",
        allowPromoCodes: true, // optional, pass this parameter to allow customer to use promo codes on checkout
        collectBillingAddress: true // optional, pass this parameter to collect billing address for invoice on checkout
    },
    metadata: { // optional
      key: 'value',  
    },
});
```

## Additional resources

<Card title="REST API: Create Subscription" href="/api-and-sdks/api-reference/rest/subscriptions-create" icon="server" horizontal />

<Card title="REST SDKs" href="/api-and-sdks/references/sdk/backend/rest/index" icon="code" horizontal />

<Card title="Node.js SDK: Provisioning Subscriptions (Legacy)" href="/api-and-sdks/integration/backend/nodejs#provisioning-subscriptions" icon="code" horizontal />

## Decision flow

<img src="https://mintcdn.com/stigg/imNqv5Llzt3VPpq8/images/6998840-image.png?fit=max&auto=format&n=imNqv5Llzt3VPpq8&q=85&s=a6de269cbdf29b2bcd0a07199baa80f0" alt="" width="965" height="1039" data-path="images/6998840-image.png" />
