A minimal Spring Boot API that creates Stripe Checkout sessions for one-time payments.
- Java 17
- Spring Boot 4.0.0
- Stripe Java SDK 26.8.0
- Maven
- REST endpoint to create a Stripe Checkout session
- Simple amount-based payment flow
- CORS enabled for all origins
src/main/java/com/example/springpayment/SpringPaymentGatewayApplication.javasrc/main/java/com/example/springpayment/controller/PaymentController.javasrc/main/resources/application.properties
- In
src/main/resources/application.properties:spring.application.name=spring-payment-gateway stripe.secret.key=${STRIPE_SECRET_KEY}
- In
.env(ignored by git):STRIPE_SECRET_KEY=sk_test_...
stripe.secret.key=sk_test_..../mvnw spring-boot:runThe app will start on http://localhost:8080.
POST /api/payment/create-checkout-session
Request Body
{
"amount": 5000
}amount is in the smallest currency unit (e.g., paise for INR).
Response
{
"url": "https://checkout.stripe.com/..."
}- Currency is set to INR in the controller.
- Success and cancel URLs are currently hardcoded to:
http://localhost:3000/successhttp://localhost:3000/cancel
./mvnw test