You can sign up for a Stripe account at https://stripe.com.
Java 1.6 or later.
Add this dependency to your project's POM:
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>3.3.0</version>
</dependency>
Add this dependency to your project's build file:
compile "com.stripe:stripe-java:3.3.0"
You'll need to manually install the following JARs:
- The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest
- Google Gson from http://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip.
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.** { *; }
Please see the Java API docs for the most up-to-date documentation.
StripeExample.java
import java.util.HashMap;
import java.util.Map;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
import com.stripe.net.RequestOptions;
public class StripeExample {
public static void main(String[] args) {
RequestOptions requestOptions = (new RequestOptionsBuilder()).setApiKey("YOUR-SECRET-KEY").build();
Map<String, Object> chargeMap = new HashMap<String, Object>();
chargeMap.put("amount", 100);
chargeMap.put("currency", "usd");
Map<String, Object> cardMap = new HashMap<String, Object>();
cardMap.put("number", "4242424242424242");
cardMap.put("exp_month", 12);
cardMap.put("exp_year", 2020);
chargeMap.put("card", cardMap);
try {
Charge charge = Charge.create(chargeMap, requestOptions);
System.out.println(charge);
} catch (StripeException e) {
e.printStackTrace();
}
}
}
See StripeTest.java for more examples.
You must have Maven installed. To run the tests:
mvn test
You can run particular tests by passing -D test=Class#method
. Make sure you use the fully qualified class name to differentiate between
unit and functional tests. For example:
mvn test -D test=com.stripe.model.AccountTest
mvn test -D test=com.stripe.functional.ChargeTest
mvn test -D test=com.stripe.functional.ChargeTest#testChargeCreate