Java integration
Call the SpicePay API from a server-side Java application.
How it works
Call the SpicePay API from a server-side Java application. Standard HTTP clients can create the payment without a branded SDK dependency.
Implementation
Read the secret from SPICEPAY_API_KEY, construct an explicit shop-scoped request, send api-key and Content-Type headers, and deserialize the response. Save payment_id before sending the customer to checkout. Use test_mode only after validating sandbox credentials. A SpicePay SDK registry package has not been confirmed; the examples below therefore use a native HTTP client.
In this area
- Install
- Create a payment
- Client options
- Per-request options
Related guides
Create a test payment
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String payload = """
{"amount":4900,"currency":"EUR","profile_id":"YOUR_SHOP_ID",
"payment_link":true,"test_mode":true,
"return_url":"https://your-shop.example/return"}
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.spicepay.net/payments"))
.header("api-key", System.getenv("SPICEPAY_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() / 100 != 2) {
throw new IllegalStateException("Request failed: " + response.statusCode());
}
// Parse JSON, persist the payment ID, and verify signed webhooks.The snippet is a server-side request example. Supply your own merchant key and shop ID and configure the processor sandbox before running it.
Fragen zu deiner Integration? SpicePay kontaktieren ↗