• Pricing
  • Blog
Log inBook a demo
Introduction

Quickstart

Create an API KeyChoose a Billing Model
Integrate with Java

Learn

Resources

SDK ReferenceAPI VersioningError HandlingTestingCLIExamples

Plugins

Better Auth
System status
DocumentationKnowledge BaseBuild with AIAPI ReferenceWebhooks

Integrate with Java

Install and configure the Commet Java SDK.

Install the Commet Skill so your coding agent can integrate the current SDK and verify its work against the live API contract.

npx skills add commet-labs/skills --skill commet

Install

pom.xml
<dependency>
    <groupId>co.commet</groupId>
    <artifactId>commet-java</artifactId>
    <version>8.0.0</version>
</dependency>
build.gradle.kts
implementation("co.commet:commet-java:9.0.0")

Configure

.env
COMMET_API_KEY=ck_sandbox_xxx
CommetClient.java
import co.commet.Commet;

public class CommetClient {

    public static final Commet commet = Commet.builder()
            .apiKey(System.getenv("COMMET_API_KEY"))
            .build();
}

There is no environment option on the client: sandbox vs live is decided by the organization the API key belongs to.

Create Customer and Subscribe

customers().create is idempotent — if a customer with the same id already exists, it returns the existing record.

import co.commet.params.CreateCustomerParams;
import co.commet.params.CreateSubscriptionParams;

commet.customers().create(
    CreateCustomerParams.builder("user@example.com")
        .id("user_123")
        .build()
);

var subscription = commet.subscriptions().create(
    CreateSubscriptionParams.builder("user_123")
        .planCode("pro")
        .build()
);

String checkoutUrl = subscription.checkoutUrl();

The customer is redirected to checkout to complete payment.

Check Access

import co.commet.models.FeatureAccess;
import co.commet.models.Subscription;
import co.commet.models.SubscriptionStatus;
import co.commet.params.GetActiveSubscriptionParams;
import co.commet.params.GetFeatureAccessParams;

Subscription sub = commet.subscriptions().getActive(
    GetActiveSubscriptionParams.builder("user_123").build()
);
SubscriptionStatus status = sub != null ? sub.status() : null;

FeatureAccess access = commet.featureAccess()
        .get("custom_branding", GetFeatureAccessParams.builder("user_123").build());
boolean allowed = access.allowed();

Track Usage

import co.commet.params.TrackUsageParams;

commet.usage().track(
    TrackUsageParams.builder("api_calls", "user_123")
        .value(1.0)
        .build()
);

Usage is aggregated and billed at end of period.

Webhooks

import co.commet.resources.Webhooks;
import java.util.Map;

Webhooks webhooks = new Webhooks();

Map<String, Object> payload = webhooks.verifyAndParse(
        rawBody, signature, webhookSecret
);

if (payload == null) {
    // return 401
}

if ("subscription.activated".equals(payload.get("event"))) {
    // handle activation
}

Related

  • SDK Reference

How is this guide?

Integrate with Django

Add billing and payments to your Django application.

Integrate with Go

Add billing and payments to your Go application using net/http.

On this page

Install
Configure
Create Customer and Subscribe
Check Access
Track Usage
Webhooks
Related