createSubscription
Creates a subscription for a customer in Stripe. Under the hood, this action calls the create a subscription API endpoint.
Configuration
This function type accepts the following parameters:
Key | Type | Default | Description |
---|---|---|---|
secretKey | string | @stripe-secret-key | Your Stripe secret key |
Run the following command to add your Stripe secret key:
statickit secrets add stripe-secret-key <your-secret-key> -k <your-deploy-key>
Example
{"functions": {"createSubscription": {"app": "stripe","type": "createSubscription"}}}
Arguments
This function type accepts the following client-side arguments when called:
Key | Type | Default | Description |
---|---|---|---|
customerToken * | string | A customer token (returned from creating a customer) | |
items * | object[] | An array of objects specifying one or more subscription plans. | |
↳ plan | string | The plan ID (from Stripe). | |
↳ quantity | number | Quantity for this item. | |
↳ metadata | object | Metadata for this item. | |
coupon | string | A coupon code to apply to this subscription. | |
metadata | object | Metadata for this subscription. |
Example
import {createClient,createCustomer,createSubscription} from '@statickit/functions';let client = createClient({ site: '{your-site-id}' });let { customerToken } = await createCustomer(client, {});let { status } = await createSubscription(client, {customerToken,items: [{ plan: "plan_XXXXX" }]});
Response
Returns a status
and the following properties when successful:
Key | Type | Description |
---|---|---|
id | string | A unique identifier for the customer. |
subscriptionStatus | string | The status of the Stripe subscription. |
Sandbox Limits
Only Stripe test keys are permitted on the Sandbox plan. Upgrade to production to use live keys.