Skip to content
Join our SlackContact usGet started

Subscribing customers

Learn how to subscribe customers to a rate card.

You can subscribe a customer to a rate card in the dashboard or using the API (either directly or via a checkout flow).

Every customer you want to subscribe to a rate card should be represented by a subject. You should create these subjects every time a new customer signs up for your service.

subject = lark_client.subjects.create(
external_id="customer_id_from_your_system",
name="John Doe",
email="john.doe@example.com",
)

You can create a subscription for a subject to a rate card using the API or the dashboard. The response will either be a subscription object or a checkout URL.

  • If the subject does not have a payment method on file, the response will provide a checkout URL to redirect the customer to.
  • If the subject has a payment method on file, the subscription will be created immediately unless create_checkout_session='always' is specified in the request.
subscription = lark_client.subscriptions.create(
subject_id="customer_id_from_your_system",
rate_card_id="RATE_CARD_ID",
checkout_callback_urls={
"success_url": "https://example.com/success",
"cancelled_url": "https://example.com/cancelled",
},
)

If you query subscriptions for the subject, you should now see a subscription with status active.

subscriptions = lark_client.subscriptions.list(
subject_id="customer_id_from_your_system"
)
subscription = subscriptions.subscriptions[0]

You can redirect customers to the hosted customer portal to manage their subscriptions.

customer_portal_session = lark_client.customer_portal.create_session(
subject_id="customer_id_from_your_system",
return_url="https://example.com/return",
)

You should then redirect the customer to the customer_portal_session.url.

You can also cancel a subscription using the API or the dashboard.