You can sign up for a Stripe account at https://stripe.com.
Java 1.5 and later.
Add this dependency to your project's POM:
...
<repository>
<id>Open Whisper Systems Maven</id>
<url>https://github.com/whispersystems/maven</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
...
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java-btc</artifactId>
<version>1.12.0-btc-beta</version>
</dependency>
You'll need to manually install the following JARs:
- The Stripe JAR from https://code.stripe.com/stripe-java-latest.jar
- Google Gson from http://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip.
StripeExample.java
import java.util.HashMap;
import java.util.Map;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
public class StripeExample {
public static void main(String[] args) {
Stripe.apiKey = "YOUR-SECRET-KEY";
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);
System.out.println(charge);
} catch (StripeException e) {
e.printStackTrace();
}
}
}
See StripeTest.java for more examples.
You must have Maven installed to run the tests then:
- cp src/test/config_example.yml src/test/config.yml
- modify src/test/config.yml to include your personal API keys
- mvn test.
You can run particular tests by passing -D test=Class#method -- for example, -D test=StripeTest#testPlanCreate.