Skip to content

About

Official Java SDK for the Payzum crypto payment API — exact decimals, signed webhooks, zero runtime dependencies.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Payzum — official Java SDK

Non-custodial crypto and stablecoin payments for JVM applications. The SDK owns the four things that break payment integrations: webhook signature verification, exact decimal amounts, the retry policy, and the status vocabulary.

Docs · https://merchant.payzum.com/docs
Site · https://payzum.com
Agent index · https://merchant.payzum.com/llms.txt

<dependency>
  <groupId>io.github.payzum-hq</groupId>
  <artifactId>payzum-java</artifactId>
  <version>0.1.0</version>
</dependency>

Java 11 or newer, because that is where java.net.http lands. Zero runtime dependencies: the SDK ships its own JSON reader and writer, so importing it does not drag a serializer into a merchant's dependency graph.

Charge a customer

PayzumClient client = new PayzumClient(System.getenv("PAYZUM_API_KEY"));

Payment invoice = client.payments().create(new PaymentsResource.CreatePaymentParams()
        .priceAmount("49.99")            // string: nothing is rounded on the way in
        .priceCurrency("usd")
        .payCurrency("all")              // the buyer picks the coin on the checkout
        .orderId("ORDER-12345")
        .ipnCallbackUrl("https://shop.example/webhooks/payzum")
        .successUrl("https://shop.example/thanks")
        .cancelUrl("https://shop.example/cart")
        .idempotencyKey("ORDER-12345"));

response.sendRedirect(invoice.invoiceUrl());

Always send an idempotencyKey: without one the SDK refuses to retry a create, because a blind retry can mint a second real invoice and charge twice.

A 201 with no checkout URL throws PayzumMissingInvoiceUrlException carrying the paymentId, so the draft can still be read.

Get notified when it's paid

@PostMapping("/webhooks/payzum")
public ResponseEntity<String> webhook(HttpServletRequest request) {
    // Cap the unauthenticated body before reading it.
    byte[] raw = readAtMost(request, 1 << 20);

    Map<String, String> headers = Collections.list(request.getHeaderNames()).stream()
            .collect(Collectors.toMap(name -> name, request::getHeader));

    WebhookVerifier verifier = PayzumClient.webhooks(System.getenv("PAYZUM_WEBHOOK_SECRET"));

    Map<String, Object> payload;
    try {
        payload = verifier.verifyPaymentIpn(new String(raw, UTF_8), headers, null); // RAW bytes
    } catch (PayzumSignatureException error) {
        int status = PayzumSignatureException.MALFORMED_PAYLOAD.equals(error.reason()) ? 400 : 401;
        return ResponseEntity.status(status).body(error.reason());
    }

    // Deduplicate on the id INSIDE the signed body, never on the header: the
    // header is not covered by the HMAC.
    String eventId = WebhookVerifier.eventIdFromPayload(payload);
    if (alreadyApplied(eventId)) {
        return ResponseEntity.ok("duplicate");
    }

    PaymentStatus status = PaymentStatus.fromMerchant((String) payload.get("payment_status"));
    if (status.isPaid()) {
        fulfil((String) payload.get("order_id"));
    }

    return ResponseEntity.ok("ok");
}

The order is fulfilled from the signed notification, never from the buyer's return. A closed tab must not lose a paid order.

Statuses

Merchant (payment_status) Buyer (status)
waiting pending
partially_paid partial
finished paid, overpaid
expired expired
failed cancelled

PaymentStatus.fromMerchant and fromBuyer throw PayzumUnknownStatusException for anything else instead of guessing — a new value from the API must never be treated as paid. Payment.status() returns null for an unknown value, which is the safe default.

Five IPN event types exist, two of them security-relevant: wrong_token_received and suspicious_token_received.

Errors

Branch on the code, never on the message.

try {
    client.payments().get("pzi_…");
} catch (PayzumApiException error) {
    if (ErrorCodes.PAYMENT_NOT_FOUND.equals(error.code())) {
        return notFound();
    }
    if (error.isRetryable()) {
        return retryLater();
    }
    throw error;
} catch (PayzumTransportException error) {
    // No HTTP response at all: DNS, TLS, timeout, reset. The server's state is
    // unknown, so a create is not retried after one unless it carried a key.
}

Exactly three of the sixteen codes are retryable, and QUOTA_EXCEEDED — which arrives as a 429 — is deliberately not one of them: too many invoices are open, so retrying makes it worse.

payments().list(...) validates limit (1–100), page, sortBy and orderBy locally, because the server silently falls back to created_at for anything it does not recognise.

Amounts are exact

Every monetary field decodes to its exact source text, never a double or a BigDecimal:

Payment invoice = client.payments().get("pzi_…");
invoice.priceAmount(); // "0.123456789012345678"

The reader keeps each number as the literal text between separators, and the writer validates the literal against a strict grammar before emitting it unquoted, so NaN, Infinity, 1_000 and hex floats are rejected before anything is sent.

The buyer surface is the exact source for a settled amount:

BuyerInvoice status = client.invoices().status("pzi_…");
status.payAmount();
status.amountReceived();

The ceiling worth knowing: the gateway casts to double before serialising, so the merchant surface may already have lost digits upstream.

Testing your integration

  • PayzumClient.sandbox(key) points at https://staging.payzum.com, which has isolated data and separate API keys.
  • Unit tests: implement PayzumTransport and pass a fake plus a Sleeper, so backoff is asserted instead of slept.
  • Contract tests: payzum-dev/payzum-conformance runs this SDK against a real HTTPS fake API and compares it with the other languages.

MIT licensed. See llms.txt for the one-page summary agents read first.

About

Official Java SDK for the Payzum crypto payment API — exact decimals, signed webhooks, zero runtime dependencies.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages