Skip to content

Repository files navigation

Stripe Java Bindings Build Status

You can sign up for a Stripe account at https://stripe.com.

Requirements

Java 1.7 or later.

Installation

Maven users

Add this dependency to your project's POM:

<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>5.24.0</version>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.stripe:stripe-java:5.24.0"

Others

You'll need to manually install the following JARs:

If you're planning on using ProGuard, make sure that you exclude the Stripe bindings. You can do this by adding the following to your proguard.cfg file:

-keep class com.stripe.** { *; }

Documentation

Please see the Java API docs for the most up-to-date documentation.

Usage

StripeExample.java

importjava.util.HashMap;
importjava.util.Map;
importcom.stripe.Stripe;
importcom.stripe.exception.StripeException;
importcom.stripe.model.Charge;
importcom.stripe.net.RequestOptions;
publicclassStripeExample {
publicstaticvoidmain(String[] args) {
RequestOptionsrequestOptions = (newRequestOptionsBuilder()).setApiKey("YOUR-SECRET-KEY").build();
Map<String, Object> chargeMap = newHashMap<String, Object>();
chargeMap.put("amount", 100);
chargeMap.put("currency", "usd");
chargeMap.put("source", "tok_1234"); // obtained via Stripe.jstry {
Chargecharge = Charge.create(chargeMap, requestOptions);
System.out.println(charge);
} catch (StripeExceptione) {
e.printStackTrace();
}
}
}

See the project's functional tests for more examples.

Configuring Timeouts

Connect and read timeouts can be configured globally:

Stripe.setConnectTimeout(30 * 1000); // in millisecondsStripe.setReadTimeout(80 * 1000);

Or on a finer grain level using RequestOptions:

RequestOptionsoptions = RequestOptions.builder()
.setConnectTimeout(30 * 1000) // in milliseconds
.setReadTimeout(80 * 1000)
.build();
Charge.create(params, options);

Please take care to set conservative read timeouts. Some API requests can take some time, and a short timeout increases the likelihood of a problem within our servers.

Testing

You must have Gradle installed. To run the tests:

./gradlew test

You can run particular tests by passing --tests Class#method. Make sure you use the fully qualified class name. For example:

./gradlew test --tests com.stripe.model.AccountTest
./gradlew test --tests com.stripe.functional.ChargeTest
./gradlew test --tests com.stripe.functional.ChargeTest.testChargeCreate

About

Java library for the Stripe API.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages