Skip to main content

Subscription API

The client application works with subscriptions through three endpoints: subscribe, cancel a subscription, and get the current user's active subscriptions.

All endpoints run on behalf of an authorized user. A subscription is always linked to the token used for the request.

Subscribe​

Creates a new subscription for the current user to the specified marker.

The behavior depends on the type of payment account linked to the subscription in the module settings (opens in a new tab):

  • stripe, midtrans: creates a subscription record and returns a payment link. The subscription becomes active after the provider successfully charges the payment.
  • custom: creates the subscription, which is active immediately. No payment link is returned. An administrator records the payment manually in the user card (opens in a new tab).

Cancel a subscription​

Cancels the user's active subscription immediately.

The behavior depends on the type of payment account:

  • stripe, midtrans: the subscription is canceled through the provider's API. Automatic charges stop, and the subscription status changes to canceled.
  • custom: cancellation through the API is not available. Only an administrator can cancel these subscriptions, in the user card (opens in a new tab).
info

Trying to cancel a custom subscription through the API returns an error. This is intentional: an administrator manages manual subscriptions because their payments are made outside the system.

Get active subscriptions​

Returns an array of markers of the current user's active subscriptions.

A subscription is active if:

  • It was created successfully.
  • Its current period has not expired.
  • It has not been canceled (canceled).

When a subscription expires or is canceled, its marker is removed from the list automatically. You can use this endpoint on the client to check access to content: if the array contains the marker of the required subscription, access is granted.