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

# Subscriptions Quickstart

> Getting started with the Customers and Subscriptions API

## Prerequisites

Before you begin managing customers and subscriptions, ensure you have:

<CardGroup cols={2}>
  <Card title="Account & Access" icon="user-shield">
    * A StateSet account ([Sign up here](https://StateSet.com/sign-up))
    * API credentials from the [StateSet Dashboard](https://app.StateSet.com/settings/api-keys)
    * Subscription management enabled in your workspace
  </Card>

  <Card title="Payment Processing" icon="credit-card">
    * Stripe account and API keys (for payment processing)
    * Understanding of subscription billing models
    * PCI compliance considerations (if handling payment data)
  </Card>
</CardGroup>

<CardGroup cols={2}>
  <Card title="Technical Setup" icon="code">
    * Node.js 16+ installed
    * Basic understanding of REST APIs and JavaScript
    * Familiarity with GraphQL (optional but recommended)
  </Card>

  <Card title="Data Migration" icon="database">
    * Access to your existing customer database (if migrating)
    * Customer data mapped to StateSet schema
    * Data validation and cleanup completed
  </Card>
</CardGroup>

## Overview

StateSet One provides a REST and GraphQL API for Subscription Lifecycle Management. These objects typically encompass:

* Customers
* Subscription
* Subscription Items

### Customer Management Overview

The Customer Management API provides a set of endpoints for managing customers. These endpoints allow you to create, update, and delete customers. You can also retrieve information about customers and their subscriptions.

### Customer Management Challenges

Customer Management is a complex process that requires a lot of time and effort. It involves managing customer data, subscriptions, and payments. The process is often manual and error-prone, which can lead to customer dissatisfaction and lost revenue.

### StateSet's Customer Management Solutions

StateSet's Customer Management solutions are designed to help you manage your customers more efficiently. Our solutions include:

* Customer Data Management
* Subscription Lifecycle Management
* Recurring Billing Processing via Stripe

### Quickstart Guide

1. Setup your company's StateSet One instance by signing up at <a href="https://StateSet.com/sign-up">StateSet.com/sign-up</a>

2. Create a new API key in the StateSet Cloud Console <a href="https://cloud.StateSet.com/api-keys">cloud.StateSet.com/api-keys</a>

3. Install the StateSet-node SDK in your project:

```jsx theme={null}
npm install StateSet-node
```

4. Create a new Customer

```jsx javascript theme={null}

import { StateSet } from 'StateSet-node'('API_KEY');

const customer = await StateSet.customers.create({
  customer: {
    email: 'customer@gmail.com'
    first_name: 'John',
    last_name: 'Doe',
    phone: '555-555-5555',
    stripe_customer_id: null,
    address: {
      line1: '123 Main St',
      city: 'San Francisco',
      state: 'CA',
      postal_code: '94111',
      country: 'US'
    }
    }
});

```

5. Create a new Subscription in Stripe and Update the StateSet Customer Record with the Stripe Customer Id

```jsx javascript theme={null}

import { stripe } from 'stripe-node'('API_KEY');
import { StateSet } from 'StateSet-node'('API_KEY');

const subscription = await stripe.subscriptions.create({
  subscription: {
    customer_id: customer.id,
    plan_id: 'plan_123',
    payment_method_id: 'pm_123'
  }
});

  // If the User doesn't already Exist in Stripe
  if (!existing_customer) {

      // Create the Stripe Customer
      var name = '';

      if (customer.firstName != null) {
        name = customer.firstName;
      };

      if (customer.lastName != null) {
        if (name != '') {
          name = name + ' ' + customer.lastName;
        } else {
          name = customer.lastName;
        }
      };

      if (name.trim() == '') {
        name = '-';
      };

      const stripe_customer = await stripe.customers.create({
        name: name,
        email: customer.email,
        metadata: { "sso": sso_id } // Adding sso to metadata
      });


      // Update Customer
      const StateSet_customer = await StateSet.customers.update({
        sso_id: sso_id,
        customer: {
          stripe_customer_id: stripe_customer.id,
          temporary_subscription_plan: null
        }
      });
  }
```

### UCP

The Unified Customer Profile (UCP) is a powerful system developed by StateSet that allows Direct-to-Consumer (DTC) brands to manage customer data and integrate it with various systems of record, including Stripe. By leveraging customer records and Stripe customer IDs, StateSet enables seamless integration and synchronization between systems using Remote Data Joins.
UCP provides functionality to create unique customer profiles, eliminate duplicate profiles, and update customer information. This documentation provides an overview of the key features and capabilities of UCP, along with instructions on how to use it effectively.

1. Customer Profile Management
   UCP enables the creation and management of unique customer profiles across multiple systems of record. By utilizing a single UUID, StateSet ensures that customer data remains consistent and synchronized throughout different platforms.

2. Stripe Integration
   UCP integrates with Stripe, a popular payment processing platform, allowing brands to leverage its capabilities for subscription management. The integration is achieved through Remote Data Joins, enabling seamless data exchange and synchronization between StateSet and Stripe.

3. Duplicate Profile Detection and Elimination
   StateSet's UCP includes built-in functionality to identify and eliminate duplicate customer profiles. This feature ensures data integrity and prevents redundant records within the system.

4. Automated Actions Based on User Existence
   UCP has the ability to check for the existence of users in other systems of record and perform automated actions based on the results. For instance, if a user does not exist in the system, UCP can create the user in Stripe, assign a Stripe Customer ID, and use the StateSet SDK to update the user's information.

### StateSet and Stripe

StateSet provides a Stripe GraphQL server for remote data joins with Hasura. This allows you to query Stripe data directly from your GraphQL API.

```jsx graphql theme={null}

query getCustomer($sso_id: uuid!) {
  customers: customers_by_pk(sso_id: $sso_id) {
    sso_id
    firstName
    lastName
    email
    stripe_customer_id
    activationDate
    delinquency_date
    plan_change_date
    returns {
      id
      action_needed
      amount
      condition
      created_date
      description
      issue
      reason_category
      refunded_date
    }
    warranties {
      id
      action_needed
      amount
      condition
      created_date
      description
      issue
      reason_category
    }
    stripe_data {
      id
      metadata
      subscriptions {
        data {
          id
          metadata
          status
          created
          cancelAt
          currentPeriodStart
          currentPeriodEnd
          plan {
            id
            metadata
            nickname
            created
          }
          items {
            data {
              id
              metadata
              price {
                id
                nickname
                unitAmount
                recurring {
                  aggregateUsage
                  usageType
                }
              }
            }
          }
        }
      }
    }
  }
}

```

### Unified Customer Profile

UCP empowers DTC brands by providing a unified and streamlined approach to managing customer profiles. Through integration with Stripe and the use of Remote Data Joins, UCP ensures data consistency, eliminates duplicate profiles, and enables efficient customer data management.
By following the documentation and guidelines provided by StateSet, you can effectively leverage UCP's features.

### Subscriptions Support

If you have any questions or need help, please contact us at: [support@StateSet.com](mailto:support@StateSet.com)
