Skip to content

Commit 39104e2

Browse files
raubrey2014claude
andcommitted
Move builder API onto TempoMethod/StripeMethod; delete standalone config classes
TempoMethod now exposes mainnet(), testnet(), custom(url, chainId) as public static factories returning an inner Builder. StripeMethod exposes of(key, networkId) the same way. No separate TempoConfig/StripeConfig classes needed. Tempo.java updated to delegate to the new builders; all existing overloads kept for backwards compat. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3e3cd79 commit 39104e2

7 files changed

Lines changed: 118 additions & 195 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on mainnet it is USDC.
2121
// Mainnet: TempoDefaults.MAINNET_USDC = "0x20C000000000000000000000b9537d11c60E8b50"
2222
String currency = TempoDefaults.TESTNET_PATH_USD;
2323

24-
TempoMethod tempo = TempoConfig.testnet().build();
24+
TempoMethod tempo = TempoMethod.testnet().build();
2525
MppHandler mppHandler = Mpp.create(tempo, "api.example.com", System.getenv("MPP_SECRET_KEY"));
2626

2727
// In your HTTP handler:
@@ -60,10 +60,10 @@ or, if already broadcast:
6060
which Stripe profile to pay. Use your Stripe profile or network ID (e.g. `STRIPE_PROFILE_ID`).
6161

6262
```java
63-
TempoMethod tempo = TempoConfig.testnet().build();
63+
TempoMethod tempo = TempoMethod.testnet().build();
6464
MppHandler tempoHandler = Mpp.create(tempo, "api.example.com", System.getenv("MPP_SECRET_KEY"));
6565

66-
StripeMethod stripe = StripeConfig.of(System.getenv("STRIPE_SECRET_KEY"), System.getenv("STRIPE_PROFILE_ID")).build();
66+
StripeMethod stripe = StripeMethod.of(System.getenv("STRIPE_SECRET_KEY"), System.getenv("STRIPE_PROFILE_ID")).build();
6767
MppHandler stripeHandler = Mpp.create(stripe, "api.example.com", System.getenv("MPP_SECRET_KEY"));
6868

6969
ComposedHandler mppHandler = Mpp.compose(

src/main/java/com/stripe/mpp/methods/stripe/Stripe.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
public final class Stripe {
2323
private Stripe() {}
2424

25-
/** Returns a {@link StripeMethod} from a {@link StripeConfig} builder. */
26-
public static StripeMethod method(StripeConfig config) {
27-
return config.build();
28-
}
29-
3025
/**
31-
* Returns a {@link StripeMethod} with default USD / 2-decimal settings.
26+
* Returns a {@link StripeMethod} with default settings.
3227
*
33-
* @param secretKey Stripe secret API key
34-
* @param networkId Stripe network identifier sent to the client in the challenge
28+
* @param secretKey Stripe secret API key
29+
* @param networkId Stripe profile/network identifier sent to the client in the challenge
3530
*/
3631
public static StripeMethod method(String secretKey, String networkId) {
3732
return method(secretKey, networkId, null, null);

src/main/java/com/stripe/mpp/methods/stripe/StripeConfig.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/main/java/com/stripe/mpp/methods/stripe/StripeMethod.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
import java.util.Map;
99

1010
/**
11-
* MPP payment method for Stripe. Obtain instances via {@link Stripe#method}.
11+
* MPP payment method for Stripe.
1212
*
1313
* <pre>{@code
14-
* StripeMethod stripe = Stripe.method(secretKey, networkId);
14+
* StripeMethod stripe = StripeMethod.of(secretKey, networkId).build();
1515
*
16-
* MppHandler server = Mpp.create(stripe, "api.example.com", secretKey);
17-
*
18-
* VerifyResult result = server.charge(
19-
* request.getHeader("Authorization"),
20-
* stripe.chargeIntent(),
21-
* "10.00", "usd", networkId
22-
* );
16+
* StripeMethod stripe = StripeMethod.of(secretKey, networkId)
17+
* .paymentMethods(List.of("card", "link"))
18+
* .metadata(Map.of("source", "mpp"))
19+
* .build();
2320
* }</pre>
2421
*/
2522
public class StripeMethod implements Method {
@@ -42,6 +39,44 @@ public class StripeMethod implements Method {
4239
this.chargeIntent = new StripeChargeIntent(secretKey, decimals, new StripeApi());
4340
}
4441

42+
/**
43+
* Starts a builder for a Stripe payment method.
44+
*
45+
* @param secretKey Stripe secret API key
46+
* @param networkId Stripe profile/network identifier sent to the client in the challenge
47+
*/
48+
public static Builder of(String secretKey, String networkId) {
49+
return new Builder(secretKey, networkId);
50+
}
51+
52+
public static final class Builder {
53+
private final String secretKey;
54+
private final String networkId;
55+
private List<String> paymentMethods;
56+
private Map<String, String> metadata;
57+
58+
private Builder(String secretKey, String networkId) {
59+
this.secretKey = secretKey;
60+
this.networkId = networkId;
61+
}
62+
63+
/** Restrict which Stripe payment method types the client may use (e.g. {@code "card"}, {@code "link"}). */
64+
public Builder paymentMethods(List<String> paymentMethods) {
65+
this.paymentMethods = paymentMethods;
66+
return this;
67+
}
68+
69+
/** Metadata attached to created Stripe PaymentIntents. */
70+
public Builder metadata(Map<String, String> metadata) {
71+
this.metadata = metadata;
72+
return this;
73+
}
74+
75+
public StripeMethod build() {
76+
return new StripeMethod(secretKey, networkId, paymentMethods, metadata, StripeDefaults.DEFAULT_DECIMALS);
77+
}
78+
}
79+
4580
@Override public String name() { return "stripe"; }
4681

4782
@Override

src/main/java/com/stripe/mpp/methods/tempo/Tempo.java

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,67 @@
33
/**
44
* Factory for Tempo payment objects.
55
*
6-
* <pre>{@code
7-
* TempoMethod tempo = Tempo.method(); // mainnet
8-
* TempoMethod tempo = Tempo.method(true); // testnet (Moderato)
9-
*
10-
* MppHandler server = Mpp.create(tempo, "api.example.com", secretKey);
6+
* <p>Prefer the named builders on {@link TempoMethod} directly:
117
*
12-
* // In your HTTP handler:
13-
* VerifyResult result = server.charge(
14-
* request.getHeader("Authorization"),
15-
* Tempo.chargeIntent(),
16-
* "10.000000", TempoDefaults.MAINNET_USDC, "0xRecipient"
17-
* );
8+
* <pre>{@code
9+
* TempoMethod tempo = TempoMethod.testnet().build();
10+
* TempoMethod tempo = TempoMethod.mainnet().debug().build();
11+
* TempoMethod tempo = TempoMethod.custom("http://localhost:8545", 1337).build();
1812
* }</pre>
13+
*
14+
* <p>The static helpers here are kept for backwards compatibility.
1915
*/
2016
public final class Tempo {
2117
private Tempo() {}
2218

23-
/** Returns a {@link TempoMethod} from a {@link TempoConfig} builder. */
24-
public static TempoMethod method(TempoConfig config) {
25-
return config.build();
26-
}
27-
2819
/** Returns a {@link TempoMethod} configured for Tempo mainnet. */
2920
public static TempoMethod method() {
30-
return method(false);
21+
return TempoMethod.mainnet().build();
3122
}
3223

3324
/**
34-
* Returns a {@link TempoMethod} configured for Tempo mainnet or testnet (Moderato).
25+
* Returns a {@link TempoMethod} for mainnet or testnet (Moderato).
3526
*
3627
* @param testnet {@code true} for Moderato testnet, {@code false} for mainnet
3728
*/
3829
public static TempoMethod method(boolean testnet) {
39-
return testnet ? TempoMethod.testnet() : TempoMethod.mainnet();
30+
return (testnet ? TempoMethod.testnet() : TempoMethod.mainnet()).build();
4031
}
4132

4233
/**
43-
* Returns a {@link TempoMethod} configured for Tempo mainnet or testnet (Moderato), with
44-
* optional debug logging of raw JSON-RPC request/response bodies.
34+
* Returns a {@link TempoMethod} for mainnet or testnet, with optional debug logging.
4535
*
4636
* @param testnet {@code true} for Moderato testnet, {@code false} for mainnet
4737
* @param debug {@code true} to log raw RPC request/response bodies at INFO level
4838
*/
4939
public static TempoMethod method(boolean testnet, boolean debug) {
50-
return testnet ? TempoMethod.testnet(debug) : TempoMethod.mainnet(debug);
40+
TempoMethod.Builder b = testnet ? TempoMethod.testnet() : TempoMethod.mainnet();
41+
if (debug) b.debug();
42+
return b.build();
43+
}
44+
45+
/**
46+
* Returns a {@link TempoMethod} pointed at a custom RPC URL and chain ID.
47+
*
48+
* @param rpcUrl JSON-RPC endpoint (e.g. {@code "http://localhost:8545"})
49+
* @param chainId numeric EVM chain ID (e.g. {@code 1337})
50+
*/
51+
public static TempoMethod method(String rpcUrl, int chainId) {
52+
return TempoMethod.custom(rpcUrl, chainId).build();
53+
}
54+
55+
/**
56+
* Returns a {@link TempoMethod} pointed at a custom RPC URL and chain ID, with optional
57+
* debug logging.
58+
*
59+
* @param rpcUrl JSON-RPC endpoint (e.g. {@code "http://localhost:8545"})
60+
* @param chainId numeric EVM chain ID (e.g. {@code 1337})
61+
* @param debug {@code true} to log raw RPC request/response bodies
62+
*/
63+
public static TempoMethod method(String rpcUrl, int chainId, boolean debug) {
64+
TempoMethod.Builder b = TempoMethod.custom(rpcUrl, chainId);
65+
if (debug) b.debug();
66+
return b.build();
5167
}
5268

5369
/** Returns a {@link TempoChargeIntent} that submits payments on Tempo mainnet. */
@@ -66,7 +82,6 @@ public static TempoChargeIntent chargeIntent(boolean testnet) {
6682

6783
/**
6884
* Returns a {@link TempoChargeIntent} pointed at a custom RPC URL.
69-
* Useful for local development nodes or private networks.
7085
*
7186
* @param rpcUrl JSON-RPC endpoint (e.g. {@code "http://localhost:8545"})
7287
*/
@@ -76,39 +91,11 @@ public static TempoChargeIntent chargeIntent(String rpcUrl) {
7691

7792
/**
7893
* Returns a {@link TempoChargeIntent} pointed at a custom RPC URL with optional debug logging.
79-
* When {@code debug} is {@code true}, raw JSON-RPC request and response bodies are logged at
80-
* INFO level via {@code java.util.logging} under the logger name
81-
* {@code com.stripe.mpp.methods.tempo.TempoRpc}.
8294
*
8395
* @param rpcUrl JSON-RPC endpoint (e.g. {@code "http://localhost:8545"})
8496
* @param debug {@code true} to log raw RPC request/response bodies
8597
*/
8698
public static TempoChargeIntent chargeIntent(String rpcUrl, boolean debug) {
8799
return new TempoChargeIntent(rpcUrl, debug);
88100
}
89-
90-
/**
91-
* Returns a {@link TempoMethod} pointed at a custom RPC URL and chain ID.
92-
* Useful for local development nodes or private networks.
93-
*
94-
* @param rpcUrl JSON-RPC endpoint (e.g. {@code "http://localhost:8545"})
95-
* @param chainId numeric EVM chain ID (e.g. {@code 1337})
96-
*/
97-
public static TempoMethod method(String rpcUrl, int chainId) {
98-
return new TempoMethod(rpcUrl, chainId);
99-
}
100-
101-
/**
102-
* Returns a {@link TempoMethod} pointed at a custom RPC URL and chain ID with optional debug
103-
* logging. When {@code debug} is {@code true}, raw JSON-RPC request and response bodies are
104-
* logged at INFO level via {@code java.util.logging} under the logger name
105-
* {@code com.stripe.mpp.methods.tempo.TempoRpc}.
106-
*
107-
* @param rpcUrl JSON-RPC endpoint (e.g. {@code "http://localhost:8545"})
108-
* @param chainId numeric EVM chain ID (e.g. {@code 1337})
109-
* @param debug {@code true} to log raw RPC request/response bodies
110-
*/
111-
public static TempoMethod method(String rpcUrl, int chainId, boolean debug) {
112-
return new TempoMethod(rpcUrl, chainId, debug);
113-
}
114101
}

src/main/java/com/stripe/mpp/methods/tempo/TempoConfig.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)