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).
Prerequisite: Creating subjects
Section titled “Prerequisite: Creating subjects”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",)- Go to the subjects page and click “New Subject”.
- Fill in the form with the following values:
- Name:
John Doe - Email:
john.doe@example.com - (Optional) External ID:
customer_id_from_your_system
- Name:
- Click “Save”.
Creating subscriptions
Section titled “Creating subscriptions”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", },)- Go to the subjects page and click on the subject you want to subscribe to a rate card.
- Click on the “Subscriptions” tab.
- Click “New Subscription”.
- Select the rate card you want to subscribe to from the dropdown.
- Click “Save”.
Fetching subscriptions
Section titled “Fetching subscriptions”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]- Go to the subscriptions page.
- Filter by subject ID:
customer_id_from_your_system. - You should see a subscription with status
active.
Managing subscriptions
Section titled “Managing subscriptions”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.