Permalink
Browse files

Merge pull request #456 from stripe/brandur-per-request

Add README section for "per-request configuration"
ob-stripe committed Feb 23, 2018
2 parents 04350bf + 958d177 commit 721d389b633e3d3e77fba63d0c4b2a975fa97dca
Showing with 23 additions and 2 deletions.
  1. +23 −2 README.md
View
@@ -61,13 +61,15 @@ import com.stripe.net.RequestOptions;
public class StripeExample {
public static void main(String[] args) {
- RequestOptions requestOptions = (new RequestOptionsBuilder()).setApiKey("YOUR-SECRET-KEY").build();
+ Stripe.apiKey = "sk_test_...";
+
Map<String, Object> chargeMap = new HashMap<String, Object>();
chargeMap.put("amount", 100);
chargeMap.put("currency", "usd");
chargeMap.put("source", "tok_1234"); // obtained via Stripe.js
+
try {
- Charge charge = Charge.create(chargeMap, requestOptions);
+ Charge charge = Charge.create(chargeMap);
System.out.println(charge);
} catch (StripeException e) {
e.printStackTrace();
@@ -78,6 +80,23 @@ public class StripeExample {
See the project's [functional tests](https://github.com/stripe/stripe-java/blob/master/src/test/java/com/stripe/functional/) for more examples.
+### Per-request Configuration
+
+For apps that need to use multiple keys during the lifetime of a process, like
+one that uses [Stripe Connect][connect], it's also possible to set a
+per-request key and/or account:
+
+``` java
+RequestOptions requestOptions = new RequestOptionsBuilder()
+ .setApiKey("sk_test_...")
+ .setStripeAccount("acct_...")
+ .build();
+
+Charge.list(null, requestOptions);
+
+Charge.retrieve("ch_18atAXCdGbJFKhCuBAa4532Z", requestOptions);
+```
+
### Configuring Timeouts
Connect and read timeouts can be configured globally:
@@ -123,6 +142,8 @@ You can run particular tests by passing `--tests Class#method`. Make sure you us
./gradlew test --tests com.stripe.functional.ChargeTest
./gradlew test --tests com.stripe.functional.ChargeTest.testChargeCreate
+[connect]: https://stripe.com/connect
+
<!--
# vim: set tw=79:
-->

0 comments on commit 721d389

Please sign in to comment.