ElebneElebneDocs
SDKs

Java SDK

Server-side Java SDK for Elebne Pay — mint client secrets, retrieve/cancel/refund intents, and verify webhooks. Java 17, zero runtime dependencies.

Java SDK

ai.elebne:pay-java is the server SDK for Elebne Pay — the JVM counterpart to stripe-java. It mints the clientSecret that the client SDKs (React, React Native, Flutter) consume, builds the hosted embed URL, and verifies webhooks. Java 17, no runtime dependencies (JDK HttpClient + a hand-rolled JSON codec).

Install

dependencies {
    implementation 'ai.elebne:pay-java:0.1.0'
}
<dependency>
  <groupId>ai.elebne</groupId>
  <artifactId>pay-java</artifactId>
  <version>0.1.0</version>
</dependency>

ai.elebne:pay-java is not yet on Maven Central. It is available via the Elebne private Maven registry — request access and repository coordinates from dev@elebne.ai.

Configure

Construct a client with your secret key and environment. Env selects the API base URL preset (PRODUCTIONhttps://api.elebne.ai/api/v1, STAGINGhttps://api.staging.elebne.ai/api/v1).

import ai.elebne.pay.*;

// Production
ElebneClient elebne = new ElebneClient(new ElebneConfig("sk_live_…", Env.PRODUCTION));

// Staging
ElebneClient staging = new ElebneClient(new ElebneConfig("sk_test_…", Env.STAGING));

Keep sk_ on the server

sk_ keys can create, cancel, and refund payments. They must never reach the browser or a mobile app — that is what the client SDKs and clientSecret are for.

A sk_test_ key produces sandbox intents (no real money); a sk_live_ key produces real payments. There is no separate sandbox hostname — the key decides.

Flow A — mint an intent and hand off the clientSecret

import ai.elebne.pay.*;
import java.util.Map;

ElebneClient elebne = new ElebneClient(new ElebneConfig("sk_live_…", Env.PRODUCTION));

PaymentIntent intent = elebne.intents().create(Map.of(
    "amount", 150000,               // centimes → 1 500.00 MRU
    "label", "Commande #12345",
    "merchantOrderId", "ORDER-12345",
    "success_url", "https://shop.example/success",
    "cancel_url", "https://shop.example/cart"
));

String clientSecret = intent.clientSecret();          // give this to your frontend
String url = EmbedUrl.build("https://elebne.ai/embed", clientSecret);
// Staging: EmbedUrl.build("https://pay.staging.elebne.ai/embed", clientSecret);

Retrieve, cancel, refund

elebne.intents().retrieve("PI-30…");
elebne.intents().cancel("PI-30…");

// Partial refund of 500.00 MRU with a reason
elebne.intents().refund("PI-30…", 50000, "SERVICE_NOT_DELIVERED");

Flow B / Flow C — publishable key

ElebneClient pk = new ElebneClient(new ElebneConfig("pk_live_…"));

// Flow B — stored price defined in the dashboard
pk.intents().createCheckoutSession(Map.of("priceId", "abc123", "quantity", 2));

// Flow C — verify against your own order reference
pk.intents().createPkIntent(Map.of("merchantOrderId", "ORDER-1"));

Verify webhooks

verifyAndParse checks the HMAC-SHA256 signature (constant-time) and rejects timestamp drift, then returns the parsed event. On a bad signature it throws SignatureVerificationException — respond 401.

import ai.elebne.pay.*;
import ai.elebne.pay.exception.SignatureVerificationException;

try {
    WebhookEvent event = new Webhooks().verifyAndParse(
        rawBody,
        request.getHeader("X-Elebne-Signature"),
        Long.parseLong(request.getHeader("X-Elebne-Timestamp")),
        System.getenv("ELEBNE_WEBHOOK_SECRET"));

    // event.event()                        e.g. "payment.confirmed"
    // event.data().get("referenceNumber")  e.g. "PI-30XXXXXXXXXXXXXX"
    response.setStatus(200);
} catch (SignatureVerificationException e) {
    response.setStatus(401);
}

The signature scheme (header X-Elebne-Signature: sha256=<hex>, signed content "{timestamp}.{rawBody}", HMAC-SHA256) is the same one documented in full at Webhooks.

Error handling

API calls throw ai.elebne.pay.exception.ApiException with errorCode() and httpStatus(). Catch it around create / refund and inspect the code.

Next steps

  • React SDK — consume the clientSecret on the web
  • PHP SDK — the same server SDK for PHP
  • Webhooks — full signature and retry contract
  • Pay API — the REST endpoints this SDK wraps

Was this page helpful?

On this page