Java¶
money.oura:oura-java · source
Requires Java 11+. Uses Gson for JSON; webhook verification has no dependencies. This SDK holds your secret key, so use it only on a server.
Install¶
<dependency>
<groupId>money.oura</groupId>
<artifactId>oura-java</artifactId>
<version>0.1.0</version>
</dependency>
Accept a payment¶
import money.oura.OuraClient;
import money.oura.Payments;
OuraClient oura = new OuraClient(System.getenv("OURA_SECRET_KEY"));
Map<String, Object> params = Payments.params();
params.put("amount", 245000); // NPR 2,450.00 in paisa
params.put("methods", List.of("esewa", "khalti"));
params.put("return_url", "https://himalstore.com.np/orders/1042");
Map<String, Object> payment = oura.payments.create(params);
String checkoutUrl = (String) payment.get("checkout_url");
Other calls¶
oura.payments.retrieve("pay_123");
oura.payments.list(20, null);
oura.payments.cancel("pay_123");
oura.payments.create(params, "order_" + orderId);
An idempotency key is generated for every create. Pass your own, tied to your order, to make retries safe across restarts. See Idempotency.
Webhooks¶
Verify with Webhooks.constructEvent(raw, header, secret) (returns the verified JSON string) and Webhooks.verify(raw, header, secret, 300). Both compare in constant time and reject stale timestamps. Always pass the raw request body. Full example: Webhooks.
Errors¶
Every non-2xx response raises OuraException with the error code, HTTP status and message. See Errors.