Commet
  • Pricing
Log InTry out
Introduction

Quickstart

Integrate with Java

Learn

Resources

SDK ReferenceError HandlingTestingCLI

Plugins

Better Auth
DocumentationKnowledge BaseBuild with AIAPI ReferenceWebhooks

Integrate with Java

Install and configure the Commet Java SDK.

Install

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

Configure

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

public class CommetClient {

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

Create Customer and Subscribe

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

import co.commet.ApiResponse;
import java.util.Map;

commet.customers().create("user@example.com", "user_123");

ApiResponse subscription = commet.subscriptions().create(
        null, "user_123", "pro",
        null, null, null, null, null, null, null, null
);

Map<String, Object> data = (Map<String, Object>) subscription.getData();
String checkoutUrl = (String) data.get("checkout_url");

The customer is redirected to checkout to complete payment.

Check Access

ApiResponse sub = commet.subscriptions().get("user_123");
Map<String, Object> subData = (Map<String, Object>) sub.getData();
String status = (String) subData.get("status");

ApiResponse access = commet.features().check("custom_branding", "user_123");
Map<String, Object> accessData = (Map<String, Object>) access.getData();
boolean allowed = (boolean) accessData.get("allowed");

Track Usage

commet.usage().track(
        "api_calls", null, "user_123",
        1, null, null, null, null, null, null, null, null
);

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