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:

KeyTypeDefaultDescription
secretKeystring@stripe-secret-keyYour 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:

KeyTypeDefaultDescription
customerToken*stringA customer token (returned from creating a customer)
items*object[]An array of objects specifying one or more subscription plans.
planstringThe plan ID (from Stripe).
quantitynumberQuantity for this item.
metadataobjectMetadata for this item.
couponstringA coupon code to apply to this subscription.
metadataobjectMetadata 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:

KeyTypeDescription
idstringA unique identifier for the customer.
subscriptionStatusstringThe status of the Stripe subscription.

Sandbox Limits

Only Stripe test keys are permitted on the Sandbox plan. Upgrade to production to use live keys.