Stripe
Since Camel 4.17
Only producer is supported
The Stripe component provides integration with the Stripe payment platform API using Stripe Java SDK.
Stripe is a popular payment processing platform that allows businesses to accept payments, send payouts, and manage their online businesses. This component enables Apache Camel routes to interact with Stripe’s API for operations such as:
-
Creating and managing customers
-
Processing payments and payment intents
-
Managing products and prices
-
Handling subscriptions
-
Creating and managing invoices
-
Processing refunds
-
And more
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stripe</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> URI format
stripe:operation[?options]
Where operation is one of the following:
-
charges- Create, retrieve, update, list, and capture charges -
customers- Create, retrieve, update, delete, and list customers -
paymentIntents- Create, retrieve, update, cancel, and list payment intents -
paymentMethods- Create, retrieve, update, and list payment methods -
refunds- Create, retrieve, update, and list refunds -
subscriptions- Create, retrieve, update, cancel, and list subscriptions -
invoices- Create, retrieve, update, and list invoices -
products- Create, retrieve, update, delete, and list products -
prices- Create, retrieve, update, and list prices -
balanceTransactions- Retrieve and list balance transactions
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. You can set them directly via Java code, or through the properties component.
StripeComponent stripe = context.getComponent("stripe", StripeComponent.class);
stripe.setApiKey("sk_test_..."); Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Stripe component supports 4 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Override the default Stripe API base URL (for testing purposes). | String | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
The Stripe API key for authentication. | String |
Endpoint Options
The Stripe endpoint is configured using URI syntax:
stripe:operation
With the following path and query parameters:
Query Parameters (3 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Override the default Stripe API base URL (for testing purposes). | String | ||
The Stripe API key for authentication. | String |
Message Headers
The Stripe component supports 3 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelStripeOperation (producer) Constant: | The operation to perform. | String | |
| Constant: | The method to invoke (create, retrieve, update, delete, list, cancel, capture). | String | |
CamelStripeObjectId (producer) Constant: | The ID of the object to retrieve, update, or delete. | String |
Authentication
The Stripe component requires a Stripe API key for authentication. You can obtain your API keys from the Stripe Dashboard.
Getting Your Stripe API Key
Step 1: Create a Stripe Account
-
Go to Stripe’s website
-
Click "Sign up" or "Start now"
-
Fill in your email, password, and country
-
Verify your email address by clicking the link sent to your email
-
Complete your account setup by providing business information
Step 2: Access the Stripe Dashboard
-
Log in to your Stripe account at dashboard.stripe.com
-
You will land on the Stripe Dashboard home page
Step 3: Get Your API Keys
-
In the Stripe Dashboard, click on the "Developers" link in the left sidebar
-
Click on "API keys" in the submenu
-
You will see two types of keys:
-
Publishable key: Used in client-side code (not needed for this component)
-
Secret key: Used for server-side API calls (this is what you need)
-
-
For testing, use the Test mode keys (toggle is at the top right)
-
Test keys start with
sk_test_… -
Test mode allows you to make API calls without processing real payments
-
-
For production, switch to Live mode (requires account verification)
-
Live keys start with
sk_live_… -
WARNING: Never use live keys for testing or development!
-
-
Click "Reveal test key" to view your secret API key
-
Copy the key starting with
sk_test_…
Important Security Notes
-
Never commit API keys to version control (Git, SVN, etc.)
-
Never expose API keys in client-side code
-
Use environment variables or secure configuration management for production
-
Always use test keys for development and testing
-
Rotate your API keys regularly for security
-
Use restricted API keys in production for least privilege access
Configuring Authentication in Camel
You can configure the API key in several ways:
Option 1: Component Level (Recommended for Single Key)
StripeComponent stripe = context.getComponent("stripe", StripeComponent.class);
stripe.setApiKey("sk_test_..."); Usage Examples
The Stripe component accepts both Map objects and JSON strings as input, providing flexibility for different integration scenarios.
Creating a Customer
Using a Map:
from("direct:createCustomer")
.setBody(constant(Map.of(
"email", "customer@example.com",
"name", "John Doe",
"description", "New customer"
)))
.to("stripe:customers?apiKey={{stripe.apiKey}}")
.log("Created customer: ${body.id}"); Using JSON:
from("direct:createCustomerJson")
.setBody(constant("""
{
"email": "customer@example.com",
"name": "John Doe",
"description": "New customer"
}
"""))
.to("stripe:customers?apiKey={{stripe.apiKey}}")
.log("Created customer: ${body.id}"); Creating a Payment Intent
Using a Map:
from("direct:payment")
.setBody(constant(Map.of(
"amount", 2000L, // Amount in cents ($20.00)
"currency", "usd",
"payment_method_types", List.of("card"),
"description", "Payment for order #12345"
)))
.to("stripe:paymentIntents?apiKey={{stripe.apiKey}}")
.log("Payment intent created: ${body.id}"); Using JSON (useful when integrating with REST endpoints):
from("rest:post:/payments")
.log("Received payment request: ${body}")
// Body is already JSON from REST endpoint
.to("stripe:paymentIntents?apiKey={{stripe.apiKey}}")
.log("Payment intent created: ${body.id}"); Retrieving a Customer
from("direct:getCustomer")
.setHeader(StripeConstants.OBJECT_ID, constant("cus_xxxxx"))
.setHeader(StripeConstants.METHOD_HEADER, constant(StripeConstants.METHOD_RETRIEVE))
.to("stripe:customers?apiKey={{stripe.apiKey}}")
.log("Retrieved customer: ${body.email}"); Updating a Payment Intent
from("direct:updatePayment")
.setHeader(StripeConstants.OBJECT_ID, simple("${exchangeProperty.paymentIntentId}"))
.setHeader(StripeConstants.METHOD_HEADER, constant(StripeConstants.METHOD_UPDATE))
.setBody(constant(Map.of(
"description", "Updated description",
"metadata", Map.of("order_id", "12345")
)))
.to("stripe:paymentIntents?apiKey={{stripe.apiKey}}"); Listing Customers
from("direct:listCustomers")
.setHeader(StripeConstants.METHOD_HEADER, constant(StripeConstants.METHOD_LIST))
.setBody(constant(Map.of("limit", 10)))
.to("stripe:customers?apiKey={{stripe.apiKey}}")
.log("Found ${body.data.size()} customers"); Creating a Product with Price
from("direct:createProduct")
// Create product
.setBody(constant(Map.of(
"name", "Premium Subscription",
"description", "Monthly premium access"
)))
.to("stripe:products?apiKey={{stripe.apiKey}}")
.setProperty("productId", simple("${body.id}"))
// Create price for the product
.process(exchange -> {
Map<String, Object> priceParams = new HashMap<>();
priceParams.put("product", exchange.getProperty("productId", String.class));
priceParams.put("currency", "usd");
priceParams.put("unit_amount", 2999L); // $29.99
priceParams.put("recurring", Map.of("interval", "month"));
exchange.getMessage().setBody(priceParams);
})
.to("stripe:prices?apiKey={{stripe.apiKey}}")
.log("Created product ${exchangeProperty.productId} with price ${body.id}"); Processing a Refund
from("direct:refund")
.setBody(constant(Map.of(
"charge", "ch_xxxxx",
"amount", 1000L, // Partial refund of $10.00
"reason", "requested_by_customer"
)))
.to("stripe:refunds?apiKey={{stripe.apiKey}}")
.log("Refund processed: ${body.id}"); Canceling a Payment Intent
from("direct:cancelPayment")
.setHeader(StripeConstants.OBJECT_ID, simple("${header.paymentIntentId}"))
.setHeader(StripeConstants.METHOD_HEADER, constant(StripeConstants.METHOD_CANCEL))
.to("stripe:paymentIntents?apiKey={{stripe.apiKey}}")
.log("Payment intent canceled: ${body.id}"); Running Integration Tests
The Stripe component includes comprehensive integration tests that verify functionality against the Stripe API.
Prerequisites
-
A Stripe account (free to create)
-
A test API key (obtained from the Stripe Dashboard as described above)
-
Maven 3.x and Java 11 or higher
Running the Tests
Provide the API key via system property:
mvn verify -Dtest=Stripe*IntegrationTest -DSTRIPE_API_KEY=sk_test_51... Running Specific Test Classes
# Test customer operations
mvn verify -Dtest=StripeCustomerIntegrationTest -DSTRIPE_API_KEY=sk_test_51...
# Test payment intent operations
mvn verify -Dtest=StripePaymentIntentIntegrationTest -DSTRIPE_API_KEY=sk_test_51...
# Test product operations
mvn verify -Dtest=StripeProductIntegrationTest -DSTRIPE_API_KEY=sk_test_51... Test Safety
All integration tests:
-
Only use test mode API keys (verified by checking
sk_test_prefix) -
Create temporary test data that is cleaned up after each test
-
Never process real payments or affect production data
-
Can be run unlimited times without cost
-
Automatically skip if no API key is provided
Supported Operations and Methods
Charges
| Method | Description |
|---|---|
| Create a charge for a payment |
| Retrieve a charge by ID |
| Update a charge’s metadata |
| List all charges |
| Capture a previously uncaptured charge |
Customers
| Method | Description |
|---|---|
| Create a new customer |
| Retrieve a customer by ID |
| Update customer information |
| Delete a customer |
| List all customers |
Payment Intents
| Method | Description |
|---|---|
| Create a payment intent |
| Retrieve a payment intent by ID |
| Update payment intent information |
| Cancel a payment intent |
| List all payment intents |
Payment Methods
| Method | Description |
|---|---|
| Create a payment method |
| Retrieve a payment method by ID |
| Update payment method information |
| List all payment methods |
Refunds
| Method | Description |
|---|---|
| Create a refund |
| Retrieve a refund by ID |
| Update refund metadata |
| List all refunds |
Subscriptions
| Method | Description |
|---|---|
| Create a subscription |
| Retrieve a subscription by ID |
| Update subscription information |
| Cancel a subscription |
| List all subscriptions |
Invoices
| Method | Description |
|---|---|
| Create an invoice |
| Retrieve an invoice by ID |
| Update invoice information |
| List all invoices |
Products
| Method | Description |
|---|---|
| Create a product |
| Retrieve a product by ID |
| Update product information |
| Delete a product |
| List all products |
Error Handling
The Stripe API may return various errors. The component propagates these as exceptions:
from("direct:createPayment")
.doTry()
.to("stripe:paymentIntents?apiKey={{stripe.apiKey}}")
.log("Payment successful: ${body.id}")
.doCatch(com.stripe.exception.CardException.class)
.log("Card was declined: ${exception.message}")
.doCatch(com.stripe.exception.InvalidRequestException.class)
.log("Invalid parameters: ${exception.message}")
.doCatch(com.stripe.exception.AuthenticationException.class)
.log("Authentication failed - check API key")
.doCatch(com.stripe.exception.ApiException.class)
.log("Stripe API error: ${exception.message}")
.end();