Firsty

Search...

Search...

Core concepts

Subscriptions

Bundle data plans into a plan that renews, and run it on a customer's eSIM.

Sell your customers a plan that renews on its own. A subscription gives them fresh data every month, on the eSIM they already have: no new order, no reinstall. You choose what goes in it, Firsty renews it on schedule and tells you with a webhook, and you bill your customer your way.

  • Renews by itself. Each period starts with fresh packages of every plan in the subscription.
  • Up to five plans in one. Combine plans from your catalogue into one offer.
  • Changes without a reinstall. Upgrade, downgrade, pause, resume or end it, straight away or at the end of the period.
  • Starts when your customer is ready. Once their eSIM is live, even when that waits for their number to move over.

How it works

A subscription plan is your offer: up to five plans and how often they renew. A subscription runs that offer on one of a profile's eSIMs. Every period it orders a fresh package of each plan, and ends the previous period's packages.

Subscription plans

You create your own subscription plans, from the package plans in your catalogue:

POST /subscription-plans
requests.post(
    "https://connect.test.firsty.app/api/v3/subscription-plans",
    headers={
      "Authorization": "Bearer YOUR_ACCESS_TOKEN",
      "Content-Type": "application/json",
      "X-Idempotency-Key": "<x-idempotency-key>"
    },
    json={
      "name": "50GB every 30 days",
      "includedPlanReferences": [
        "SG050GB030DGLN"
      ],
      "renewal": {
        "unit": "day",
        "count": 30
      }
    }
)

renewal is a month, or 4 to 30 days. Each plan in it must last at least one renewal period. Store subscriptionPlanReference exactly as returned.

You wantCall
Your plansList subscription plans
One plan with its included package plansGet subscription plan
To rename a plan or change what it includesUpdate subscription plan

includedPlanReferences is always the whole set, so an update replaces it. Each update raises the plan's revision. Subscriptions on the plan pick up the new set at their next renewal; the current period keeps its packages and what is left of them.

renewal can't change. For a different cadence, create a new plan, terminate the subscription, and start a new one once subscription.terminated arrives.

Starting a subscription

POST /profiles/{profileReference}/subscriptions
requests.post(
    "https://connect.test.firsty.app/api/v3/profiles/{profileReference}/subscriptions",
    headers={
      "Authorization": "Bearer YOUR_ACCESS_TOKEN",
      "Content-Type": "application/json",
      "X-Idempotency-Key": "<x-idempotency-key>"
    },
    json={
      "subscriptionPlanReference": "SP12345678",
      "esimReference": "123456000000000001"
    }
)

A profile has one subscription at a time that isn't terminated. The eSIM must be preactive or active: a suspended one answers 409 esim_suspended, any other 409 invalid_state_transition. To subscribe a new customer in one call, pass subscription when you order the eSIM.

A new subscription is pending, with no period and no packages, and subscription.created confirms it. It starts once the eSIM has network service: usually right away, later when the eSIM waits for activation or a port-in. A pending subscription never expires. subscription.activated reports the start, with the first period and the packages it ordered in packageChanges.created. Each of those packages then sends its own package.created and package.activated.

Periods and renewal

The start fixes the renewal schedule, in UTC. nextRenewalAt is the next boundary and currentPeriod the period running now. At each renewal the previous period's packages end, with reason subscription_renewal on package.ended, and fresh ones start from the plan's latest revision. Unused allowance doesn't carry over, and subscription.renewed follows.

Let subscription.renewed open each new billing period on your side, rather than a clock of your own. A subscription that is suspended doesn't renew, so a clock of your own would bill a customer who has no service.

A subscription's packages show on the eSIM like any other, with a subscription object naming the subscription and period. Their life follows the subscription, so you can't remove one yourself.

Subscription status

statusMeaningWebhook
pendingAccepted, waiting for the eSIM's network service.subscription.created
activeRunning: a current period and its packages.subscription.activated, subscription.resumed
suspendedPaused. Doesn't renew, and nextRenewalAt is null.subscription.suspended
terminatedEnded for good.subscription.terminated

Every subscription event carries the subscription's status, its current period once it has started, and the packages the change created and removed in packageChanges. Handle them as any webhook: at least once, keyed on webhook-id.

Suspending, resuming and terminating

Every change is an action:

POST /profiles/{profileReference}/subscriptions/{subscriptionReference}/actions
requests.post(
    "https://connect.test.firsty.app/api/v3/profiles/{profileReference}/subscriptions/{subscriptionReference}/actions",
    headers={
      "Authorization": "Bearer YOUR_ACCESS_TOKEN",
      "Content-Type": "application/json",
      "X-Idempotency-Key": "<x-idempotency-key>"
    },
    json={
      "action": "suspend",
      "when": "period_end"
    }
)

action is suspend, resume, terminate or change_plan. when is now, period_end or a timestamp with a timezone. The call answers 202 once it accepts the action, even with now; the webhook reports when it is done. A pending subscription takes only terminate with now, which cancels it at once and answers 200.

Actions queue up in scheduledActions, in the order they take effect, so you can suspend at the end of the period and resume on a later date in one go. Schedule an action at least 24 hours before a pending termination, and a termination at least 24 hours after the action before it. Termination ends the packages, with reason subscription_cancellation, and drops whatever is still scheduled.

Suspending ends the period's packages, with reason subscription_suspension. Resuming starts fresh packages with the plan's full allowance: for the rest of the current period, or, once that period has ended, for the period current at the resume. Either way it sends subscription.resumed, not subscription.renewed.

Changed your mind? Cancel a scheduled action before it runs. An action that already ran answers 409.

DELETE /profiles/{profileReference}/subscriptions/{subscriptionReference}/scheduled-actions/{actionReference}
requests.delete(
    "https://connect.test.firsty.app/api/v3/profiles/{profileReference}/subscriptions/{subscriptionReference}/scheduled-actions/{actionReference}",
    headers={
      "Authorization": "Bearer YOUR_ACCESS_TOKEN",
      "X-Idempotency-Key": "<x-idempotency-key>"
    }
)

When the eSIM changes

The subscription follows its eSIM's lifecycle:

eSIMSubscription
SuspendedSuspended, with subscription.suspended. A pending one stays pending.
ReactivatedStays suspended. Resume it yourself once the eSIM is active.
TerminatedTerminated, with subscription.terminated.

Keep your own records in step from the subscription.* webhooks, not from the calls you made: a suspension you didn't ask the subscription for still arrives as subscription.suspended.

Changing plan

change_plan moves the subscription to another of your subscription plans with the same renewal, named in subscriptionPlanReference.

The current period ends, its packages with reason subscription_cancellation, and a new one starts on the new plan, running to the original renewal boundary. The subscription keeps its reference, status and other scheduled actions. subscription.plan.changed carries previousSubscriptionPlanReference. One plan change can be scheduled at a time; cancel it to schedule another.

With period_end, the switch lands on the renewal, so a period your customer already paid for keeps the plan they paid for. Bill the new plan from the period that starts there. With now, the customer gets the new plan's packages straight away, and what was left of the old ones ends.

Following a subscription

You wantCall
A profile's subscriptions, current and pastList subscriptions
One subscription, with its period and scheduled actionsGet subscription
GET /profiles/{profileReference}/subscriptions/{subscriptionReference}
requests.get(
    "https://connect.test.firsty.app/api/v3/profiles/{profileReference}/subscriptions/{subscriptionReference}",
    headers={
      "Authorization": "Bearer YOUR_ACCESS_TOKEN"
    }
)